Skip to content

Commit

Permalink
tester: differentiate expected output by golang version (#3087)
Browse files Browse the repository at this point in the history
Fixes #3082.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
  • Loading branch information
srenatus authored Jan 22, 2021
1 parent 727cef9 commit 1d96675
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 51 deletions.
59 changes: 59 additions & 0 deletions tester/fixture_go1.14_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// +build !go1.16

// The outputs here change with Go 1.16, see
// https://github.com/golang/go/commit/afe7c8d0b25f26f0abd749ca52c7e1e7dfdee8cb
// But since we've been using 1.14 by the time these split-off fixtures
// were introduced, the filename mentions go1.14.

package tester

const fixtureReporterVerboseBenchmark = `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
data.foo.bar.test_baz 1000 123 ns/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`

const fixtureReporterVerboseBenchmarkShowAllocations = `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
data.foo.bar.test_baz 1000 123 ns/op 123 timer_rego_query_eval_ns/op 91 B/op 0 allocs/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`

const fixtureReporterVerboseBenchmarkShowAllocationsGoBenchFormat = `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
BenchmarkDataFooBarTestBaz 1000 123 ns/op 123 timer_rego_query_eval_ns/op 91 B/op 0 allocs/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`
57 changes: 57 additions & 0 deletions tester/fixture_go1.16_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// +build go1.16

// See https://golang.org/cmd/go/#hdr-Build_constraints,
// this build constraint will match go 1.16 onwards.

package tester

const fixtureReporterVerboseBenchmark = `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
data.foo.bar.test_baz 1000 123.0 ns/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`

const fixtureReporterVerboseBenchmarkShowAllocations = `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
data.foo.bar.test_baz 1000 123.0 ns/op 123.0 timer_rego_query_eval_ns/op 91 B/op 0 allocs/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`

const fixtureReporterVerboseBenchmarkShowAllocationsGoBenchFormat = `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
BenchmarkDataFooBarTestBaz 1000 123.0 ns/op 123.0 timer_rego_query_eval_ns/op 91 B/op 0 allocs/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`
54 changes: 3 additions & 51 deletions tester/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,23 +359,7 @@ func TestPrettyReporterVerboseBenchmark(t *testing.T) {
t.Fatal(err)
}

exp := `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
data.foo.bar.test_baz 1000 123 ns/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`

exp := fixtureReporterVerboseBenchmark
if exp != buf.String() {
t.Fatalf("Expected:\n\n%v\n\nGot:\n\n%v", exp, buf.String())
}
Expand Down Expand Up @@ -436,23 +420,7 @@ func TestPrettyReporterVerboseBenchmarkShowAllocations(t *testing.T) {
t.Fatal(err)
}

exp := `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
data.foo.bar.test_baz 1000 123 ns/op 123 timer_rego_query_eval_ns/op 91 B/op 0 allocs/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`

exp := fixtureReporterVerboseBenchmarkShowAllocations
if exp != buf.String() {
t.Fatalf("Expected:\n\n%v\n\nGot:\n\n%v", exp, buf.String())
}
Expand Down Expand Up @@ -514,23 +482,7 @@ func TestPrettyReporterVerboseBenchmarkShowAllocationsGoBenchFormat(t *testing.T
t.Fatal(err)
}

exp := `FAILURES
--------------------------------------------------------------------------------
data.foo.bar.test_corge: FAIL (0s)
SUMMARY
--------------------------------------------------------------------------------
BenchmarkDataFooBarTestBaz 1000 123 ns/op 123 timer_rego_query_eval_ns/op 91 B/op 0 allocs/op
data.foo.bar.test_qux: ERROR (0s)
some err
data.foo.bar.test_corge: FAIL (0s)
--------------------------------------------------------------------------------
PASS: 1/3
FAIL: 1/3
ERROR: 1/3
`

exp := fixtureReporterVerboseBenchmarkShowAllocationsGoBenchFormat
if exp != buf.String() {
t.Fatalf("Expected:\n\n%v\n\nGot:\n\n%v", exp, buf.String())
}
Expand Down

0 comments on commit 1d96675

Please sign in to comment.