tests/run-tests.py
changeset 8094 60a9e3cf0cf4
parent 8093 70d8f70264c4
child 8095 f5428d4ffd97
equal deleted inserted replaced
8093:70d8f70264c4 8094:60a9e3cf0cf4
   181         if found:
   181         if found:
   182             vlog("# Found prerequisite", p, "at", found)
   182             vlog("# Found prerequisite", p, "at", found)
   183         else:
   183         else:
   184             print "WARNING: Did not find prerequisite tool: "+p
   184             print "WARNING: Did not find prerequisite tool: "+p
   185 
   185 
   186 def cleanup_exit():
   186 def cleanup_exit(options):
   187     if not options.keep_tmpdir:
   187     if not options.keep_tmpdir:
   188         if verbose:
   188         if verbose:
   189             print "# Cleaning up HGTMP", HGTMP
   189             print "# Cleaning up HGTMP", HGTMP
   190         shutil.rmtree(HGTMP, True)
   190         shutil.rmtree(HGTMP, True)
   191 
   191 
   204     except AttributeError:
   204     except AttributeError:
   205         # windows fallback
   205         # windows fallback
   206         shutil.copyfile(sys.executable, my_python)
   206         shutil.copyfile(sys.executable, my_python)
   207         shutil.copymode(sys.executable, my_python)
   207         shutil.copymode(sys.executable, my_python)
   208 
   208 
   209 def install_hg():
   209 def install_hg(options):
   210     global python
   210     global python
   211     vlog("# Performing temporary installation of HG")
   211     vlog("# Performing temporary installation of HG")
   212     installerrs = os.path.join("tests", "install.err")
   212     installerrs = os.path.join("tests", "install.err")
   213     pure = options.pure and "--pure" or ""
   213     pure = options.pure and "--pure" or ""
   214 
   214 
   279     hgpath = os.popen(cmd % python)
   279     hgpath = os.popen(cmd % python)
   280     path = hgpath.read().strip()
   280     path = hgpath.read().strip()
   281     hgpath.close()
   281     hgpath.close()
   282     return path
   282     return path
   283 
   283 
   284 def output_coverage():
   284 def output_coverage(options):
   285     vlog("# Producing coverage report")
   285     vlog("# Producing coverage report")
   286     omit = [BINDIR, TESTDIR, PYTHONDIR]
   286     omit = [BINDIR, TESTDIR, PYTHONDIR]
   287     if not options.cover_stdlib:
   287     if not options.cover_stdlib:
   288         # Exclude as system paths (ignoring empty strings seen on win)
   288         # Exclude as system paths (ignoring empty strings seen on win)
   289         omit += [x for x in sys.path if x != '']
   289         omit += [x for x in sys.path if x != '']
   337                 ret = signal.SIGTERM << 8
   337                 ret = signal.SIGTERM << 8
   338             output += ("\n### Abort: timeout after %d seconds.\n"
   338             output += ("\n### Abort: timeout after %d seconds.\n"
   339                        % options.timeout)
   339                        % options.timeout)
   340     return ret, splitnewlines(output)
   340     return ret, splitnewlines(output)
   341 
   341 
   342 def run_one(test, skips, fails):
   342 def run_one(options, test, skips, fails):
   343     '''tristate output:
   343     '''tristate output:
   344     None -> skipped
   344     None -> skipped
   345     True -> passed
   345     True -> passed
   346     False -> failed'''
   346     False -> failed'''
   347 
   347 
   494         shutil.rmtree(tmpd, True)
   494         shutil.rmtree(tmpd, True)
   495     if skipped:
   495     if skipped:
   496         return None
   496         return None
   497     return ret == 0
   497     return ret == 0
   498 
   498 
   499 def run_children(tests):
   499 def run_children(options, expecthg, tests):
   500     if not options.with_hg:
   500     if not options.with_hg:
   501         install_hg()
   501         install_hg()
   502         if hgpkg != expecthg:
   502         if hgpkg != expecthg:
   503             print '# Testing unexpected mercurial: %s' % hgpkg
   503             print '# Testing unexpected mercurial: %s' % hgpkg
   504 
   504 
   559         print '# Tested unexpected mercurial: %s' % hgpkg
   559         print '# Tested unexpected mercurial: %s' % hgpkg
   560     print "# Ran %d tests, %d skipped, %d failed." % (
   560     print "# Ran %d tests, %d skipped, %d failed." % (
   561         tested, skipped, failed)
   561         tested, skipped, failed)
   562     sys.exit(failures != 0)
   562     sys.exit(failures != 0)
   563 
   563 
   564 def run_tests(tests):
   564 def run_tests(options, expecthg, tests):
   565     global DAEMON_PIDS, HGRCPATH
   565     global DAEMON_PIDS, HGRCPATH
   566     DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
   566     DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
   567     HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
   567     HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
   568 
   568 
   569     try:
   569     try:
   570         if not options.with_hg:
   570         if not options.with_hg:
   571             install_hg()
   571             install_hg(options)
   572 
   572 
   573             if hgpkg != expecthg:
   573             if hgpkg != expecthg:
   574                 print '# Testing unexpected mercurial: %s' % hgpkg
   574                 print '# Testing unexpected mercurial: %s' % hgpkg
   575 
   575 
   576         if options.timeout > 0:
   576         if options.timeout > 0:
   600         fails = []
   600         fails = []
   601         for test in tests:
   601         for test in tests:
   602             if options.retest and not os.path.exists(test + ".err"):
   602             if options.retest and not os.path.exists(test + ".err"):
   603                 skipped += 1
   603                 skipped += 1
   604                 continue
   604                 continue
   605             ret = run_one(test, skips, fails)
   605             ret = run_one(options, test, skips, fails)
   606             if ret is None:
   606             if ret is None:
   607                 skipped += 1
   607                 skipped += 1
   608             elif not ret:
   608             elif not ret:
   609                 if options.interactive:
   609                 if options.interactive:
   610                     print "Accept this change? [n] ",
   610                     print "Accept this change? [n] ",
   637                 print '# Tested unexpected mercurial: %s' % hgpkg
   637                 print '# Tested unexpected mercurial: %s' % hgpkg
   638             print "# Ran %d tests, %d skipped, %d failed." % (
   638             print "# Ran %d tests, %d skipped, %d failed." % (
   639                 tested, skipped, failed)
   639                 tested, skipped, failed)
   640 
   640 
   641         if coverage:
   641         if coverage:
   642             output_coverage()
   642             output_coverage(options)
   643     except KeyboardInterrupt:
   643     except KeyboardInterrupt:
   644         failed = True
   644         failed = True
   645         print "\ninterrupted!"
   645         print "\ninterrupted!"
   646 
   646 
   647     if failed:
   647     if failed:
   648         sys.exit(1)
   648         sys.exit(1)
   649 
   649 
   650 (options, args) = parse_args()
   650 def main():
   651 if not options.child:
   651     (options, args) = parse_args()
   652     os.umask(022)
   652     if not options.child:
   653 
   653         os.umask(022)
   654     check_required_tools()
   654 
   655 
   655         check_required_tools()
   656 # Reset some environment variables to well-known values so that
   656 
   657 # the tests produce repeatable output.
   657     # Reset some environment variables to well-known values so that
   658 os.environ['LANG'] = os.environ['LC_ALL'] = 'C'
   658     # the tests produce repeatable output.
   659 os.environ['TZ'] = 'GMT'
   659     os.environ['LANG'] = os.environ['LC_ALL'] = 'C'
   660 os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>"
   660     os.environ['TZ'] = 'GMT'
   661 os.environ['CDPATH'] = ''
   661     os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>"
   662 
   662     os.environ['CDPATH'] = ''
   663 TESTDIR = os.environ["TESTDIR"] = os.getcwd()
   663 
   664 HGTMP = os.environ['HGTMP'] = os.path.realpath(tempfile.mkdtemp('', 'hgtests.',
   664     global TESTDIR, HGTMP, INST, BINDIR, PYTHONDIR, COVERAGE_FILE
   665                                                options.tmpdir))
   665     TESTDIR = os.environ["TESTDIR"] = os.getcwd()
   666 DAEMON_PIDS = None
   666     HGTMP = os.environ['HGTMP'] = os.path.realpath(tempfile.mkdtemp('', 'hgtests.',
   667 HGRCPATH = None
   667                                                    options.tmpdir))
   668 
   668     DAEMON_PIDS = None
   669 os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
   669     HGRCPATH = None
   670 os.environ["HGMERGE"] = "internal:merge"
   670 
   671 os.environ["HGUSER"]   = "test"
   671     os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
   672 os.environ["HGENCODING"] = "ascii"
   672     os.environ["HGMERGE"] = "internal:merge"
   673 os.environ["HGENCODINGMODE"] = "strict"
   673     os.environ["HGUSER"]   = "test"
   674 os.environ["HGPORT"] = str(options.port)
   674     os.environ["HGENCODING"] = "ascii"
   675 os.environ["HGPORT1"] = str(options.port + 1)
   675     os.environ["HGENCODINGMODE"] = "strict"
   676 os.environ["HGPORT2"] = str(options.port + 2)
   676     os.environ["HGPORT"] = str(options.port)
   677 
   677     os.environ["HGPORT1"] = str(options.port + 1)
   678 if options.with_hg:
   678     os.environ["HGPORT2"] = str(options.port + 2)
   679     INST = options.with_hg
   679 
   680 else:
   680     if options.with_hg:
   681     INST = os.path.join(HGTMP, "install")
   681         INST = options.with_hg
   682 BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin")
       
   683 PYTHONDIR = os.path.join(INST, "lib", "python")
       
   684 COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
       
   685 
       
   686 expecthg = os.path.join(HGTMP, 'install', 'lib', 'python', 'mercurial')
       
   687 hgpkg = None
       
   688 
       
   689 if len(args) == 0:
       
   690     args = os.listdir(".")
       
   691     args.sort()
       
   692 
       
   693 tests = []
       
   694 for test in args:
       
   695     if (test.startswith("test-") and '~' not in test and
       
   696         ('.' not in test or test.endswith('.py') or
       
   697          test.endswith('.bat'))):
       
   698         tests.append(test)
       
   699 
       
   700 vlog("# Using TESTDIR", TESTDIR)
       
   701 vlog("# Using HGTMP", HGTMP)
       
   702 
       
   703 try:
       
   704     if len(tests) > 1 and options.jobs > 1:
       
   705         run_children(tests)
       
   706     else:
   682     else:
   707         run_tests(tests)
   683         INST = os.path.join(HGTMP, "install")
   708 finally:
   684     BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin")
   709     cleanup_exit()
   685     PYTHONDIR = os.path.join(INST, "lib", "python")
       
   686     COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
       
   687 
       
   688     expecthg = os.path.join(HGTMP, 'install', 'lib', 'python', 'mercurial')
       
   689     hgpkg = None
       
   690 
       
   691     if len(args) == 0:
       
   692         args = os.listdir(".")
       
   693         args.sort()
       
   694 
       
   695     tests = []
       
   696     for test in args:
       
   697         if (test.startswith("test-") and '~' not in test and
       
   698             ('.' not in test or test.endswith('.py') or
       
   699              test.endswith('.bat'))):
       
   700             tests.append(test)
       
   701 
       
   702     vlog("# Using TESTDIR", TESTDIR)
       
   703     vlog("# Using HGTMP", HGTMP)
       
   704 
       
   705     try:
       
   706         if len(tests) > 1 and options.jobs > 1:
       
   707             run_children(options, expecthg, tests)
       
   708         else:
       
   709             run_tests(options, expecthg, tests)
       
   710     finally:
       
   711         cleanup_exit(options)
       
   712 
       
   713 main()