Skip to content

Commit e8e074d

Browse files
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 7e64377 commit e8e074d

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

src/cmd/vet/testdata/print.go

+11-31
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44

55
// This file contains tests for the printf checker.
66

7-
// TODO(rsc): The user-defined wrapper tests are commented out
8-
// because they produced too many false positives when vet was
9-
// enabled during go test. See the TODO in ../print.go for a plan
10-
// to fix that; when it's fixed, uncomment the user-defined wrapper tests.
11-
127
package testdata
138

149
import (
1510
"fmt"
16-
. "fmt"
1711
logpkg "log" // renamed to make it harder to see
1812
"math"
1913
"os"
@@ -103,7 +97,7 @@ func PrintfTests() {
10397
fmt.Printf("%s", stringerarrayv)
10498
fmt.Printf("%v", notstringerarrayv)
10599
fmt.Printf("%T", notstringerarrayv)
106-
fmt.Printf("%d", new(Formatter))
100+
fmt.Printf("%d", new(fmt.Formatter))
107101
fmt.Printf("%*%", 2) // Ridiculous but allowed.
108102
fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say.
109103

@@ -250,13 +244,13 @@ func PrintfTests() {
250244
t.Logf("%d", 3)
251245
t.Logf("%d", "hi") // ERROR "Logf format %d has arg \x22hi\x22 of wrong type string"
252246

253-
// Errorf(1, "%d", 3) // OK
254-
// Errorf(1, "%d", "hi") // no error "Errorf format %d has arg \x22hi\x22 of wrong type string"
247+
Errorf(1, "%d", 3) // OK
248+
Errorf(1, "%d", "hi") // ERROR "Errorf format %d has arg \x22hi\x22 of wrong type string"
255249

256250
// Multiple string arguments before variadic args
257-
// errorf("WARNING", "foobar") // OK
258-
// errorf("INFO", "s=%s, n=%d", "foo", 1) // OK
259-
// errorf("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has 0 args"
251+
errorf("WARNING", "foobar") // OK
252+
errorf("INFO", "s=%s, n=%d", "foo", 1) // OK
253+
errorf("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has 0 args"
260254

261255
// Printf from external package
262256
// externalprintf.Printf("%d", 42) // OK
@@ -348,46 +342,32 @@ func (ss *someStruct) log(f func(), args ...interface{}) {}
348342
// A function we use as a function value; it has no other purpose.
349343
func someFunction() {}
350344

351-
/*
352345
// Printf is used by the test so we must declare it.
353346
func Printf(format string, args ...interface{}) {
354-
panic("don't call - testing only")
347+
fmt.Printf(format, args...)
355348
}
356349

357350
// Println is used by the test so we must declare it.
358351
func Println(args ...interface{}) {
359-
panic("don't call - testing only")
360-
}
361-
362-
// Logf is used by the test so we must declare it.
363-
func Logf(format string, args ...interface{}) {
364-
panic("don't call - testing only")
352+
fmt.Println(args...)
365353
}
366354

367-
// Log is used by the test so we must declare it.
368-
func Log(args ...interface{}) {
369-
panic("don't call - testing only")
370-
}
371-
*/
372-
373355
// printf is used by the test so we must declare it.
374356
func printf(format string, args ...interface{}) {
375-
panic("don't call - testing only")
357+
fmt.Printf(format, args...)
376358
}
377359

378-
/*
379360
// Errorf is used by the test for a case in which the first parameter
380361
// is not a format string.
381362
func Errorf(i int, format string, args ...interface{}) {
382-
panic("don't call - testing only")
363+
_ = fmt.Errorf(format, args...)
383364
}
384365

385366
// errorf is used by the test for a case in which the function accepts multiple
386367
// string parameters before variadic arguments
387368
func errorf(level, format string, args ...interface{}) {
388-
panic("don't call - testing only")
369+
_ = fmt.Errorf(format, args...)
389370
}
390-
*/
391371

392372
// multi is used by the test.
393373
func multi() []interface{} {

src/cmd/vet/vet_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ func TestVet(t *testing.T) {
9595
}
9696
batch := make([][]string, wide)
9797
for i, file := range gos {
98-
// TODO: Remove print.go exception once we require type checking for everything,
99-
// and then delete TestVetPrint.
98+
// The print.go test is run by TestVetPrint.
10099
if strings.HasSuffix(file, "print.go") {
101100
continue
102101
}

0 commit comments

Comments
 (0)