##// END OF EJS Templates
run-tests: move TESTDIR out of a global...
Gregory Szorc -
r21341:cb88d4a0 default
parent child Browse files
Show More
@@ -432,7 +432,7 b' def usecorrectpython():'
432 if not findprogram(pyexename):
432 if not findprogram(pyexename):
433 print "WARNING: Cannot find %s in search path" % pyexename
433 print "WARNING: Cannot find %s in search path" % pyexename
434
434
435 def installhg(options):
435 def installhg(runner, options):
436 vlog("# Performing temporary installation of HG")
436 vlog("# Performing temporary installation of HG")
437 installerrs = os.path.join("tests", "install.err")
437 installerrs = os.path.join("tests", "install.err")
438 compiler = ''
438 compiler = ''
@@ -472,7 +472,7 b' def installhg(options):'
472 print line,
472 print line,
473 f.close()
473 f.close()
474 sys.exit(1)
474 sys.exit(1)
475 os.chdir(TESTDIR)
475 os.chdir(runner.testdir)
476
476
477 usecorrectpython()
477 usecorrectpython()
478
478
@@ -504,11 +504,11 b' def installhg(options):'
504 print 'WARNING: cannot fix hg.bat reference to python.exe'
504 print 'WARNING: cannot fix hg.bat reference to python.exe'
505
505
506 if options.anycoverage:
506 if options.anycoverage:
507 custom = os.path.join(TESTDIR, 'sitecustomize.py')
507 custom = os.path.join(runner.testdir, 'sitecustomize.py')
508 target = os.path.join(PYTHONDIR, 'sitecustomize.py')
508 target = os.path.join(PYTHONDIR, 'sitecustomize.py')
509 vlog('# Installing coverage trigger to %s' % target)
509 vlog('# Installing coverage trigger to %s' % target)
510 shutil.copyfile(custom, target)
510 shutil.copyfile(custom, target)
511 rc = os.path.join(TESTDIR, '.coveragerc')
511 rc = os.path.join(runner.testdir, '.coveragerc')
512 vlog('# Installing coverage rc to %s' % rc)
512 vlog('# Installing coverage rc to %s' % rc)
513 os.environ['COVERAGE_PROCESS_START'] = rc
513 os.environ['COVERAGE_PROCESS_START'] = rc
514 fn = os.path.join(INST, '..', '.coverage')
514 fn = os.path.join(INST, '..', '.coverage')
@@ -522,7 +522,7 b' def outputtimes(options):'
522 for test, timetaken in times:
522 for test, timetaken in times:
523 print cols % (timetaken, test)
523 print cols % (timetaken, test)
524
524
525 def outputcoverage(options):
525 def outputcoverage(runner, options):
526
526
527 vlog('# Producing coverage report')
527 vlog('# Producing coverage report')
528 os.chdir(PYTHONDIR)
528 os.chdir(PYTHONDIR)
@@ -533,13 +533,13 b' def outputcoverage(options):'
533 os.system(cmd)
533 os.system(cmd)
534
534
535 covrun('-c')
535 covrun('-c')
536 omit = ','.join(os.path.join(x, '*') for x in [BINDIR, TESTDIR])
536 omit = ','.join(os.path.join(x, '*') for x in [BINDIR, runner.testdir])
537 covrun('-i', '-r', '"--omit=%s"' % omit) # report
537 covrun('-i', '-r', '"--omit=%s"' % omit) # report
538 if options.htmlcov:
538 if options.htmlcov:
539 htmldir = os.path.join(TESTDIR, 'htmlcov')
539 htmldir = os.path.join(runner.testdir, 'htmlcov')
540 covrun('-i', '-b', '"--directory=%s"' % htmldir, '"--omit=%s"' % omit)
540 covrun('-i', '-b', '"--directory=%s"' % htmldir, '"--omit=%s"' % omit)
541 if options.annotate:
541 if options.annotate:
542 adir = os.path.join(TESTDIR, 'annotated')
542 adir = os.path.join(runner.testdir, 'annotated')
543 if not os.path.isdir(adir):
543 if not os.path.isdir(adir):
544 os.mkdir(adir)
544 os.mkdir(adir)
545 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
545 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
@@ -555,6 +555,7 b' class Test(object):'
555 path = os.path.join(testdir, test)
555 path = os.path.join(testdir, test)
556 errpath = os.path.join(testdir, '%s.err' % test)
556 errpath = os.path.join(testdir, '%s.err' % test)
557
557
558 self._testdir = testdir
558 self._test = test
559 self._test = test
559 self._path = path
560 self._path = path
560 self._options = options
561 self._options = options
@@ -847,7 +848,7 b' class TTest(Test):'
847
848
848 def _hghave(self, reqs, testtmp):
849 def _hghave(self, reqs, testtmp):
849 # TODO do something smarter when all other uses of hghave are gone.
850 # TODO do something smarter when all other uses of hghave are gone.
850 tdir = TESTDIR.replace('\\', '/')
851 tdir = self._testdir.replace('\\', '/')
851 proc = Popen4('%s -c "%s/hghave %s"' %
852 proc = Popen4('%s -c "%s/hghave %s"' %
852 (self._options.shell, tdir, ' '.join(reqs)),
853 (self._options.shell, tdir, ' '.join(reqs)),
853 testtmp, 0)
854 testtmp, 0)
@@ -1084,7 +1085,7 b' class TTest(Test):'
1084 return '+glob'
1085 return '+glob'
1085 return False
1086 return False
1086
1087
1087 def gettest(testdir, test, options, count):
1088 def gettest(runner, test, options, count):
1088 """Obtain a Test by looking at its filename.
1089 """Obtain a Test by looking at its filename.
1089
1090
1090 Returns a Test instance. The Test may not be runnable if it doesn't map
1091 Returns a Test instance. The Test may not be runnable if it doesn't map
@@ -1092,17 +1093,17 b' def gettest(testdir, test, options, coun'
1092 """
1093 """
1093
1094
1094 lctest = test.lower()
1095 lctest = test.lower()
1095 refpath = os.path.join(testdir, test)
1096 refpath = os.path.join(runner.testdir, test)
1096
1097
1097 runner = Test
1098 testcls = Test
1098
1099
1099 for ext, cls, out in testtypes:
1100 for ext, cls, out in testtypes:
1100 if lctest.endswith(ext):
1101 if lctest.endswith(ext):
1101 runner = cls
1102 testcls = cls
1102 refpath = os.path.join(testdir, test + out)
1103 refpath = os.path.join(runner.testdir, test + out)
1103 break
1104 break
1104
1105
1105 return runner(testdir, test, options, count, refpath)
1106 return testcls(runner.testdir, test, options, count, refpath)
1106
1107
1107 wifexited = getattr(os, "WIFEXITED", lambda x: False)
1108 wifexited = getattr(os, "WIFEXITED", lambda x: False)
1108 def run(cmd, wd, options, replacements, env):
1109 def run(cmd, wd, options, replacements, env):
@@ -1191,7 +1192,7 b' def scheduletests(runner, options, tests'
1191
1192
1192 def job(test, count):
1193 def job(test, count):
1193 try:
1194 try:
1194 t = gettest(TESTDIR, test, options, count)
1195 t = gettest(runner, test, options, count)
1195 done.put(t.run())
1196 done.put(t.run())
1196 t.cleanup()
1197 t.cleanup()
1197 except KeyboardInterrupt:
1198 except KeyboardInterrupt:
@@ -1225,7 +1226,7 b' def scheduletests(runner, options, tests'
1225 def runtests(runner, options, tests):
1226 def runtests(runner, options, tests):
1226 try:
1227 try:
1227 if INST:
1228 if INST:
1228 installhg(options)
1229 installhg(runner, options)
1229 _checkhglib("Testing")
1230 _checkhglib("Testing")
1230 else:
1231 else:
1231 usecorrectpython()
1232 usecorrectpython()
@@ -1265,7 +1266,7 b' def runtests(runner, options, tests):'
1265 outputtimes(options)
1266 outputtimes(options)
1266
1267
1267 if options.anycoverage:
1268 if options.anycoverage:
1268 outputcoverage(options)
1269 outputcoverage(runner, options)
1269 except KeyboardInterrupt:
1270 except KeyboardInterrupt:
1270 failed = True
1271 failed = True
1271 print "\ninterrupted!"
1272 print "\ninterrupted!"
@@ -1283,6 +1284,8 b' class TestRunner(object):'
1283
1284
1284 Tests rely on a lot of state. This object holds it for them.
1285 Tests rely on a lot of state. This object holds it for them.
1285 """
1286 """
1287 def __init__(self):
1288 self.testdir = None
1286
1289
1287 def main(args, parser=None):
1290 def main(args, parser=None):
1288 runner = TestRunner()
1291 runner = TestRunner()
@@ -1330,8 +1333,8 b' def main(args, parser=None):'
1330 # we do the randomness ourself to know what seed is used
1333 # we do the randomness ourself to know what seed is used
1331 os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32))
1334 os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32))
1332
1335
1333 global TESTDIR, HGTMP, INST, BINDIR, TMPBINDIR, PYTHONDIR, COVERAGE_FILE
1336 global HGTMP, INST, BINDIR, TMPBINDIR, PYTHONDIR, COVERAGE_FILE
1334 TESTDIR = os.environ["TESTDIR"] = os.getcwd()
1337 runner.testdir = os.environ['TESTDIR'] = os.getcwd()
1335 if options.tmpdir:
1338 if options.tmpdir:
1336 options.keep_tmpdir = True
1339 options.keep_tmpdir = True
1337 tmpdir = options.tmpdir
1340 tmpdir = options.tmpdir
@@ -1387,7 +1390,8 b' def main(args, parser=None):'
1387 # can run .../tests/run-tests.py test-foo where test-foo
1390 # can run .../tests/run-tests.py test-foo where test-foo
1388 # adds an extension to HGRC. Also include run-test.py directory to import
1391 # adds an extension to HGRC. Also include run-test.py directory to import
1389 # modules like heredoctest.
1392 # modules like heredoctest.
1390 pypath = [PYTHONDIR, TESTDIR, os.path.abspath(os.path.dirname(__file__))]
1393 pypath = [PYTHONDIR, runner.testdir,
1394 os.path.abspath(os.path.dirname(__file__))]
1391 # We have to augment PYTHONPATH, rather than simply replacing
1395 # We have to augment PYTHONPATH, rather than simply replacing
1392 # it, in case external libraries are only available via current
1396 # it, in case external libraries are only available via current
1393 # PYTHONPATH. (In particular, the Subversion bindings on OS X
1397 # PYTHONPATH. (In particular, the Subversion bindings on OS X
@@ -1397,9 +1401,9 b' def main(args, parser=None):'
1397 pypath.append(oldpypath)
1401 pypath.append(oldpypath)
1398 os.environ[IMPL_PATH] = os.pathsep.join(pypath)
1402 os.environ[IMPL_PATH] = os.pathsep.join(pypath)
1399
1403
1400 COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
1404 COVERAGE_FILE = os.path.join(runner.testdir, ".coverage")
1401
1405
1402 vlog("# Using TESTDIR", TESTDIR)
1406 vlog("# Using TESTDIR", runner.testdir)
1403 vlog("# Using HGTMP", HGTMP)
1407 vlog("# Using HGTMP", HGTMP)
1404 vlog("# Using PATH", os.environ["PATH"])
1408 vlog("# Using PATH", os.environ["PATH"])
1405 vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
1409 vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
General Comments 0
You need to be logged in to leave comments. Login now