diff options
author | Mats Wichmann <mats@linux.com> | 2021-11-10 14:55:37 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2021-11-10 14:55:37 (GMT) |
commit | b89ae1563a42ffd10bbeef49c5ebc3b00b69c7bf (patch) | |
tree | 4755b62203dc2e088621d4f2b04f40b5c2db92be | |
parent | fc2facd7b42106ce07a551e5d7fa2a3100716d32 (diff) | |
download | SCons-b89ae1563a42ffd10bbeef49c5ebc3b00b69c7bf.zip SCons-b89ae1563a42ffd10bbeef49c5ebc3b00b69c7bf.tar.gz SCons-b89ae1563a42ffd10bbeef49c5ebc3b00b69c7bf.tar.bz2 |
Some adjustments to runtest.py
* Close a hole where if logging (-o) *and* multi-job (-j),
the feedback from the tests was not logged. (-j)
* Clear list of failed tests if no tests failed.
* add a flush method to the Tee class, there are error conditions
where the lack of a flush threw an exception.
Signed-off-by: Mats Wichmann <mats@linux.com>
-rwxr-xr-x | runtest.py | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -14,6 +14,11 @@ This script adds SCons/ and testing/ directories to PYTHONPATH, performs test discovery and processes tests according to options. """ +# TODO: normalize requested and testlist/exclude paths for easier comparison. +# e.g.: "runtest foo/bar" on windows will produce paths like foo/bar\test.py +# this is hard to match with excludelists, and makes those both os.sep-specific +# and command-line-typing specific. + import argparse import glob import os @@ -190,9 +195,10 @@ if args.excludelistfile: ) sys.exit(1) -if args.jobs > 1: - # don't let tests write stdout/stderr directly if multi-job, - # else outputs will interleave and be hard to read +if args.jobs > 1 or args.output: + # 1. don't let tests write stdout/stderr directly if multi-job, + # else outputs will interleave and be hard to read. + # 2. If we're going to write a logfile, we also need to catch the output. catch_output = True if not args.printcommand: @@ -231,14 +237,23 @@ sys.stderr = Unbuffered(sys.stderr) # print = functools.partial(print, flush) if args.output: - logfile = open(args.output, 'w') class Tee: def __init__(self, openfile, stream): self.file = openfile self.stream = stream + def write(self, data): self.file.write(data) self.stream.write(data) + + def flush(self, data): + self.file.flush(data) + self.stream.flush(data) + + logfile = open(args.output, 'w') + # this is not ideal: we monkeypatch stdout/stderr a second time + # (already did for Unbuffered), so here we can't easily detect what + # state we're in on closedown. Just hope it's okay... sys.stdout = Tee(logfile, sys.stdout) sys.stderr = Tee(logfile, sys.stderr) @@ -831,12 +846,13 @@ if len(tests) != 1 and args.execute_tests: sys.stdout.write("\t" + "\n\t".join(paths) + "\n") # save the fails to a file -if fail and args.error_log: - paths = [x.path for x in fail] - #print(f"DEBUG: Writing fails to {args.error_log}") +if args.error_log: with open(args.error_log, "w") as f: - for test in paths: - print(test, file=f) + if fail: + paths = [x.path for x in fail] + for test in paths: + print(test, file=f) + # if there are no fails, file will be cleared if args.xml: if args.output == '-': |