tests/run-tests.py
changeset 832 1f1db3dc9ddf
parent 829 7d66d78e6179
child 833 a9c6ada32647
equal deleted inserted replaced
825:908e4fe6c177 832:1f1db3dc9ddf
   441     pass
   441     pass
   442 
   442 
   443 def alarmed(signum, frame):
   443 def alarmed(signum, frame):
   444     raise Timeout
   444     raise Timeout
   445 
   445 
   446 def pytest(test, options):
   446 def pytest(test, options, replacements):
   447     py3kswitch = options.py3k_warnings and ' -3' or ''
   447     py3kswitch = options.py3k_warnings and ' -3' or ''
   448     cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test)
   448     cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test)
   449     vlog("# Running", cmd)
   449     vlog("# Running", cmd)
   450     return run(cmd, options)
   450     return run(cmd, options, replacements)
   451 
   451 
   452 def shtest(test, options):
   452 def shtest(test, options, replacements):
   453     cmd = '"%s"' % test
   453     cmd = '"%s"' % test
   454     vlog("# Running", cmd)
   454     vlog("# Running", cmd)
   455     return run(cmd, options)
   455     return run(cmd, options, replacements)
   456 
   456 
   457 def battest(test, options):
   457 def battest(test, options, replacements):
   458     # To reliably get the error code from batch files on WinXP,
   458     # To reliably get the error code from batch files on WinXP,
   459     # the "cmd /c call" prefix is needed. Grrr
   459     # the "cmd /c call" prefix is needed. Grrr
   460     cmd = 'cmd /c call "%s"' % testpath
   460     cmd = 'cmd /c call "%s"' % testpath
   461     vlog("# Running", cmd)
   461     vlog("# Running", cmd)
   462     return run(cmd, options)
   462     return run(cmd, options, replacements)
   463 
   463 
   464 def tsttest(test, options):
   464 def tsttest(test, options, replacements):
   465     t = open(test)
   465     t = open(test)
   466     out = []
   466     out = []
   467     script = []
   467     script = []
   468     salt = "SALT" + str(time.time())
   468     salt = "SALT" + str(time.time())
   469 
   469 
   498             os.write(fd, l)
   498             os.write(fd, l)
   499         os.close(fd)
   499         os.close(fd)
   500 
   500 
   501         cmd = '/bin/sh "%s"' % name
   501         cmd = '/bin/sh "%s"' % name
   502         vlog("# Running", cmd)
   502         vlog("# Running", cmd)
   503         exitcode, output = run(cmd, options)
   503         exitcode, output = run(cmd, options, replacements)
   504         # do not merge output if skipped, return hghave message instead
   504         # do not merge output if skipped, return hghave message instead
   505         if exitcode == SKIPPED_STATUS:
   505         if exitcode == SKIPPED_STATUS:
   506             return exitcode, output
   506             return exitcode, output
   507     finally:
   507     finally:
   508         os.remove(name)
   508         os.remove(name)
   563     if pos in after:
   563     if pos in after:
   564         postout += after.pop(pos)
   564         postout += after.pop(pos)
   565 
   565 
   566     return exitcode, postout
   566     return exitcode, postout
   567 
   567 
   568 def run(cmd, options):
   568 def run(cmd, options, replacements):
   569     """Run command in a sub-process, capturing the output (stdout and stderr).
   569     """Run command in a sub-process, capturing the output (stdout and stderr).
   570     Return a tuple (exitcode, output).  output is None in debug mode."""
   570     Return a tuple (exitcode, output).  output is None in debug mode."""
   571     # TODO: Use subprocess.Popen if we're running on Python 2.4
   571     # TODO: Use subprocess.Popen if we're running on Python 2.4
   572     if options.debug:
   572     if options.debug:
   573         proc = subprocess.Popen(cmd, shell=True)
   573         proc = subprocess.Popen(cmd, shell=True)
   606         except KeyboardInterrupt:
   606         except KeyboardInterrupt:
   607             vlog('# Handling keyboard interrupt')
   607             vlog('# Handling keyboard interrupt')
   608             cleanup()
   608             cleanup()
   609             raise
   609             raise
   610 
   610 
       
   611     for s, r in replacements:
       
   612         output = output.replace(s, r)
   611     return ret, splitnewlines(output)
   613     return ret, splitnewlines(output)
   612 
   614 
   613 def runone(options, test, skips, fails):
   615 def runone(options, test, skips, fails):
   614     '''tristate output:
   616     '''tristate output:
   615     None -> skipped
   617     None -> skipped
   680         elif not os.access(testpath, os.X_OK):
   682         elif not os.access(testpath, os.X_OK):
   681             return skip("not executable")
   683             return skip("not executable")
   682         runner = shtest
   684         runner = shtest
   683 
   685 
   684     # Make a tmp subdirectory to work in
   686     # Make a tmp subdirectory to work in
   685     tmpd = os.path.join(HGTMP, test)
   687     testtmp = os.environ["TESTTMP"] = os.path.join(HGTMP, test)
   686     os.mkdir(tmpd)
   688     os.mkdir(testtmp)
   687     os.chdir(tmpd)
   689     os.chdir(testtmp)
   688 
   690 
   689     if options.timeout > 0:
   691     if options.timeout > 0:
   690         signal.alarm(options.timeout)
   692         signal.alarm(options.timeout)
   691 
   693 
   692     ret, out = runner(testpath, options)
   694     ret, out = runner(testpath, options, [
       
   695         (testtmp, '$TESTTMP'),
       
   696         (':%s' % options.port, ':$HGPORT'),
       
   697         (':%s' % (options.port + 1), ':$HGPORT1'),
       
   698         (':%s' % (options.port + 2), ':$HGPORT2'),
       
   699         ])
   693     vlog("# Ret was:", ret)
   700     vlog("# Ret was:", ret)
   694 
   701 
   695     if options.timeout > 0:
   702     if options.timeout > 0:
   696         signal.alarm(0)
   703         signal.alarm(0)
   697 
   704 
   753 
   760 
   754     killdaemons()
   761     killdaemons()
   755 
   762 
   756     os.chdir(TESTDIR)
   763     os.chdir(TESTDIR)
   757     if not options.keep_tmpdir:
   764     if not options.keep_tmpdir:
   758         shutil.rmtree(tmpd, True)
   765         shutil.rmtree(testtmp, True)
   759     if skipped:
   766     if skipped:
   760         return None
   767         return None
   761     return ret == 0
   768     return ret == 0
   762 
   769 
   763 _hgpath = None
   770 _hgpath = None