Skip to content

Commit a653032

Browse files
tpoundsjirfag
authored andcommitted
Fix flaky cgo test failures. (#716)
Fixes flaky cgo test failures caused by duplicate printf format checks in staticcheck and go vet that use slightly different reporting formats.
1 parent 1040e34 commit a653032

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

test/run_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ func TestCgoOk(t *testing.T) {
5959
}
6060

6161
func TestCgoWithIssues(t *testing.T) {
62-
testshared.NewLintRunner(t).Run("--no-config", "--enable-all", getTestDataDir("cgo_with_issues")).
62+
testshared.NewLintRunner(t).Run("--no-config", "--disable-all", "-Egovet", getTestDataDir("cgo_with_issues")).
6363
ExpectHasIssue("Printf format %t has arg cs of wrong type")
64+
testshared.NewLintRunner(t).Run("--no-config", "--disable-all", "-Estaticcheck", getTestDataDir("cgo_with_issues")).
65+
ExpectHasIssue("SA5009: Printf format %t has arg #1 of wrong type")
6466
}
6567

6668
func TestUnsafeOk(t *testing.T) {

test/testdata/govet.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package testdata
44

55
import (
6+
"fmt"
67
"io"
78
"os"
89
)
@@ -30,3 +31,8 @@ func GovetNolintVet() error {
3031
func GovetNolintVetShadow() error {
3132
return &os.PathError{"first", "path", os.ErrNotExist} //nolint:vetshadow
3233
}
34+
35+
func GovetPrintf() {
36+
x := "dummy"
37+
fmt.Printf("%d", x) // ERROR "printf: Printf format %d has arg x of wrong type string"
38+
}

test/testdata/staticcheck.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package testdata
33

44
import (
5+
"fmt"
56
"runtime"
67
)
78

@@ -23,3 +24,8 @@ func StaticcheckNolintMegacheck() {
2324
func StaticcheckDeprecated() {
2425
_ = runtime.CPUProfile() // ERROR "SA1019: runtime.CPUProfile is deprecated"
2526
}
27+
28+
func StaticcheckPrintf() {
29+
x := "dummy"
30+
fmt.Printf("%d", x) // ERROR "SA5009: Printf format %d has arg #1 of wrong type"
31+
}

0 commit comments

Comments
 (0)