Debian Codegraph @

src/cmd/link/script_test.go

raw
1 // Copyright 2024 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "cmd/internal/script/scripttest"
9 "flag"
10 "internal/testenv"
11 "runtime"
12 "testing"
13 )
14
15 //go:generate go test cmd/link -v -run=TestScript/README --fixreadme
16
17 var fixReadme = flag.Bool("fixreadme", false, "if true, update README for script tests")
18
19 func TestScript(t *testing.T) {
20 testenv.MustHaveGoBuild(t)
21 doReplacement := true
22 switch runtime.GOOS {
23 case "wasip1", "js":
24 // wasm doesn't support os.Executable, so we'll skip replacing
25 // the installed linker with our test binary.
26 doReplacement = false
27 }
28 repls := []scripttest.ToolReplacement{}
29 if doReplacement {
30 if testLinker == "" {
31 t.Fatalf("testLinker not set, can't replace")
32 }
33 repls = []scripttest.ToolReplacement{
34 scripttest.ToolReplacement{
35 ToolName: "link",
36 ReplacementPath: testLinker,
37 EnvVar: "LINK_TEST_EXEC_LINKER=1",
38 },
39 }
40 }
41 scripttest.RunToolScriptTest(t, repls, "testdata/script", *fixReadme)
42 }