From a653032409d310c859ad45ba35932763270afcc1 Mon Sep 17 00:00:00 2001 From: Trevor Pounds Date: Fri, 20 Sep 2019 12:05:01 -0400 Subject: [PATCH] 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. --- test/run_test.go | 4 +++- test/testdata/govet.go | 6 ++++++ test/testdata/staticcheck.go | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/run_test.go b/test/run_test.go index 3904cec9..cbc8bdb3 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -59,8 +59,10 @@ func TestCgoOk(t *testing.T) { } func TestCgoWithIssues(t *testing.T) { - testshared.NewLintRunner(t).Run("--no-config", "--enable-all", getTestDataDir("cgo_with_issues")). + testshared.NewLintRunner(t).Run("--no-config", "--disable-all", "-Egovet", getTestDataDir("cgo_with_issues")). ExpectHasIssue("Printf format %t has arg cs of wrong type") + testshared.NewLintRunner(t).Run("--no-config", "--disable-all", "-Estaticcheck", getTestDataDir("cgo_with_issues")). + ExpectHasIssue("SA5009: Printf format %t has arg #1 of wrong type") } func TestUnsafeOk(t *testing.T) { diff --git a/test/testdata/govet.go b/test/testdata/govet.go index ed9d9bed..c928699c 100644 --- a/test/testdata/govet.go +++ b/test/testdata/govet.go @@ -3,6 +3,7 @@ package testdata import ( + "fmt" "io" "os" ) @@ -30,3 +31,8 @@ func GovetNolintVet() error { func GovetNolintVetShadow() error { return &os.PathError{"first", "path", os.ErrNotExist} //nolint:vetshadow } + +func GovetPrintf() { + x := "dummy" + fmt.Printf("%d", x) // ERROR "printf: Printf format %d has arg x of wrong type string" +} diff --git a/test/testdata/staticcheck.go b/test/testdata/staticcheck.go index 6297b8a2..f6b78b57 100644 --- a/test/testdata/staticcheck.go +++ b/test/testdata/staticcheck.go @@ -2,6 +2,7 @@ package testdata import ( + "fmt" "runtime" ) @@ -23,3 +24,8 @@ func StaticcheckNolintMegacheck() { func StaticcheckDeprecated() { _ = runtime.CPUProfile() // ERROR "SA1019: runtime.CPUProfile is deprecated" } + +func StaticcheckPrintf() { + x := "dummy" + fmt.Printf("%d", x) // ERROR "SA5009: Printf format %d has arg #1 of wrong type" +}