From e8e074d1ba286c3e06847a96fe6aa90e294dfcd9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 19 Jul 2018 14:03:09 -0700 Subject: [PATCH] cmd/vet: implement old TODO from testdata/print.go MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The code was fixed in CL 108559 but the testing TODO was not implemented. Updates #22936 Change-Id: I20a703260a181bbcf5f87609d6fb8221a182be1a Reviewed-on: https://go-review.googlesource.com/125038 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike Reviewed-by: Daniel Martí --- src/cmd/vet/testdata/print.go | 42 +++++++++-------------------------- src/cmd/vet/vet_test.go | 3 +-- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/cmd/vet/testdata/print.go b/src/cmd/vet/testdata/print.go index ecafed5fa2..88163b59d9 100644 --- a/src/cmd/vet/testdata/print.go +++ b/src/cmd/vet/testdata/print.go @@ -4,16 +4,10 @@ // This file contains tests for the printf checker. -// TODO(rsc): The user-defined wrapper tests are commented out -// because they produced too many false positives when vet was -// enabled during go test. See the TODO in ../print.go for a plan -// to fix that; when it's fixed, uncomment the user-defined wrapper tests. - package testdata import ( "fmt" - . "fmt" logpkg "log" // renamed to make it harder to see "math" "os" @@ -103,7 +97,7 @@ func PrintfTests() { fmt.Printf("%s", stringerarrayv) fmt.Printf("%v", notstringerarrayv) fmt.Printf("%T", notstringerarrayv) - fmt.Printf("%d", new(Formatter)) + fmt.Printf("%d", new(fmt.Formatter)) fmt.Printf("%*%", 2) // Ridiculous but allowed. fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say. @@ -250,13 +244,13 @@ func PrintfTests() { t.Logf("%d", 3) t.Logf("%d", "hi") // ERROR "Logf format %d has arg \x22hi\x22 of wrong type string" - // Errorf(1, "%d", 3) // OK - // Errorf(1, "%d", "hi") // no error "Errorf format %d has arg \x22hi\x22 of wrong type string" + Errorf(1, "%d", 3) // OK + Errorf(1, "%d", "hi") // ERROR "Errorf format %d has arg \x22hi\x22 of wrong type string" // Multiple string arguments before variadic args - // errorf("WARNING", "foobar") // OK - // errorf("INFO", "s=%s, n=%d", "foo", 1) // OK - // errorf("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has 0 args" + errorf("WARNING", "foobar") // OK + errorf("INFO", "s=%s, n=%d", "foo", 1) // OK + errorf("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has 0 args" // Printf from external package // externalprintf.Printf("%d", 42) // OK @@ -348,46 +342,32 @@ func (ss *someStruct) log(f func(), args ...interface{}) {} // A function we use as a function value; it has no other purpose. func someFunction() {} -/* // Printf is used by the test so we must declare it. func Printf(format string, args ...interface{}) { - panic("don't call - testing only") + fmt.Printf(format, args...) } // Println is used by the test so we must declare it. func Println(args ...interface{}) { - panic("don't call - testing only") -} - -// Logf is used by the test so we must declare it. -func Logf(format string, args ...interface{}) { - panic("don't call - testing only") + fmt.Println(args...) } -// Log is used by the test so we must declare it. -func Log(args ...interface{}) { - panic("don't call - testing only") -} -*/ - // printf is used by the test so we must declare it. func printf(format string, args ...interface{}) { - panic("don't call - testing only") + fmt.Printf(format, args...) } -/* // Errorf is used by the test for a case in which the first parameter // is not a format string. func Errorf(i int, format string, args ...interface{}) { - panic("don't call - testing only") + _ = fmt.Errorf(format, args...) } // errorf is used by the test for a case in which the function accepts multiple // string parameters before variadic arguments func errorf(level, format string, args ...interface{}) { - panic("don't call - testing only") + _ = fmt.Errorf(format, args...) } -*/ // multi is used by the test. func multi() []interface{} { diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go index ecb4ce1295..90665d77bc 100644 --- a/src/cmd/vet/vet_test.go +++ b/src/cmd/vet/vet_test.go @@ -95,8 +95,7 @@ func TestVet(t *testing.T) { } batch := make([][]string, wide) for i, file := range gos { - // TODO: Remove print.go exception once we require type checking for everything, - // and then delete TestVetPrint. + // The print.go test is run by TestVetPrint. if strings.HasSuffix(file, "print.go") { continue } -- 2.50.0