| 1 |
go test -json |
| 2 |
|
| 3 |
stdout '"Action":"output","Package":"p","Output":"M1"}' |
| 4 |
stdout '"Action":"output","Package":"p","Test":"Test","Output":"=== RUN Test\\n"}' |
| 5 |
stdout '"Action":"output","Package":"p","Test":"Test","Output":"T1"}' |
| 6 |
stdout '"Action":"output","Package":"p","Test":"Test/Sub1","Output":"=== RUN Test/Sub1\\n"}' |
| 7 |
stdout '"Action":"output","Package":"p","Test":"Test/Sub1","Output":"Sub1 x_test.go:19: SubLog1\\n"}' |
| 8 |
stdout '"Action":"output","Package":"p","Test":"Test/Sub1","Output":"Sub2"}' |
| 9 |
stdout '"Action":"output","Package":"p","Test":"Test/Sub1","Output":"--- PASS: Test/Sub1 \([\d.]+s\)\\n"}' |
| 10 |
stdout '"Action":"pass","Package":"p","Test":"Test/Sub1","Elapsed"' |
| 11 |
stdout '"Action":"output","Package":"p","Test":"Test/Sub3","Output":"foo bar"}' |
| 12 |
stdout '"Action":"output","Package":"p","Test":"Test/Sub3","Output":"baz\\n"}' |
| 13 |
stdout '"Action":"output","Package":"p","Test":"Test","Output":"T2"}' |
| 14 |
stdout '"Action":"output","Package":"p","Test":"Test","Output":"--- PASS: Test \([\d.]+s\)\\n"}' |
| 15 |
stdout '"Action":"pass","Package":"p","Test":"Test","Elapsed"' |
| 16 |
stdout '"Action":"output","Package":"p","Output":"M2ok \\tp\\t[\d.]+s\\n"}' |
| 17 |
stdout '"Action":"pass","Package":"p","Elapsed"' |
| 18 |
|
| 19 |
-- go.mod -- |
| 20 |
module p |
| 21 |
|
| 22 |
-- x_test.go -- |
| 23 |
package p |
| 24 |
|
| 25 |
import ( |
| 26 |
"os" |
| 27 |
"testing" |
| 28 |
) |
| 29 |
|
| 30 |
func TestMain(m *testing.M) { |
| 31 |
print("M1") |
| 32 |
code := m.Run() |
| 33 |
print("M2") |
| 34 |
os.Exit(code) |
| 35 |
} |
| 36 |
|
| 37 |
func Test(t *testing.T) { |
| 38 |
print("T1") |
| 39 |
t.Run("Sub1", func(t *testing.T) { |
| 40 |
print("Sub1") |
| 41 |
t.Log("SubLog1") |
| 42 |
print("Sub2") |
| 43 |
}) |
| 44 |
t.Run("Sub3", func(t *testing.T) { |
| 45 |
print("\x16foo bar\x16baz\n") |
| 46 |
}) |
| 47 |
print("T2") |
| 48 |
} |