From 02cae725ed116ae6cd996fe3bf5888f7f8f61b97 Mon Sep 17 00:00:00 2001 From: anatoly techtonik Date: Tue, 18 Dec 2012 14:40:36 +0300 Subject: runtest.py: Enable -o, --output to save stdout/stderr into a file --- runtest.py | 22 +++++++++++++++------- src/CHANGES.txt | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/runtest.py b/runtest.py index 4c12298..6beb4ba 100644 --- a/runtest.py +++ b/runtest.py @@ -113,7 +113,6 @@ print_passed_summary = None python3incompatibilities = None scons = None scons_exec = None -outputfile = None qmtest = None testlistfile = None version = '' @@ -199,6 +198,8 @@ class PassThroughOptionParser(OptionParser): parser = PassThroughOptionParser(add_help_option=False) parser.add_option('-a', '--all', action='store_true', help="Run all tests.") +parser.add_option('-o', '--output', + help="Save the output from a test run to the log file.") parser.add_option('--xml', help="Save results to file in SCons XML format.") (options, args) = parser.parse_args() @@ -207,11 +208,11 @@ parser.add_option('--xml', #print "args:", args -opts, args = getopt.getopt(args, "3b:def:hj:klno:P:p:qsv:Xx:t", +opts, args = getopt.getopt(args, "3b:def:hj:klnP:p:qsv:Xx:t", ['baseline=', 'builddir=', 'debug', 'external', 'file=', 'help', 'no-progress', 'jobs=', - 'list', 'no-exec', 'nopipefiles', 'output=', + 'list', 'no-exec', 'nopipefiles', 'package=', 'passed', 'python=', 'qmtest', 'quiet', 'short-progress', 'time', 'version=', 'exec=', @@ -251,10 +252,6 @@ for o, a in opts: execute_tests = None elif o in ['--nopipefiles']: allow_pipe_files = False - elif o in ['-o', '--output']: - if a != '-' and not os.path.isabs(a): - a = os.path.join(cwd, a) - outputfile = a elif o in ['-p', '--package']: package = a elif o in ['--passed']: @@ -311,6 +308,17 @@ class Unbuffered(object): sys.stdout = Unbuffered(sys.stdout) sys.stderr = Unbuffered(sys.stderr) +if options.output: + logfile = open(options.output, 'w') + class Tee(object): + def __init__(self, openfile, stream): + self.file = openfile + self.stream = stream + def write(self, data): + self.file.write(data) + self.stream.write(data) + sys.stdout = Tee(logfile, sys.stdout) + sys.stderr = Tee(logfile, sys.stderr) # --- define helpers ---- if sys.platform in ('win32', 'cygwin'): diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 736160f..e8aa5ee 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -16,6 +16,8 @@ RELEASE 2.X.X - * exit with an error if no tests were found * removed --noqmtest option - this behavior is by default * replaced `-o FILE --xml` combination with `--xml FILE` + * changed `-o, --output FILE` option to capture stdout/stderr output + from runtest.py From Juan Lang: - Fix WiX Tool to use .wixobj rather than .wxiobj for compiler output -- cgit v0.12