|
15 | 15 | package importpath_test
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "strings" |
18 | 19 | "testing"
|
19 | 20 |
|
20 | 21 | "github.com/bazelbuild/rules_go/go/tools/bazel_testing"
|
@@ -45,6 +46,18 @@ go_test(
|
45 | 46 | srcs = ["super_simple_test.go"],
|
46 | 47 | )
|
47 | 48 |
|
| 49 | +go_test( |
| 50 | + name = "diagnostic_external_test", |
| 51 | + size = "small", |
| 52 | + srcs = ["diagnostic_external_test.go"], |
| 53 | +) |
| 54 | +
|
| 55 | +go_test( |
| 56 | + name = "diagnostic_internal_test", |
| 57 | + size = "small", |
| 58 | + srcs = ["diagnostic_internal_test.go"], |
| 59 | +) |
| 60 | +
|
48 | 61 | nogo(
|
49 | 62 | name = "nogo",
|
50 | 63 | vet = True,
|
@@ -75,21 +88,63 @@ import (
|
75 | 88 |
|
76 | 89 | func TestFoo(t *testing.T) {
|
77 | 90 | }
|
| 91 | +-- diagnostic_external_test.go -- |
| 92 | +package diagnostic_test |
| 93 | +
|
| 94 | +import ( |
| 95 | + "testing" |
| 96 | +) |
| 97 | +
|
| 98 | +func TestFoo(t *testing.T) { |
| 99 | + if TestFoo == nil { |
| 100 | + t.Fatal("TestFoo is nil") |
| 101 | + } |
| 102 | +} |
| 103 | +-- diagnostic_internal_test.go -- |
| 104 | +package diagnostic |
| 105 | +
|
| 106 | +import ( |
| 107 | + "testing" |
| 108 | +) |
| 109 | +
|
| 110 | +func TestFoo(t *testing.T) { |
| 111 | + if TestFoo == nil { |
| 112 | + t.Fatal("TestFoo is nil") |
| 113 | + } |
| 114 | +} |
78 | 115 | `,
|
79 | 116 | Nogo: `@//:nogo`,
|
80 | 117 | })
|
81 | 118 | }
|
82 | 119 |
|
83 | 120 | func TestExternalTestWithFullImportpath(t *testing.T) {
|
84 |
| - if out, err := bazel_testing.BazelOutput("test", "//:all"); err != nil { |
| 121 | + if out, err := bazel_testing.BazelOutput("test", "//:simple_test"); err != nil { |
85 | 122 | println(string(out))
|
86 | 123 | t.Fatal(err)
|
87 | 124 | }
|
88 | 125 | }
|
89 | 126 |
|
90 | 127 | func TestEmptyExternalTest(t *testing.T) {
|
91 |
| - if out, err := bazel_testing.BazelOutput("test", "//:all"); err != nil { |
| 128 | + if out, err := bazel_testing.BazelOutput("test", "//:super_simple_test"); err != nil { |
92 | 129 | println(string(out))
|
93 | 130 | t.Fatal(err)
|
94 | 131 | }
|
95 | 132 | }
|
| 133 | + |
| 134 | +func TestDiagnosticInExternalTest(t *testing.T) { |
| 135 | + if _, err := bazel_testing.BazelOutput("test", "//:diagnostic_external_test"); err == nil { |
| 136 | + t.Fatal("unexpected success") |
| 137 | + } else if !strings.Contains(err.Error(), "diagnostic_external_test.go:8:8: comparison of function TestFoo == nil is always false (nilfunc)") { |
| 138 | + println(err.Error()) |
| 139 | + t.Fatal("unexpected output") |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +func TestDiagnosticInInternalTest(t *testing.T) { |
| 144 | + if _, err := bazel_testing.BazelOutput("test", "//:diagnostic_internal_test"); err == nil { |
| 145 | + t.Fatal("unexpected success") |
| 146 | + } else if !strings.Contains(err.Error(), "diagnostic_internal_test.go:8:8: comparison of function TestFoo == nil is always false (nilfunc)") { |
| 147 | + println(err.Error()) |
| 148 | + t.Fatal("unexpected output") |
| 149 | + } |
| 150 | +} |
0 commit comments