]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: implement old TODO from testdata/print.go
authorIan Lance Taylor <iant@golang.org>
Thu, 19 Jul 2018 21:03:09 +0000 (14:03 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 21 Aug 2018 03:39:47 +0000 (03:39 +0000)
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/cmd/vet/testdata/print.go
src/cmd/vet/vet_test.go

index ecafed5fa2f2cc05621668c5ee7caa5b5931204c..88163b59d949bbbf406f3ef1e487cc641228bdd2 100644 (file)
@@ -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{} {
index ecb4ce129566e54cef5c3c503554e1f4e17ae98a..90665d77bc655e17536deea88e8dd3e43c2fd5de 100644 (file)
@@ -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
                }