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 @@
// 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{} {
......
......@@ -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
}
......
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