comparison tests/run-tests.py @ 21510:97127c4ce460

run-tests: move debug into an argument to Test.__init__
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 22 Apr 2014 11:44:34 -0700
parents d21d53ee0d7a
children 3ec3e81a4110
comparison
equal deleted inserted replaced
21509:d21d53ee0d7a 21510:97127c4ce460
336 """ 336 """
337 337
338 # Status code reserved for skipped tests (used by hghave). 338 # Status code reserved for skipped tests (used by hghave).
339 SKIPPED_STATUS = 80 339 SKIPPED_STATUS = 80
340 340
341 def __init__(self, options, path, count, tmpdir, abort, keeptmpdir=False): 341 def __init__(self, options, path, count, tmpdir, abort, keeptmpdir=False,
342 debug=False):
342 """Create a test from parameters. 343 """Create a test from parameters.
343 344
344 options are parsed command line options that control test execution. 345 options are parsed command line options that control test execution.
345 346
346 path is the full path to the file defining the test. 347 path is the full path to the file defining the test.
352 abort is a flag that turns to True if test execution should be aborted. 353 abort is a flag that turns to True if test execution should be aborted.
353 It is consulted periodically during the execution of tests. 354 It is consulted periodically during the execution of tests.
354 355
355 keeptmpdir determines whether to keep the test's temporary directory 356 keeptmpdir determines whether to keep the test's temporary directory
356 after execution. It defaults to removal (False). 357 after execution. It defaults to removal (False).
358
359 debug mode will make the test execute verbosely, with unfiltered
360 output.
357 """ 361 """
358 362
359 self.path = path 363 self.path = path
360 self.name = os.path.basename(path) 364 self.name = os.path.basename(path)
361 self._testdir = os.path.dirname(path) 365 self._testdir = os.path.dirname(path)
364 self._options = options 368 self._options = options
365 self._count = count 369 self._count = count
366 self._threadtmp = tmpdir 370 self._threadtmp = tmpdir
367 self._abort = abort 371 self._abort = abort
368 self._keeptmpdir = keeptmpdir 372 self._keeptmpdir = keeptmpdir
373 self._debug = debug
369 self._daemonpids = [] 374 self._daemonpids = []
370 375
371 self._finished = None 376 self._finished = None
372 self._ret = None 377 self._ret = None
373 self._out = None 378 self._out = None
374 self._skipped = None 379 self._skipped = None
375 self._testtmp = None 380 self._testtmp = None
376 381
377 # If we're not in --debug mode and reference output file exists, 382 # If we're not in --debug mode and reference output file exists,
378 # check test output against it. 383 # check test output against it.
379 if options.debug: 384 if debug:
380 self._refout = None # to match "out is None" 385 self._refout = None # to match "out is None"
381 elif os.path.exists(self._refpath): 386 elif os.path.exists(self._refpath):
382 f = open(self._refpath, 'r') 387 f = open(self._refpath, 'r')
383 self._refout = f.read().splitlines(True) 388 self._refout = f.read().splitlines(True)
384 f.close() 389 f.close()
544 if not self._keeptmpdir: 549 if not self._keeptmpdir:
545 shutil.rmtree(self._testtmp, True) 550 shutil.rmtree(self._testtmp, True)
546 shutil.rmtree(self._threadtmp, True) 551 shutil.rmtree(self._threadtmp, True)
547 552
548 if (self._ret != 0 or self._out != self._refout) and not self._skipped \ 553 if (self._ret != 0 or self._out != self._refout) and not self._skipped \
549 and not self._options.debug and self._out: 554 and not self._debug and self._out:
550 f = open(self.errpath, 'wb') 555 f = open(self.errpath, 'wb')
551 for line in self._out: 556 for line in self._out:
552 f.write(line) 557 f.write(line)
553 f.close() 558 f.close()
554 559
668 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, self.path) 673 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, self.path)
669 vlog("# Running", cmd) 674 vlog("# Running", cmd)
670 if os.name == 'nt': 675 if os.name == 'nt':
671 replacements.append((r'\r\n', '\n')) 676 replacements.append((r'\r\n', '\n'))
672 return run(cmd, self._testtmp, replacements, env, self._abort, 677 return run(cmd, self._testtmp, replacements, env, self._abort,
673 debug=self._options.debug, timeout=self._options.timeout) 678 debug=self._debug, timeout=self._options.timeout)
674 679
675 class TTest(Test): 680 class TTest(Test):
676 """A "t test" is a test backed by a .t file.""" 681 """A "t test" is a test backed by a .t file."""
677 682
678 SKIPPED_PREFIX = 'skipped: ' 683 SKIPPED_PREFIX = 'skipped: '
703 708
704 cmd = '%s "%s"' % (self._options.shell, fname) 709 cmd = '%s "%s"' % (self._options.shell, fname)
705 vlog("# Running", cmd) 710 vlog("# Running", cmd)
706 711
707 exitcode, output = run(cmd, self._testtmp, replacements, env, 712 exitcode, output = run(cmd, self._testtmp, replacements, env,
708 self._abort, debug=self._options.debug, 713 self._abort, debug=self._debug,
709 timeout=self._options.timeout) 714 timeout=self._options.timeout)
710 # Do not merge output if skipped. Return hghave message instead. 715 # Do not merge output if skipped. Return hghave message instead.
711 # Similarly, with --debug, output is None. 716 # Similarly, with --debug, output is None.
712 if exitcode == self.SKIPPED_STATUS or output is None: 717 if exitcode == self.SKIPPED_STATUS or output is None:
713 return exitcode, output 718 return exitcode, output
759 764
760 # We keep track of whether or not we're in a Python block so we 765 # We keep track of whether or not we're in a Python block so we
761 # can generate the surrounding doctest magic. 766 # can generate the surrounding doctest magic.
762 inpython = False 767 inpython = False
763 768
764 if self._options.debug: 769 if self._debug:
765 script.append('set -x\n') 770 script.append('set -x\n')
766 if os.getenv('MSYSTEM'): 771 if os.getenv('MSYSTEM'):
767 script.append('alias pwd="pwd -W"\n') 772 script.append('alias pwd="pwd -W"\n')
768 773
769 for n, l in enumerate(lines): 774 for n, l in enumerate(lines):
1488 1493
1489 refpath = os.path.join(self.testdir, test) 1494 refpath = os.path.join(self.testdir, test)
1490 tmpdir = os.path.join(self.hgtmp, 'child%d' % count) 1495 tmpdir = os.path.join(self.hgtmp, 'child%d' % count)
1491 1496
1492 return testcls(self.options, refpath, count, tmpdir, self.abort, 1497 return testcls(self.options, refpath, count, tmpdir, self.abort,
1493 keeptmpdir=self.options.keep_tmpdir) 1498 keeptmpdir=self.options.keep_tmpdir,
1499 debug=self.options.debug)
1494 1500
1495 def _cleanup(self): 1501 def _cleanup(self):
1496 """Clean up state from this test invocation.""" 1502 """Clean up state from this test invocation."""
1497 1503
1498 if self.options.keep_tmpdir: 1504 if self.options.keep_tmpdir: