diff options
Diffstat (limited to 'libgo/go/cmd/go/script_test.go')
-rw-r--r-- | libgo/go/cmd/go/script_test.go | 86 |
1 files changed, 65 insertions, 21 deletions
diff --git a/libgo/go/cmd/go/script_test.go b/libgo/go/cmd/go/script_test.go index 4dcb4b4e0d5..ec498bbcd76 100644 --- a/libgo/go/cmd/go/script_test.go +++ b/libgo/go/cmd/go/script_test.go @@ -30,6 +30,7 @@ import ( "cmd/go/internal/robustio" "cmd/go/internal/txtar" "cmd/go/internal/work" + "cmd/internal/sys" ) // TestScript runs the tests in testdata/script/*.txt. @@ -117,6 +118,7 @@ func (ts *testScript) setup() { "GOSUMDB=" + testSumDBVerifierKey, "GONOPROXY=", "GONOSUMDB=", + "PWD=" + ts.cd, tempEnvName() + "=" + filepath.Join(ts.workdir, "tmp"), "devnull=" + os.DevNull, "goversion=" + goVersion(ts), @@ -291,6 +293,22 @@ Script: }).(bool) break } + if strings.HasPrefix(cond.tag, "GODEBUG:") { + value := strings.TrimPrefix(cond.tag, "GODEBUG:") + parts := strings.Split(os.Getenv("GODEBUG"), ",") + for _, p := range parts { + if strings.TrimSpace(p) == value { + ok = true + break + } + } + break + } + if strings.HasPrefix(cond.tag, "buildmode:") { + value := strings.TrimPrefix(cond.tag, "buildmode:") + ok = sys.BuildModeSupported(runtime.Compiler, value, runtime.GOOS, runtime.GOARCH) + break + } if !imports.KnownArch[cond.tag] && !imports.KnownOS[cond.tag] && cond.tag != "gc" && cond.tag != "gccgo" { ts.fatalf("unknown condition %q", cond.tag) } @@ -414,6 +432,7 @@ func (ts *testScript) cmdCd(neg bool, args []string) { ts.fatalf("%s is not a directory", dir) } ts.cd = dir + ts.envMap["PWD"] = dir fmt.Fprintf(&ts.log, "%s\n", ts.cd) } @@ -429,7 +448,11 @@ func (ts *testScript) cmdChmod(neg bool, args []string) { if err != nil || perm&uint64(os.ModePerm) != perm { ts.fatalf("invalid mode: %s", args[0]) } - for _, path := range args[1:] { + for _, arg := range args[1:] { + path := arg + if !filepath.IsAbs(path) { + path = filepath.Join(ts.cd, arg) + } err := os.Chmod(path, os.FileMode(perm)) ts.check(err) } @@ -441,10 +464,15 @@ func (ts *testScript) cmdCmp(neg bool, args []string) { // It would be strange to say "this file can have any content except this precise byte sequence". ts.fatalf("unsupported: ! cmp") } + quiet := false + if len(args) > 0 && args[0] == "-q" { + quiet = true + args = args[1:] + } if len(args) != 2 { ts.fatalf("usage: cmp file1 file2") } - ts.doCmdCmp(args, false) + ts.doCmdCmp(args, false, quiet) } // cmpenv compares two files with environment variable substitution. @@ -452,13 +480,18 @@ func (ts *testScript) cmdCmpenv(neg bool, args []string) { if neg { ts.fatalf("unsupported: ! cmpenv") } + quiet := false + if len(args) > 0 && args[0] == "-q" { + quiet = true + args = args[1:] + } if len(args) != 2 { ts.fatalf("usage: cmpenv file1 file2") } - ts.doCmdCmp(args, true) + ts.doCmdCmp(args, true, quiet) } -func (ts *testScript) doCmdCmp(args []string, env bool) { +func (ts *testScript) doCmdCmp(args []string, env, quiet bool) { name1, name2 := args[0], args[1] var text1, text2 string if name1 == "stdout" { @@ -484,15 +517,14 @@ func (ts *testScript) doCmdCmp(args []string, env bool) { return } - fmt.Fprintf(&ts.log, "[diff -%s +%s]\n%s\n", name1, name2, diff(text1, text2)) + if !quiet { + fmt.Fprintf(&ts.log, "[diff -%s +%s]\n%s\n", name1, name2, diff(text1, text2)) + } ts.fatalf("%s and %s differ", name1, name2) } // cp copies files, maybe eventually directories. func (ts *testScript) cmdCp(neg bool, args []string) { - if neg { - ts.fatalf("unsupported: ! cp") - } if len(args) < 2 { ts.fatalf("usage: cp src... dst") } @@ -531,7 +563,14 @@ func (ts *testScript) cmdCp(neg bool, args []string) { if dstDir { targ = filepath.Join(dst, filepath.Base(src)) } - ts.check(ioutil.WriteFile(targ, data, mode)) + err := ioutil.WriteFile(targ, data, mode) + if neg { + if err == nil { + ts.fatalf("unexpected command success") + } + } else { + ts.check(err) + } } } @@ -547,26 +586,31 @@ func (ts *testScript) cmdEnv(neg bool, args []string) { args = args[1:] } + var out strings.Builder if len(args) == 0 { printed := make(map[string]bool) // env list can have duplicates; only print effective value (from envMap) once for _, kv := range ts.env { k := kv[:strings.Index(kv, "=")] if !printed[k] { - fmt.Fprintf(&ts.log, "%s=%s\n", k, ts.envMap[k]) + fmt.Fprintf(&out, "%s=%s\n", k, ts.envMap[k]) } } - return - } - for _, env := range args { - i := strings.Index(env, "=") - if i < 0 { - // Display value instead of setting it. - fmt.Fprintf(&ts.log, "%s=%s\n", env, ts.envMap[env]) - continue + } else { + for _, env := range args { + i := strings.Index(env, "=") + if i < 0 { + // Display value instead of setting it. + fmt.Fprintf(&out, "%s=%s\n", env, ts.envMap[env]) + continue + } + key, val := env[:i], conv(env[i+1:]) + ts.env = append(ts.env, key+"="+val) + ts.envMap[key] = val } - key, val := env[:i], conv(env[i+1:]) - ts.env = append(ts.env, key+"="+val) - ts.envMap[key] = val + } + if out.Len() > 0 || len(args) > 0 { + ts.stdout = out.String() + ts.log.WriteString(out.String()) } } |