comparison tests/run-tests.py @ 21304:e626a67da4ba

run-tests: clean up temp directory variables testtmp is an implementation detail. It didn't need to be exposed to the world. threadtmp is derived from count. It is now created as part of the constructor and mostly hidden from the outside world.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 19 Apr 2014 13:29:26 -0700
parents 21a706020dd6
children d7a7825ff2cf
comparison
equal deleted inserted replaced
21303:21a706020dd6 21304:e626a67da4ba
545 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit) 545 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
546 546
547 class Test(object): 547 class Test(object):
548 """Encapsulates a single, runnable test.""" 548 """Encapsulates a single, runnable test."""
549 549
550 def __init__(self, path, options, threadtmp, count): 550 def __init__(self, path, options, count):
551 self._path = path 551 self._path = path
552 self._options = options 552 self._options = options
553 self._threadtmp = threadtmp 553
554 554 self.threadtmp = os.path.join(HGTMP, 'child%d' % count)
555 self.testtmp = os.path.join(threadtmp, os.path.basename(path)) 555 os.mkdir(self.threadtmp)
556 os.mkdir(self.testtmp) 556
557 self._testtmp = os.path.join(self.threadtmp, os.path.basename(path))
558 os.mkdir(self._testtmp)
557 559
558 self._setreplacements(count) 560 self._setreplacements(count)
559 561
560 def run(self): 562 def run(self):
561 env = self._getenv() 563 env = self._getenv()
579 581
580 if os.name == 'nt': 582 if os.name == 'nt':
581 r.append( 583 r.append(
582 (''.join(c.isalpha() and '[%s%s]' % (c.lower(), c.upper()) or 584 (''.join(c.isalpha() and '[%s%s]' % (c.lower(), c.upper()) or
583 c in '/\\' and r'[/\\]' or c.isdigit() and c or '\\' + c 585 c in '/\\' and r'[/\\]' or c.isdigit() and c or '\\' + c
584 for c in self.testtmp), '$TESTTMP')) 586 for c in self._testtmp), '$TESTTMP'))
585 else: 587 else:
586 r.append((re.escape(self.testtmp), '$TESTTMP')) 588 r.append((re.escape(self._testtmp), '$TESTTMP'))
587 589
588 self._replacements = r 590 self._replacements = r
589 self._port = port 591 self._port = port
590 592
591 def _getenv(self): 593 def _getenv(self):
592 env = os.environ.copy() 594 env = os.environ.copy()
593 env['TESTTMP'] = self.testtmp 595 env['TESTTMP'] = self._testtmp
594 env['HOME'] = self.testtmp 596 env['HOME'] = self._testtmp
595 env["HGPORT"] = str(self._port) 597 env["HGPORT"] = str(self._port)
596 env["HGPORT1"] = str(self._port + 1) 598 env["HGPORT1"] = str(self._port + 1)
597 env["HGPORT2"] = str(self._port + 2) 599 env["HGPORT2"] = str(self._port + 2)
598 env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc') 600 env["HGRCPATH"] = os.path.join(self.threadtmp, '.hgrc')
599 env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids') 601 env["DAEMON_PIDS"] = os.path.join(self.threadtmp, 'daemon.pids')
600 env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' 602 env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
601 env["HGMERGE"] = "internal:merge" 603 env["HGMERGE"] = "internal:merge"
602 env["HGUSER"] = "test" 604 env["HGUSER"] = "test"
603 env["HGENCODING"] = "ascii" 605 env["HGENCODING"] = "ascii"
604 env["HGENCODINGMODE"] = "strict" 606 env["HGENCODINGMODE"] = "strict"
632 return run(cmd, wd, options, replacements, env) 634 return run(cmd, wd, options, replacements, env)
633 635
634 class PythonTest(Test): 636 class PythonTest(Test):
635 """A Python-based test.""" 637 """A Python-based test."""
636 def _run(self, replacements, env): 638 def _run(self, replacements, env):
637 return pytest(self._path, self.testtmp, self._options, replacements, 639 return pytest(self._path, self._testtmp, self._options, replacements,
638 env) 640 env)
639 641
640 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search 642 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
641 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub 643 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
642 escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256)) 644 escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256))
895 897
896 class TTest(Test): 898 class TTest(Test):
897 """A "t test" is a test backed by a .t file.""" 899 """A "t test" is a test backed by a .t file."""
898 900
899 def _run(self, replacements, env): 901 def _run(self, replacements, env):
900 return tsttest(self._path, self.testtmp, self._options, replacements, 902 return tsttest(self._path, self._testtmp, self._options, replacements,
901 env) 903 env)
902 904
903 wifexited = getattr(os, "WIFEXITED", lambda x: False) 905 wifexited = getattr(os, "WIFEXITED", lambda x: False)
904 def run(cmd, wd, options, replacements, env): 906 def run(cmd, wd, options, replacements, env):
905 """Run command in a sub-process, capturing the output (stdout and stderr). 907 """Run command in a sub-process, capturing the output (stdout and stderr).
1020 vlog("# Test", test) 1022 vlog("# Test", test)
1021 1023
1022 if os.path.exists(err): 1024 if os.path.exists(err):
1023 os.remove(err) # Remove any previous output files 1025 os.remove(err) # Remove any previous output files
1024 1026
1025 # Make a tmp subdirectory to work in 1027 t = runner(testpath, options, count)
1026 threadtmp = os.path.join(HGTMP, "child%d" % count)
1027 os.mkdir(threadtmp)
1028
1029 t = runner(testpath, options, threadtmp, count)
1030 1028
1031 starttime = time.time() 1029 starttime = time.time()
1032 try: 1030 try:
1033 ret, out = t.run() 1031 ret, out = t.run()
1034 except KeyboardInterrupt: 1032 except KeyboardInterrupt:
1100 sys.stdout.write(result[0]) 1098 sys.stdout.write(result[0])
1101 sys.stdout.flush() 1099 sys.stdout.flush()
1102 iolock.release() 1100 iolock.release()
1103 1101
1104 if not options.keep_tmpdir: 1102 if not options.keep_tmpdir:
1105 shutil.rmtree(threadtmp, True) 1103 shutil.rmtree(t.threadtmp, True)
1106 return result 1104 return result
1107 1105
1108 _hgpath = None 1106 _hgpath = None
1109 1107
1110 def _gethgpath(): 1108 def _gethgpath():