rules_go
rules_go copied to clipboard
Writing to stdout without a newline causes `go_test` output errors
What version of rules_go are you using?
v.0.39.1
What version of gazelle are you using?
v.0.30.0
What version of Bazel are you using?
5.4.0
Does this issue reproduce with the latest releases of all the above?
Unsure re: Bazel version, yes re: rules/Gazelle
What operating system and processor architecture are you using?
MacOS v13.3.1, m1
Any other potentially useful information about your toolchain?
N/A
What did you do?
Function tested with a go_test
test outputs text to stdout via fmt.Printf
without a newline. In the below example, Invalid data found for filename: path/to/test/file.go, skipping
is outputted via fmt.Printf
.
This was discovered while troubleshooting a flaky test: this was a parallel execution, and we were able to replicate with 100% accuracy by adding a fmt.Print
statement to the test function itself.
What did you expect to see?
Tests successfully passing, with a clean test.xml
output file.
What did you see instead?
test.log
seems fine, but test.xml
outputs errors. Test execution exits with a status code of 0.
test.log
:
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //path/to/project:go_default_test
-----------------------------------------------------------------------------
=== RUN TestOutputMetrics
=== PAUSE TestOutputMetrics
=== CONT TestOutputMetrics
=== RUN TestOutputMetrics/Successful_Test
=== PAUSE TestOutputMetrics/Successful_Test
=== RUN TestOutputMetrics/Missing_Name
=== PAUSE TestOutputMetrics/Missing_Name
=== RUN TestOutputMetrics/Missing_IntVal
=== PAUSE TestOutputMetrics/Missing_IntVal
=== RUN TestOutputMetrics/Bad_Int_Val
=== PAUSE TestOutputMetrics/Bad_Int_Val
=== CONT TestOutputMetrics/Successful_Test
=== CONT TestOutputMetrics/Missing_Name
=== CONT TestOutputMetrics/Missing_IntVal
=== CONT TestOutputMetrics/Bad_Int_Val
Invalid data found for filename: path/to/test/file.go, skipping--- PASS: TestOutputMetrics (0.00s)
--- PASS: TestOutputMetrics/Successful_Test (0.00s)
--- PASS: TestOutputMetrics/Missing_Name (0.00s)
--- PASS: TestOutputMetrics/Bad_Int_Val (0.00s)
--- PASS: TestOutputMetrics/Missing_IntVal (0.00s)
PASS
test.xml
:
<testsuites>
<testsuite errors="5" failures="0" skipped="0" tests="5" time="0.005" name="github.com/org/repo/path/to/project">
<testcase classname="project" name="TestOutputMetrics" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestOutputMetrics
=== PAUSE TestOutputMetrics
=== CONT TestOutputMetrics
</error>
</testcase>
<testcase classname="project" name="TestOutputMetrics/Bad_Int_Val" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestOutputMetrics/Bad_Int_Val
=== PAUSE TestOutputMetrics/Bad_Int_Val
=== CONT TestOutputMetrics/Bad_Int_Val
Invalid data found for filename: path/to/test/file.go, skipping--- PASS: TestOutputMetrics (0.00s)
 --- PASS: TestOutputMetrics/Successful_Test (0.00s)
 --- PASS: TestOutputMetrics/Missing_Name (0.00s)
 --- PASS: TestOutputMetrics/Bad_Int_Val (0.00s)
 --- PASS: TestOutputMetrics/Missing_IntVal (0.00s)
</error>
</testcase>
<testcase classname="project" name="TestOutputMetrics/Missing_IntVal" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestOutputMetrics/Missing_IntVal
=== PAUSE TestOutputMetrics/Missing_IntVal
=== CONT TestOutputMetrics/Missing_IntVal
</error>
</testcase>
<testcase classname="project" name="TestOutputMetrics/Missing_Name" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestOutputMetrics/Missing_Name
=== PAUSE TestOutputMetrics/Missing_Name
=== CONT TestOutputMetrics/Missing_Name
</error>
</testcase>
<testcase classname="project" name="TestOutputMetrics/Successful_Test" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestOutputMetrics/Successful_Test
=== PAUSE TestOutputMetrics/Successful_Test
=== CONT TestOutputMetrics/Successful_Test
</error>
</testcase>
</testsuite>
</testsuites>
This may be fixed by updating our copy of test2json.go
to https://github.com/golang/go/commit/1c72ee7f13831b215b8744f6b35bc4fd53aba5e2#diff-aba3251fae880161e12c38219025123ca9af7607a42f87c7234cb201c770fa04, which was made in response to https://github.com/golang/go/issues/26325.
@bryceitoc9 Would you be interested in turning that into a PR? I could support you along the way.
We also ran into this issue, created https://github.com/bazelbuild/rules_go/pull/3662 to hopefully address it as suggested.
I just patched this in our repo and noticed that it didn't solve the parsing issue into test.xml. This issue will need to be reopened.