bazel-contrib / bazel-contrib/rules_go

Writing to stdout without a newline causes `go_test` output errors

Open
#3,568 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### 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`:
```



=== RUN TestOutputMetrics
=== PAUSE TestOutputMetrics
=== CONT TestOutputMetrics



=== 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)



=== RUN TestOutputMetrics/Missing_IntVal
=== PAUSE TestOutputMetrics/Missing_IntVal
=== CONT TestOutputMetrics/Missing_IntVal



=== RUN TestOutputMetrics/Missing_Name
=== PAUSE TestOutputMetrics/Missing_Name
=== CONT TestOutputMetrics/Missing_Name



=== RUN TestOutputMetrics/Successful_Test
=== PAUSE TestOutputMetrics/Successful_Test
=== CONT TestOutputMetrics/Successful_Test


```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with a Bazel go_test that calls fmt.Print without a trailing newline, then trace how the test output is converted into test.xml. Compare that output with test.log; done means the test exits successfully and test.xml records the passing tests without spurious errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.