|
1 | 1 | package brief |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strings" |
4 | 5 | "testing" |
5 | 6 | "time" |
6 | 7 | ) |
@@ -53,6 +54,72 @@ func TestParseTestEvents_WithFailure(t *testing.T) { |
53 | 54 | } |
54 | 55 | } |
55 | 56 |
|
| 57 | +func TestParseTestEvents_FailureDetails(t *testing.T) { |
| 58 | + input := `{"Action":"run","Package":"p","Test":"TestFoo"} |
| 59 | +{"Action":"output","Package":"p","Test":"TestFoo","Output":" foo_test.go:42: want true, got false\n"} |
| 60 | +{"Action":"output","Package":"p","Test":"TestFoo","Output":" foo_test.go:43: another error\n"} |
| 61 | +{"Action":"fail","Package":"p","Test":"TestFoo","Elapsed":0.001} |
| 62 | +{"Action":"fail","Package":"p","Elapsed":0.005} |
| 63 | +` |
| 64 | + r := parseTestEvents(input) |
| 65 | + if r == nil { |
| 66 | + t.Fatal("nil result") |
| 67 | + } |
| 68 | + if r.Passed { |
| 69 | + t.Error("want Passed = false") |
| 70 | + } |
| 71 | + if len(r.Details) != 1 { |
| 72 | + t.Fatalf("len(Details) = %d, want 1", len(r.Details)) |
| 73 | + } |
| 74 | + if r.Details[0].Test != "TestFoo" { |
| 75 | + t.Errorf("Details[0].Test = %q, want TestFoo", r.Details[0].Test) |
| 76 | + } |
| 77 | + if len(r.Details[0].Messages) != 2 { |
| 78 | + t.Fatalf("len(Messages) = %d, want 2", len(r.Details[0].Messages)) |
| 79 | + } |
| 80 | + if !strings.Contains(r.Details[0].Messages[0], "want true, got false") { |
| 81 | + t.Errorf("Messages[0] = %q", r.Details[0].Messages[0]) |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +func TestParseTestEvents_FailureDetails_MultipleTests(t *testing.T) { |
| 86 | + input := `{"Action":"run","Package":"p","Test":"TestA"} |
| 87 | +{"Action":"output","Package":"p","Test":"TestA","Output":" a_test.go:1: err A\n"} |
| 88 | +{"Action":"fail","Package":"p","Test":"TestA","Elapsed":0.001} |
| 89 | +{"Action":"run","Package":"p","Test":"TestB"} |
| 90 | +{"Action":"output","Package":"p","Test":"TestB","Output":" b_test.go:2: err B\n"} |
| 91 | +{"Action":"fail","Package":"p","Test":"TestB","Elapsed":0.002} |
| 92 | +{"Action":"run","Package":"p","Test":"TestC"} |
| 93 | +{"Action":"pass","Package":"p","Test":"TestC","Elapsed":0.001} |
| 94 | +{"Action":"fail","Package":"p","Elapsed":0.005} |
| 95 | +` |
| 96 | + r := parseTestEvents(input) |
| 97 | + if r == nil { |
| 98 | + t.Fatal("nil result") |
| 99 | + } |
| 100 | + if len(r.Details) != 2 { |
| 101 | + t.Fatalf("len(Details) = %d, want 2", len(r.Details)) |
| 102 | + } |
| 103 | + if r.Details[0].Test != "TestA" || r.Details[1].Test != "TestB" { |
| 104 | + t.Errorf("Details tests = %q, %q", r.Details[0].Test, r.Details[1].Test) |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +func TestParseTestEvents_PassedTestsHaveNoDetails(t *testing.T) { |
| 109 | + input := `{"Action":"run","Package":"p","Test":"TestFoo"} |
| 110 | +{"Action":"output","Package":"p","Test":"TestFoo","Output":"=== RUN TestFoo\n"} |
| 111 | +{"Action":"pass","Package":"p","Test":"TestFoo","Elapsed":0.001} |
| 112 | +{"Action":"pass","Package":"p","Elapsed":0.005} |
| 113 | +` |
| 114 | + r := parseTestEvents(input) |
| 115 | + if r == nil { |
| 116 | + t.Fatal("nil result") |
| 117 | + } |
| 118 | + if len(r.Details) != 0 { |
| 119 | + t.Errorf("expected no Details for passing tests, got %v", r.Details) |
| 120 | + } |
| 121 | +} |
| 122 | + |
56 | 123 | func TestParseTestEvents_Empty(t *testing.T) { |
57 | 124 | if r := parseTestEvents(""); r != nil { |
58 | 125 | t.Errorf("want nil for empty input, got %+v", r) |
|
0 commit comments