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