1
2
3
4
5 package test
6
7 import (
8 "internal/testenv"
9 "os"
10 "path/filepath"
11 "testing"
12 )
13
14 const helloSrc = `
15 package main
16 import "fmt"
17 func main() { fmt.Println("hello") }
18 `
19
20 func TestClobberDead(t *testing.T) {
21
22 runHello(t, "-clobberdead")
23 }
24
25 func TestClobberDeadReg(t *testing.T) {
26
27 runHello(t, "-clobberdeadreg")
28 }
29
30 func runHello(t *testing.T, flag string) {
31 if testing.Short() {
32
33
34 t.Skip("skip in short mode")
35 }
36 testenv.MustHaveGoRun(t)
37 t.Parallel()
38
39 tmpdir := t.TempDir()
40 src := filepath.Join(tmpdir, "x.go")
41 err := os.WriteFile(src, []byte(helloSrc), 0644)
42 if err != nil {
43 t.Fatalf("write file failed: %v", err)
44 }
45
46 cmd := testenv.Command(t, testenv.GoToolPath(t), "run", "-gcflags=all="+flag, src)
47 out, err := cmd.CombinedOutput()
48 if err != nil {
49 t.Fatalf("go run failed: %v\n%s", err, out)
50 }
51 if string(out) != "hello\n" {
52 t.Errorf("wrong output: got %q, want %q", out, "hello\n")
53 }
54 }
55
View as plain text