Source file
src/cmd/compile/script_test.go
1
2
3
4
5 package main
6
7 import (
8 "cmd/internal/script/scripttest"
9 "flag"
10 "internal/testenv"
11 "os"
12 "runtime"
13 "testing"
14 )
15
16
17
18 var fixReadme = flag.Bool("fixreadme", false, "if true, update README for script tests")
19
20 var testCompiler string
21
22
23
24
25
26
27 func TestMain(m *testing.M) {
28
29
30 if os.Getenv("COMPILE_TEST_EXEC_COMPILE") != "" {
31 main()
32 os.Exit(0)
33 }
34
35 if testExe, err := os.Executable(); err == nil {
36
37 testCompiler = testExe
38 }
39
40
41 os.Exit(m.Run())
42 }
43
44 func TestScript(t *testing.T) {
45 testenv.MustHaveGoBuild(t)
46 doReplacement := true
47 switch runtime.GOOS {
48 case "wasip1", "js":
49
50
51 doReplacement = false
52 }
53 repls := []scripttest.ToolReplacement{}
54 if doReplacement {
55 if testCompiler == "" {
56 t.Fatalf("testCompiler not set, can't replace")
57 }
58 repls = []scripttest.ToolReplacement{
59 scripttest.ToolReplacement{
60 ToolName: "compile",
61 ReplacementPath: testCompiler,
62 EnvVar: "COMPILE_TEST_EXEC_COMPILE=1",
63 },
64 }
65 }
66 scripttest.RunToolScriptTest(t, repls, "testdata/script", *fixReadme)
67 }
68
View as plain text