run-tests: move debug into an argument to Test.__init__
authorGregory Szorc <gregory.szorc@gmail.com>
Tue, 22 Apr 2014 11:44:34 -0700
changeset 21510 97127c4ce460
parent 21509 d21d53ee0d7a
child 21511 3ec3e81a4110
run-tests: move debug into an argument to Test.__init__
tests/run-tests.py
--- a/tests/run-tests.py	Tue Apr 22 11:41:10 2014 -0700
+++ b/tests/run-tests.py	Tue Apr 22 11:44:34 2014 -0700
@@ -338,7 +338,8 @@
     # Status code reserved for skipped tests (used by hghave).
     SKIPPED_STATUS = 80
 
-    def __init__(self, options, path, count, tmpdir, abort, keeptmpdir=False):
+    def __init__(self, options, path, count, tmpdir, abort, keeptmpdir=False,
+                 debug=False):
         """Create a test from parameters.
 
         options are parsed command line options that control test execution.
@@ -354,6 +355,9 @@
 
         keeptmpdir determines whether to keep the test's temporary directory
         after execution. It defaults to removal (False).
+
+        debug mode will make the test execute verbosely, with unfiltered
+        output.
         """
 
         self.path = path
@@ -366,6 +370,7 @@
         self._threadtmp = tmpdir
         self._abort = abort
         self._keeptmpdir = keeptmpdir
+        self._debug = debug
         self._daemonpids = []
 
         self._finished = None
@@ -376,7 +381,7 @@
 
         # If we're not in --debug mode and reference output file exists,
         # check test output against it.
-        if options.debug:
+        if debug:
             self._refout = None # to match "out is None"
         elif os.path.exists(self._refpath):
             f = open(self._refpath, 'r')
@@ -546,7 +551,7 @@
             shutil.rmtree(self._threadtmp, True)
 
         if (self._ret != 0 or self._out != self._refout) and not self._skipped \
-            and not self._options.debug and self._out:
+            and not self._debug and self._out:
             f = open(self.errpath, 'wb')
             for line in self._out:
                 f.write(line)
@@ -670,7 +675,7 @@
         if os.name == 'nt':
             replacements.append((r'\r\n', '\n'))
         return run(cmd, self._testtmp, replacements, env, self._abort,
-                   debug=self._options.debug, timeout=self._options.timeout)
+                   debug=self._debug, timeout=self._options.timeout)
 
 class TTest(Test):
     """A "t test" is a test backed by a .t file."""
@@ -705,7 +710,7 @@
         vlog("# Running", cmd)
 
         exitcode, output = run(cmd, self._testtmp, replacements, env,
-                               self._abort, debug=self._options.debug,
+                               self._abort, debug=self._debug,
                                timeout=self._options.timeout)
         # Do not merge output if skipped. Return hghave message instead.
         # Similarly, with --debug, output is None.
@@ -761,7 +766,7 @@
         # can generate the surrounding doctest magic.
         inpython = False
 
-        if self._options.debug:
+        if self._debug:
             script.append('set -x\n')
         if os.getenv('MSYSTEM'):
             script.append('alias pwd="pwd -W"\n')
@@ -1490,7 +1495,8 @@
         tmpdir = os.path.join(self.hgtmp, 'child%d' % count)
 
         return testcls(self.options, refpath, count, tmpdir, self.abort,
-                       keeptmpdir=self.options.keep_tmpdir)
+                       keeptmpdir=self.options.keep_tmpdir,
+                       debug=self.options.debug)
 
     def _cleanup(self):
         """Clean up state from this test invocation."""