Debian Codegraph @

go/analysis/passes/printf/testdata/nonconst_go124.txtar

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