tests/run-tests.py
changeset 21318 6b3d66e4d3be
parent 21317 58a599784a0c
child 21319 44c96e2bab20
equal deleted inserted replaced
21317:58a599784a0c 21318:6b3d66e4d3be
   549 
   549 
   550     Test instances can be run multiple times via run(). However, multiple
   550     Test instances can be run multiple times via run(). However, multiple
   551     runs cannot be run concurrently.
   551     runs cannot be run concurrently.
   552     """
   552     """
   553 
   553 
   554     def __init__(self, path, options, count):
   554     def __init__(self, path, options, count, refpath):
   555         self._path = path
   555         self._path = path
   556         self._options = options
   556         self._options = options
   557         self._count = count
   557         self._count = count
   558 
   558 
       
   559         # If we're not in --debug mode and reference output file exists,
       
   560         # check test output against it.
       
   561         if options.debug:
       
   562             self._refout = None # to match "out is None"
       
   563         elif os.path.exists(refpath):
       
   564             f = open(refpath, 'r')
       
   565             self._refout = f.read().splitlines(True)
       
   566             f.close()
       
   567         else:
       
   568             self._refout = []
       
   569 
   559         self._threadtmp = os.path.join(HGTMP, 'child%d' % count)
   570         self._threadtmp = os.path.join(HGTMP, 'child%d' % count)
   560         os.mkdir(self._threadtmp)
   571         os.mkdir(self._threadtmp)
   561 
   572 
   562     def cleanup(self):
   573     def cleanup(self):
   563         if self._threadtmp and not self._options.keep_tmpdir:
   574         if self._threadtmp and not self._options.keep_tmpdir:
   564             shutil.rmtree(self._threadtmp, True)
   575             shutil.rmtree(self._threadtmp, True)
   565 
   576 
   566     def run(self, result, refpath):
   577     def run(self, result):
   567         testtmp = os.path.join(self._threadtmp, os.path.basename(self._path))
   578         testtmp = os.path.join(self._threadtmp, os.path.basename(self._path))
   568         os.mkdir(testtmp)
   579         os.mkdir(testtmp)
   569         replacements, port = self._getreplacements(testtmp)
   580         replacements, port = self._getreplacements(testtmp)
   570         env = self._getenv(testtmp, port)
   581         env = self._getenv(testtmp, port)
   571         createhgrc(env['HGRCPATH'], self._options)
   582         createhgrc(env['HGRCPATH'], self._options)
   587             updateduration()
   598             updateduration()
   588             result.exception = e
   599             result.exception = e
   589 
   600 
   590         killdaemons(env['DAEMON_PIDS'])
   601         killdaemons(env['DAEMON_PIDS'])
   591 
   602 
   592         # If we're not in --debug mode and reference output file exists,
   603         result.refout = self._refout
   593         # check test output against it.
       
   594         if self._options.debug:
       
   595             result.refout = None # to match "out is None"
       
   596         elif os.path.exists(refpath):
       
   597             f = open(refpath, 'r')
       
   598             result.refout = f.read().splitlines(True)
       
   599             f.close()
       
   600         else:
       
   601             result.refout = []
       
   602 
   604 
   603         if not self._options.keep_tmpdir:
   605         if not self._options.keep_tmpdir:
   604             shutil.rmtree(testtmp)
   606             shutil.rmtree(testtmp)
   605 
   607 
   606     def _run(self, testtmp, replacements, env):
   608     def _run(self, testtmp, replacements, env):
  1082     vlog("# Test", test)
  1084     vlog("# Test", test)
  1083 
  1085 
  1084     if os.path.exists(err):
  1086     if os.path.exists(err):
  1085         os.remove(err)       # Remove any previous output files
  1087         os.remove(err)       # Remove any previous output files
  1086 
  1088 
  1087     t = runner(testpath, options, count)
  1089     t = runner(testpath, options, count, ref)
  1088     res = TestResult()
  1090     res = TestResult()
  1089     t.run(res, ref)
  1091     t.run(res)
  1090     t.cleanup()
  1092     t.cleanup()
  1091 
  1093 
  1092     if res.interrupted:
  1094     if res.interrupted:
  1093         log('INTERRUPTED: %s (after %d seconds)' % (test, res.duration))
  1095         log('INTERRUPTED: %s (after %d seconds)' % (test, res.duration))
  1094         raise KeyboardInterrupt()
  1096         raise KeyboardInterrupt()