| 1 |
This test checks for the correct suppression (or activation) of the |
| 2 |
non-constant format string check (golang/go#60529), in a go1.23 module. |
| 3 |
|
| 4 |
See golang/go#71485 for details. |
| 5 |
|
| 6 |
-- go.mod -- |
| 7 |
module example.com/nonconst |
| 8 |
|
| 9 |
go 1.23 |
| 10 |
|
| 11 |
-- nonconst.go -- |
| 12 |
package nonconst |
| 13 |
|
| 14 |
import ( |
| 15 |
"fmt" |
| 16 |
"log" |
| 17 |
"os" |
| 18 |
) |
| 19 |
|
| 20 |
func _(s string) { |
| 21 |
fmt.Printf(s) |
| 22 |
fmt.Printf(s, "arg") |
| 23 |
fmt.Fprintf(os.Stderr, s) |
| 24 |
log.Printf(s) |
| 25 |
} |
| 26 |
|
| 27 |
-- nonconst_go124.go -- |
| 28 |
//go:build go1.24 |
| 29 |
package nonconst |
| 30 |
|
| 31 |
import ( |
| 32 |
"fmt" |
| 33 |
"log" |
| 34 |
"os" |
| 35 |
) |
| 36 |
|
| 37 |
// With Go 1.24, the analyzer should be activated, as this is a go1.24 file. |
| 38 |
func _(s string) { |
| 39 |
fmt.Printf(s) // want `non-constant format string in call to fmt.Printf` |
| 40 |
fmt.Printf(s, "arg") |
| 41 |
fmt.Fprintf(os.Stderr, s) // want `non-constant format string in call to fmt.Fprintf` |
| 42 |
log.Printf(s) // want `non-constant format string in call to log.Printf` |
| 43 |
} |
| 44 |
|
| 45 |
-- nonconst_go124.go.golden -- |
| 46 |
//go:build go1.24 |
| 47 |
package nonconst |
| 48 |
|
| 49 |
import ( |
| 50 |
"fmt" |
| 51 |
"log" |
| 52 |
"os" |
| 53 |
) |
| 54 |
|
| 55 |
// With Go 1.24, the analyzer should be activated, as this is a go1.24 file. |
| 56 |
func _(s string) { |
| 57 |
fmt.Printf("%s", s) // want `non-constant format string in call to fmt.Printf` |
| 58 |
fmt.Printf(s, "arg") |
| 59 |
fmt.Fprintf(os.Stderr, "%s", s) // want `non-constant format string in call to fmt.Fprintf` |
| 60 |
log.Printf("%s", s) // want `non-constant format string in call to log.Printf` |
| 61 |
} |