1
2
3
4
5 package godebug_test
6
7 import (
8 "bytes"
9 "internal/testenv"
10 "os"
11 "path/filepath"
12 "testing"
13 )
14
15
16 func TestLinkerGC(t *testing.T) {
17 if testing.Short() {
18 t.Skip("skipping in short mode")
19 }
20 testenv.MustHaveGoBuild(t)
21 t.Parallel()
22
23 dir := t.TempDir()
24 src := filepath.Join(dir, "main.go")
25 program := []byte(`package main
26
27 import _ "net"
28
29 func main() {}
30 `)
31 if err := os.WriteFile(src, program, 0644); err != nil {
32 t.Fatal(err)
33 }
34
35 exe := filepath.Join(dir, "main.exe")
36 cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src)
37 if out, err := cmd.CombinedOutput(); err != nil {
38 t.Fatalf("build: %v\n%s", err, out)
39 }
40
41 cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "nm", exe)
42 nm, err := cmd.CombinedOutput()
43 if err != nil {
44 t.Fatalf("nm: %v\n%s", err, nm)
45 }
46 if want := []byte("internal/godebug.(*Setting).Value"); !bytes.Contains(nm, want) {
47 t.Fatalf("expected symbol %q not found", want)
48 }
49 if bad := []byte("runtime.initMetrics"); bytes.Contains(nm, bad) {
50 t.Fatalf("unexpected symbol %q found", bad)
51 }
52 }
53
View as plain text