Commit e8e074d1 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/vet: implement old TODO from testdata/print.go

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: default avatarRob Pike <r@golang.org>
Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
parent 7e643779
...@@ -4,16 +4,10 @@ ...@@ -4,16 +4,10 @@
// This file contains tests for the printf checker. // 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 package testdata
import ( import (
"fmt" "fmt"
. "fmt"
logpkg "log" // renamed to make it harder to see logpkg "log" // renamed to make it harder to see
"math" "math"
"os" "os"
...@@ -103,7 +97,7 @@ func PrintfTests() { ...@@ -103,7 +97,7 @@ func PrintfTests() {
fmt.Printf("%s", stringerarrayv) fmt.Printf("%s", stringerarrayv)
fmt.Printf("%v", notstringerarrayv) fmt.Printf("%v", notstringerarrayv)
fmt.Printf("%T", notstringerarrayv) fmt.Printf("%T", notstringerarrayv)
fmt.Printf("%d", new(Formatter)) fmt.Printf("%d", new(fmt.Formatter))
fmt.Printf("%*%", 2) // Ridiculous but allowed. fmt.Printf("%*%", 2) // Ridiculous but allowed.
fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say. fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say.
...@@ -250,13 +244,13 @@ func PrintfTests() { ...@@ -250,13 +244,13 @@ func PrintfTests() {
t.Logf("%d", 3) t.Logf("%d", 3)
t.Logf("%d", "hi") // ERROR "Logf format %d has arg \x22hi\x22 of wrong type string" t.Logf("%d", "hi") // ERROR "Logf format %d has arg \x22hi\x22 of wrong type string"
// Errorf(1, "%d", 3) // OK 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", "hi") // ERROR "Errorf format %d has arg \x22hi\x22 of wrong type string"
// Multiple string arguments before variadic args // Multiple string arguments before variadic args
// errorf("WARNING", "foobar") // OK errorf("WARNING", "foobar") // OK
// errorf("INFO", "s=%s, n=%d", "foo", 1) // 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("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has 0 args"
// Printf from external package // Printf from external package
// externalprintf.Printf("%d", 42) // OK // externalprintf.Printf("%d", 42) // OK
...@@ -348,46 +342,32 @@ func (ss *someStruct) log(f func(), args ...interface{}) {} ...@@ -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. // A function we use as a function value; it has no other purpose.
func someFunction() {} func someFunction() {}
/*
// Printf is used by the test so we must declare it. // Printf is used by the test so we must declare it.
func Printf(format string, args ...interface{}) { 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. // Println is used by the test so we must declare it.
func Println(args ...interface{}) { func Println(args ...interface{}) {
panic("don't call - testing only") fmt.Println(args...)
}
// Logf is used by the test so we must declare it.
func Logf(format string, args ...interface{}) {
panic("don't call - testing only")
} }
// 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. // printf is used by the test so we must declare it.
func printf(format string, args ...interface{}) { 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 // Errorf is used by the test for a case in which the first parameter
// is not a format string. // is not a format string.
func Errorf(i int, format string, args ...interface{}) { 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 // errorf is used by the test for a case in which the function accepts multiple
// string parameters before variadic arguments // string parameters before variadic arguments
func errorf(level, format string, args ...interface{}) { func errorf(level, format string, args ...interface{}) {
panic("don't call - testing only") _ = fmt.Errorf(format, args...)
} }
*/
// multi is used by the test. // multi is used by the test.
func multi() []interface{} { func multi() []interface{} {
......
...@@ -95,8 +95,7 @@ func TestVet(t *testing.T) { ...@@ -95,8 +95,7 @@ func TestVet(t *testing.T) {
} }
batch := make([][]string, wide) batch := make([][]string, wide)
for i, file := range gos { for i, file := range gos {
// TODO: Remove print.go exception once we require type checking for everything, // The print.go test is run by TestVetPrint.
// and then delete TestVetPrint.
if strings.HasSuffix(file, "print.go") { if strings.HasSuffix(file, "print.go") {
continue continue
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment