Skip to content
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

test2json: associate streaming log output with the originating test #38189

Closed
wants to merge 5 commits into from
Closed
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
62 changes: 62 additions & 0 deletions src/cmd/go/testdata/script/test_json_issue38050.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[short] skip

# Run go test -json on a contrived test suite that
# runs tests in parallel, some of which fail with
# output. We assert here that the t.Error logs
# are correctly attributed to the originating test
# cases by the test2json utility.
! go test -json -short -v parallel

# Check for run action
stdout '"Package":"parallel"'

# Check for correctly attributed log/failure output
stdout '"Action":"output","Package":"parallel","Test":"TestToUpper1/should_fail","Output":" TestToUpper1/should_fail: parallel_test.go:32: strings.ToUpper\(\\"lower case\\"\) = \\"LOWER CASE\\"; want \\"lower case\\"\\n"}'
stdout '"Action":"output","Package":"parallel","Test":"TestToUpper2/should_fail","Output":" TestToUpper2/should_fail: parallel_test.go:32: strings.ToUpper\(\\"lower case\\"\) = \\"LOWER CASE\\"; want \\"lower case\\"\\n"}'

# Check for run action via go tool test2json
go test -o $WORK/tmp/parallel.test$GOEXE -c parallel
! go tool test2json -p parallel $WORK/tmp/parallel.test$GOEXE -test.v
stdout '"Package":"parallel"'

# Check for correctly attributed log/failure output via go tool test2json
stdout '"Action":"output","Package":"parallel","Test":"TestToUpper1/should_fail","Output":" TestToUpper1/should_fail: parallel_test.go:32: strings.ToUpper\(\\"lower case\\"\) = \\"LOWER CASE\\"; want \\"lower case\\"\\n"}'
stdout '"Action":"output","Package":"parallel","Test":"TestToUpper2/should_fail","Output":" TestToUpper2/should_fail: parallel_test.go:32: strings.ToUpper\(\\"lower case\\"\) = \\"LOWER CASE\\"; want \\"lower case\\"\\n"}'

-- parallel/parallel_test.go --
package parallel

import (
"strings"
"testing"
)

func TestToUpper1(t *testing.T) { testToUpper(t) }
func TestToUpper2(t *testing.T) { testToUpper(t) }

func testToUpper(t *testing.T) {
t.Parallel()

cases := []struct{ name, in, want string }{
{
name: "should_pass",
in: "upper case",
want: "UPPER CASE",
},
{
name: "should_fail",
in: "lower case",
want: "lower case",
},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

if got := strings.ToUpper(tc.in); got != tc.want {
t.Errorf("strings.ToUpper(%q) = %q; want %q", tc.in, got, tc.want)
}
})
}
}