@@ -31,7 +31,7 @@ func TestMain(m *testing.M) {
31
31
Nogo : "@//:nogo" ,
32
32
Main : `
33
33
-- BUILD.bazel --
34
- load("@io_bazel_rules_go//go:def.bzl", "go_library", "nogo")
34
+ load("@io_bazel_rules_go//go:def.bzl", "go_binary", " go_library", "nogo")
35
35
36
36
nogo(
37
37
name = "nogo",
@@ -124,6 +124,12 @@ go_library(
124
124
importpath = "dep",
125
125
)
126
126
127
+ go_binary(
128
+ name = "type_check_fail",
129
+ srcs = ["type_check_fail.go"],
130
+ pure = "on",
131
+ )
132
+
127
133
-- foofuncname.go --
128
134
// foofuncname checks for functions named "Foo".
129
135
// It has the same package name as another check to test the checks with
@@ -434,6 +440,16 @@ func Foo() bool { // This should fail foofuncname
434
440
return Bar()
435
441
}
436
442
443
+ -- type_check_fail.go --
444
+ package type_check_fail
445
+
446
+ import (
447
+ "strings"
448
+ )
449
+
450
+ func Foo() bool {
451
+ return strings.Split("a,b,c", ",") // This fails type-checking
452
+ }
437
453
` ,
438
454
})
439
455
}
@@ -443,6 +459,7 @@ func Test(t *testing.T) {
443
459
desc , config , target string
444
460
wantSuccess bool
445
461
includes , excludes []string
462
+ bazelArgs []string
446
463
}{
447
464
{
448
465
desc : "default_config" ,
@@ -507,6 +524,16 @@ func Test(t *testing.T) {
507
524
// note the cross platform regex :)
508
525
`examplepkg[\\/]pure_src_with_err_calling_native.go:.*function must not be named Foo \(foofuncname\)` ,
509
526
},
527
+ }, {
528
+ desc : "type_check_fail" ,
529
+ config : "config.json" ,
530
+ target : "//:type_check_fail" ,
531
+ wantSuccess : false ,
532
+ includes : []string {
533
+ "4 analyzers skipped due to type-checking error: type_check_fail.go:8:10:" ,
534
+ },
535
+ // Ensure that nogo runs even though compilation fails
536
+ bazelArgs : []string {"--keep_going" },
510
537
}, {
511
538
desc : "no_errors" ,
512
539
target : "//:no_errors" ,
@@ -527,7 +554,7 @@ func Test(t *testing.T) {
527
554
defer replaceInFile ("BUILD.bazel" , customConfig , origConfig )
528
555
}
529
556
530
- cmd := bazel_testing .BazelCmd ("build" , test .target )
557
+ cmd := bazel_testing .BazelCmd (append ([] string { "build" , test .target }, test . bazelArgs ... ) ... )
531
558
stderr := & bytes.Buffer {}
532
559
cmd .Stderr = stderr
533
560
if err := cmd .Run (); err == nil && ! test .wantSuccess {
0 commit comments