|
4 | 4 |
|
5 | 5 | // This file contains tests for the printf checker.
|
6 | 6 |
|
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 |
| - |
12 | 7 | package testdata
|
13 | 8 |
|
14 | 9 | import (
|
15 | 10 | "fmt"
|
16 |
| - . "fmt" |
17 | 11 | logpkg "log" // renamed to make it harder to see
|
18 | 12 | "math"
|
19 | 13 | "os"
|
@@ -103,7 +97,7 @@ func PrintfTests() {
|
103 | 97 | fmt.Printf("%s", stringerarrayv)
|
104 | 98 | fmt.Printf("%v", notstringerarrayv)
|
105 | 99 | fmt.Printf("%T", notstringerarrayv)
|
106 |
| - fmt.Printf("%d", new(Formatter)) |
| 100 | + fmt.Printf("%d", new(fmt.Formatter)) |
107 | 101 | fmt.Printf("%*%", 2) // Ridiculous but allowed.
|
108 | 102 | fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say.
|
109 | 103 |
|
@@ -250,13 +244,13 @@ func PrintfTests() {
|
250 | 244 | t.Logf("%d", 3)
|
251 | 245 | t.Logf("%d", "hi") // ERROR "Logf format %d has arg \x22hi\x22 of wrong type string"
|
252 | 246 |
|
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" |
255 | 249 |
|
256 | 250 | // 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" |
260 | 254 |
|
261 | 255 | // Printf from external package
|
262 | 256 | // externalprintf.Printf("%d", 42) // OK
|
@@ -348,46 +342,32 @@ func (ss *someStruct) log(f func(), args ...interface{}) {}
|
348 | 342 | // A function we use as a function value; it has no other purpose.
|
349 | 343 | func someFunction() {}
|
350 | 344 |
|
351 |
| -/* |
352 | 345 | // Printf is used by the test so we must declare it.
|
353 | 346 | func Printf(format string, args ...interface{}) {
|
354 |
| - panic("don't call - testing only") |
| 347 | + fmt.Printf(format, args...) |
355 | 348 | }
|
356 | 349 |
|
357 | 350 | // Println is used by the test so we must declare it.
|
358 | 351 | 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...) |
365 | 353 | }
|
366 | 354 |
|
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 |
| - |
373 | 355 | // printf is used by the test so we must declare it.
|
374 | 356 | func printf(format string, args ...interface{}) {
|
375 |
| - panic("don't call - testing only") |
| 357 | + fmt.Printf(format, args...) |
376 | 358 | }
|
377 | 359 |
|
378 |
| -/* |
379 | 360 | // Errorf is used by the test for a case in which the first parameter
|
380 | 361 | // is not a format string.
|
381 | 362 | func Errorf(i int, format string, args ...interface{}) {
|
382 |
| - panic("don't call - testing only") |
| 363 | + _ = fmt.Errorf(format, args...) |
383 | 364 | }
|
384 | 365 |
|
385 | 366 | // errorf is used by the test for a case in which the function accepts multiple
|
386 | 367 | // string parameters before variadic arguments
|
387 | 368 | func errorf(level, format string, args ...interface{}) {
|
388 |
| - panic("don't call - testing only") |
| 369 | + _ = fmt.Errorf(format, args...) |
389 | 370 | }
|
390 |
| -*/ |
391 | 371 |
|
392 | 372 | // multi is used by the test.
|
393 | 373 | func multi() []interface{} {
|
|
0 commit comments