Anonymous avatar Anonymous committed c455086

Add a --verbose option to runtest.py. (Baptiste Lepilleur) Fix (?) a deadlock using the --xml option on Windows.

Comments (0)

Files changed (4)

 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 
 __author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCmd.py 0.18.D001 2005/10/15 06:40:23 knight"
-__version__ = "0.18"
+__revision__ = "TestCmd.py 0.20.D001 2006/02/16 06:28:21 knight"
+__version__ = "0.20"
 
 import os
 import os.path
                        interpreter = None,
                        workdir = None,
                        subdir = None,
-                       verbose = 0,
+                       verbose = None,
                        match = None,
                        combine = 0):
         self._cwd = os.getcwd()
         self.description_set(description)
         self.program_set(program)
         self.interpreter_set(interpreter)
+        if verbose is None:
+            try:
+                verbose = max( 0, int(os.environ.get('TESTCMD_VERBOSE', 0)) )
+            except ValueError:
+                verbose = 0
         self.verbose_set(verbose)
         self.combine = combine
         if not match is None:
             self.status = p.wait()
         if chdir:
             os.chdir(oldcwd)
+        if self.verbose >= 2:
+            write = sys.stdout.write
+            write('============ STATUS: %d\n' % self.status)
+            out = self.stdout()
+            if out or self.verbose >= 3:
+                write('============ BEGIN STDOUT (len=%d):\n' % len(out))
+                write(out)
+                write('============ END STDOUT\n')
+            err = self.stderr()
+            if err or self.verbose >= 3:
+                write('============ BEGIN STDERR (len=%d)\n' % len(err))
+                write(err)
+                write('============ END STDERR\n')
 
     def sleep(self, seconds = default_sleep_seconds):
         """Sleeps at least the specified number of seconds.  If no

etc/TestCommon.py

 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 
 __author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.18.D001 2005/10/15 06:40:23 knight"
-__version__ = "0.18"
+__revision__ = "TestCommon.py 0.20.D001 2006/02/16 06:28:21 knight"
+__version__ = "0.20"
 
 import os
 import os.path
   -q, --quiet                 Don't print the test being executed.
   -t, --time                  Print test execution time.
   -v version                  Specify the SCons version.
+  --verbose=LEVEL             Set verbose level: 1 = print executed commands,
+                                2 = print commands and non-zero output,
+                                3 = print commands and all output.
   -X                          Test script is executable, don't feed to Python.
   -x SCRIPT, --exec SCRIPT    Test SCRIPT.
   --xml                       Print results in SCons XML format.
                              'debug', 'file=', 'help', 'output=',
                              'package=', 'passed', 'python=', 'quiet',
                              'version=', 'exec=', 'time',
-                             'xml'])
+                             'verbose=', 'xml'])
 
 for o, a in opts:
     if o == '-a' or o == '--all':
         printcommand = 0
     elif o == '-t' or o == '--time':
         print_time = lambda fmt, time: sys.stdout.write(fmt % time)
+    elif o in ['--verbose']:
+        os.environ['TESTCMD_VERBOSE'] = a
     elif o == '-v' or o == '--version':
         version = a
     elif o == '-X':
             return status >> 8
 else:
     def spawn_it(command_args):
-	command_args = map(escape, command_args)
+        command_args = map(escape, command_args)
+        command_args = map(lambda s: string.replace(s, '\\','\\\\'), command_args)
         return os.spawnv(os.P_WAIT, command_args[0], command_args)
 
 class Base:
         def execute(self):
             (tochild, fromchild, childerr) = os.popen3(self.command_str)
             tochild.close()
+            self.stderr = childerr.read()
             self.stdout = fromchild.read()
-            self.stderr = childerr.read()
             fromchild.close()
             self.status = childerr.close()
             if not self.status:
     $WINDOWSIMPLIBPREFIX construction variables.  The old names are now
     deprecated, but preserved for backwards compatibility.
 
+  - Fix (?) a runtest.py hang on Windows when the --xml option is used.
+
   From Chen Lee:
 
   - Add x64 support for Microsoft Visual Studio 8.
 
   - Speed up the SCons/EnvironmentTests.py unit tests.
 
+  - Add a --verbose= option to runtest.py to print executed commands
+    and their output at various levels.
+
   From Christian Maaser:
 
   - Add support for Visual Studio Express Editions.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.