| 1 |
[short] skip |
| 2 |
|
| 3 |
# Test file |
| 4 |
! go test p1_test.go |
| 5 |
stderr 'Logf format %d' |
| 6 |
go test -vet=off |
| 7 |
stdout '^ok' |
| 8 |
|
| 9 |
# Non-test file |
| 10 |
! go test p1.go |
| 11 |
stderr 'Printf format %d' |
| 12 |
go test -x -vet=shift p1.go |
| 13 |
stderr '[\\/]vet.*-shift' |
| 14 |
stdout '\[no test files\]' |
| 15 |
go test -vet=off p1.go |
| 16 |
! stderr '[\\/]vet.*-shift' |
| 17 |
stdout '\[no test files\]' |
| 18 |
|
| 19 |
# ensure all runs non-default vet |
| 20 |
! go test -vet=all ./vetall/... |
| 21 |
stderr 'using resp before checking for errors' |
| 22 |
|
| 23 |
# Test issue #47309 |
| 24 |
! go test -vet=bools,xyz ./vetall/... |
| 25 |
stderr '-vet argument must be a supported analyzer' |
| 26 |
|
| 27 |
# Test with a single analyzer |
| 28 |
! go test -vet=httpresponse ./vetall/... |
| 29 |
stderr 'using resp before checking for errors' |
| 30 |
|
| 31 |
# Test with a list of analyzers |
| 32 |
go test -vet=atomic,bools,nilfunc ./vetall/... |
| 33 |
stdout 'm/vetall.*\[no tests to run\]' |
| 34 |
|
| 35 |
# Test issue #22890 |
| 36 |
go test m/vetcycle |
| 37 |
stdout 'm/vetcycle.*\[no test files\]' |
| 38 |
|
| 39 |
# Test with ... |
| 40 |
! go test ./vetfail/... |
| 41 |
stderr 'Printf format %d' |
| 42 |
stdout 'ok\s+m/vetfail/p2' |
| 43 |
|
| 44 |
# Check there's no diagnosis of a bad build constraint in vetxonly mode. |
| 45 |
# Use -a so that we need to recompute the vet-specific export data for |
| 46 |
# vetfail/p1. |
| 47 |
go test -a m/vetfail/p2 |
| 48 |
! stderr 'invalid.*constraint' |
| 49 |
|
| 50 |
-- go.mod -- |
| 51 |
module m |
| 52 |
|
| 53 |
go 1.16 |
| 54 |
-- p1_test.go -- |
| 55 |
package p |
| 56 |
|
| 57 |
import "testing" |
| 58 |
|
| 59 |
func Test(t *testing.T) { |
| 60 |
t.Logf("%d") // oops |
| 61 |
} |
| 62 |
-- p1.go -- |
| 63 |
package p |
| 64 |
|
| 65 |
import "fmt" |
| 66 |
|
| 67 |
func F() { |
| 68 |
fmt.Printf("%d") // oops |
| 69 |
} |
| 70 |
-- vetall/p.go -- |
| 71 |
package p |
| 72 |
|
| 73 |
import "net/http" |
| 74 |
|
| 75 |
func F() { |
| 76 |
resp, err := http.Head("example.com") |
| 77 |
defer resp.Body.Close() |
| 78 |
if err != nil { |
| 79 |
panic(err) |
| 80 |
} |
| 81 |
// (defer statement belongs here) |
| 82 |
} |
| 83 |
-- vetall/p_test.go -- |
| 84 |
package p |
| 85 |
-- vetcycle/p.go -- |
| 86 |
package p |
| 87 |
|
| 88 |
type ( |
| 89 |
_ interface{ m(B1) } |
| 90 |
A1 interface{ a(D1) } |
| 91 |
B1 interface{ A1 } |
| 92 |
C1 interface { |
| 93 |
B1 /* ERROR issue #18395 */ |
| 94 |
} |
| 95 |
D1 interface{ C1 } |
| 96 |
) |
| 97 |
|
| 98 |
var _ A1 = C1 /* ERROR cannot use C1 */ (nil) |
| 99 |
-- vetfail/p1/p1.go -- |
| 100 |
// +build !foo-bar |
| 101 |
|
| 102 |
package p1 |
| 103 |
|
| 104 |
import "fmt" |
| 105 |
|
| 106 |
func F() { |
| 107 |
fmt.Printf("%d", "hello") // causes vet error |
| 108 |
} |
| 109 |
-- vetfail/p2/p2.go -- |
| 110 |
package p2 |
| 111 |
|
| 112 |
import _ "m/vetfail/p1" |
| 113 |
|
| 114 |
func F() { |
| 115 |
} |
| 116 |
-- vetfail/p2/p2_test.go -- |
| 117 |
package p2 |
| 118 |
|
| 119 |
import "testing" |
| 120 |
|
| 121 |
func TestF(t *testing.T) { |
| 122 |
F() |
| 123 |
} |