diff options
author | Damian Gryski <[email protected]> | 2023-03-30 21:35:18 -0700 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-03-31 09:07:13 +0200 |
commit | 9182664845affa6715c39d38c14c396ab8f907c7 (patch) | |
tree | ff911d674b2a952a15ff9e8a261fd4e0199a2168 /main.go | |
parent | a2f95d6b87418cc4a75892a43a6a405674aab876 (diff) | |
download | tinygo-9182664845affa6715c39d38c14c396ab8f907c7.tar.gz tinygo-9182664845affa6715c39d38c14c396ab8f907c7.zip |
testing: make test output unbuffered when verbose
Fixes #3579
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -249,10 +249,16 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options flags = append(flags, "-test.count="+strconv.Itoa(testConfig.Count)) } - buf := bytes.Buffer{} + var buf bytes.Buffer + var output io.Writer = &buf + // Send the test output to stdout if -v or -bench + if testConfig.Verbose || testConfig.BenchRegexp != "" { + output = os.Stdout + } + passed := false var duration time.Duration - result, err := buildAndRun(pkgName, config, &buf, flags, nil, 0, func(cmd *exec.Cmd, result builder.BuildResult) error { + result, err := buildAndRun(pkgName, config, output, flags, nil, 0, func(cmd *exec.Cmd, result builder.BuildResult) error { if testConfig.CompileOnly || outpath != "" { // Write test binary to the specified file name. if outpath == "" { @@ -310,11 +316,9 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options duration = time.Since(start) passed = err == nil - // print the test output if - // 1) the tests passed and in verbose mode - // 2) the tests failed - // 3) running benchmarks - if (passed && testConfig.Verbose) || (!passed) || (testConfig.BenchRegexp != "") { + // if verbose or benchmarks, then output is already going to stdout + // However, if we failed and weren't printing to stdout, print the output we accumulated. + if !passed && output != os.Stdout { buf.WriteTo(stdout) } |