| 1 |
# This test verifies that issue 56293 has been fixed, and that the |
| 2 |
# insertion of coverage instrumentation doesn't perturb package |
| 3 |
# initialization order. |
| 4 |
|
| 5 |
[short] skip |
| 6 |
|
| 7 |
go test -cover example |
| 8 |
|
| 9 |
-- go.mod -- |
| 10 |
module example |
| 11 |
|
| 12 |
go 1.20 |
| 13 |
|
| 14 |
-- m.go -- |
| 15 |
|
| 16 |
package main |
| 17 |
|
| 18 |
import ( |
| 19 |
"flag" |
| 20 |
) |
| 21 |
|
| 22 |
var ( |
| 23 |
fooFlag = flag.String("foo", "", "this should be ok") |
| 24 |
foo = flag.Lookup("foo") |
| 25 |
|
| 26 |
barFlag = flag.String("bar", "", "this should be also ok, but is "+notOK()+".") |
| 27 |
bar = flag.Lookup("bar") |
| 28 |
) |
| 29 |
|
| 30 |
func notOK() string { |
| 31 |
return "not OK" |
| 32 |
} |
| 33 |
|
| 34 |
-- m_test.go -- |
| 35 |
|
| 36 |
package main |
| 37 |
|
| 38 |
import ( |
| 39 |
"testing" |
| 40 |
) |
| 41 |
|
| 42 |
func TestFoo(t *testing.T) { |
| 43 |
if foo == nil { |
| 44 |
t.Fatal() |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
func TestBar(t *testing.T) { |
| 49 |
if bar == nil { |
| 50 |
t.Fatal() |
| 51 |
} |
| 52 |
} |