Skip to content

testing: tolerate \r\n as a newline separator in test output #54886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/cmd/internal/test2json/test2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ func (c *Converter) Exited(err error) {

var (
// printed by test on successful run.
bigPass = []byte("PASS\n")
bigPass = []byte("PASS\n")
bigPassCRLN = []byte("PASS\r\n")

// printed by test after a normal test failure.
bigFail = []byte("FAIL\n")
bigFail = []byte("FAIL\n")
bigFailCRLN = []byte("FAIL\r\n")

// printed by 'go test' along with an error if the test binary terminates
// with an error.
Expand Down Expand Up @@ -171,10 +173,11 @@ var (
// before or after emitting other events.
func (c *Converter) handleInputLine(line []byte) {
// Final PASS or FAIL.
if bytes.Equal(line, bigPass) || bytes.Equal(line, bigFail) || bytes.HasPrefix(line, bigFailErrorPrefix) {
if bytes.Equal(line, bigPass) || bytes.Equal(line, bigPassCRLN) ||
bytes.Equal(line, bigFail) || bytes.Equal(line, bigFailCRLN) || bytes.HasPrefix(line, bigFailErrorPrefix) {
c.flushReport(0)
c.output.write(line)
if bytes.Equal(line, bigPass) {
if bytes.Equal(line, bigPass) || bytes.Equal(line, bigPassCRLN) {
c.result = "pass"
} else {
c.result = "fail"
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/internal/test2json/testdata/debugserver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"Action":"run","Test":"Test1"}
{"Action":"output","Test":"Test1","Output":"=== RUN Test1\r\n"}
{"Action":"output","Test":"Test1","Output":"--- PASS: Test1 (0.00s)\r\n"}
{"Action":"pass","Test":"Test1"}
{"Action":"output","Output":"PASS\r\n"}
{"Action":"pass"}
3 changes: 3 additions & 0 deletions src/cmd/internal/test2json/testdata/debugserver.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=== RUN Test1
--- PASS: Test1 (0.00s)
PASS