From a2c3ba474a5ad47539b5ecf7218db272fab8359f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sun, 7 Apr 2019 01:42:44 +0200 Subject: [PATCH] mtest: fix TAP with --verbose (#5160) * mtest: fix TAP with --verbose TAP needs to process the test stdout even if --verbose is passed. Capture it to a separate temporary file, and print it at the end of the test if --verbose was passed. In the future, we could parse it on the fly and print the result of each TAP test point in verbose mode. * Prefer "stderr is stdout" to "==" The previous commit used "==" in accordance with the preexisting code, but reviewers preferred using "is" instead. Fix both occurrences. --- mesonbuild/mtest.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index dc820841f..0f15690f2 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -490,7 +490,9 @@ class SingleTestRunner: stderr = None if not self.options.verbose: stdout = tempfile.TemporaryFile("wb+") - stderr = tempfile.TemporaryFile("wb+") if self.options and self.options.split else stdout + stderr = tempfile.TemporaryFile("wb+") if self.options.split else stdout + if self.test.protocol == 'tap' and stderr is stdout: + stdout = tempfile.TemporaryFile("wb+") # Let gdb handle ^C instead of us if self.options.gdb: @@ -570,17 +572,16 @@ class SingleTestRunner: endtime = time.time() duration = endtime - starttime if additional_error is None: - if stdout is None: # if stdout is None stderr should be as well + if stdout is None: stdo = '' - stde = '' else: stdout.seek(0) stdo = decode(stdout.read()) - if stderr != stdout: - stderr.seek(0) - stde = decode(stderr.read()) - else: - stde = "" + if stderr is None or stderr is stdout: + stde = '' + else: + stderr.seek(0) + stde = decode(stderr.read()) else: stdo = "" stde = additional_error @@ -590,6 +591,8 @@ class SingleTestRunner: if self.test.protocol == 'exitcode': return TestRun.make_exitcode(self.test, p.returncode, duration, stdo, stde, cmd) else: + if self.options.verbose: + print(stdo, end='') return TestRun.make_tap(self.test, p.returncode, duration, stdo, stde, cmd)