Fix flaky cgo test failures. ()

Fixes flaky cgo test failures caused by duplicate printf
format checks in staticcheck and go vet that use slightly
different reporting formats.
This commit is contained in:
Trevor Pounds 2019-09-20 12:05:01 -04:00 committed by Isaev Denis
parent 1040e34da2
commit a653032409
3 changed files with 15 additions and 1 deletions

@ -59,8 +59,10 @@ func TestCgoOk(t *testing.T) {
} }
func TestCgoWithIssues(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") 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) { func TestUnsafeOk(t *testing.T) {

@ -3,6 +3,7 @@
package testdata package testdata
import ( import (
"fmt"
"io" "io"
"os" "os"
) )
@ -30,3 +31,8 @@ func GovetNolintVet() error {
func GovetNolintVetShadow() error { func GovetNolintVetShadow() error {
return &os.PathError{"first", "path", os.ErrNotExist} //nolint:vetshadow 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"
}

@ -2,6 +2,7 @@
package testdata package testdata
import ( import (
"fmt"
"runtime" "runtime"
) )
@ -23,3 +24,8 @@ func StaticcheckNolintMegacheck() {
func StaticcheckDeprecated() { func StaticcheckDeprecated() {
_ = runtime.CPUProfile() // ERROR "SA1019: runtime.CPUProfile is deprecated" _ = 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"
}