-43e458ab704e04cdf347f3e74e0b0eff3de00a3d
+4fbd06dc7b1b8fb665293399a2b6d5326435512f
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
select {}
}
- dir, err := ioutil.TempDir(os.Getenv("GOTMPDIR"), "cmd-go-test-")
+ // Run with a temporary TMPDIR to check that the tests don't
+ // leave anything behind.
+ topTmpdir, err := ioutil.TempDir("", "cmd-go-test-")
+ if err != nil {
+ log.Fatal(err)
+ }
+ if !*testWork {
+ defer removeAll(topTmpdir)
+ }
+ os.Setenv(tempEnvName(), topTmpdir)
+
+ dir, err := ioutil.TempDir(topTmpdir, "tmpdir")
if err != nil {
log.Fatal(err)
}
removeAll(testTmpDir) // os.Exit won't run defer
}
+ if !*testWork {
+ // There shouldn't be anything left in topTmpdir.
+ dirf, err := os.Open(topTmpdir)
+ if err != nil {
+ log.Fatal(err)
+ }
+ names, err := dirf.Readdirnames(0)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if len(names) > 0 {
+ log.Fatalf("unexpected files left in tmpdir: %v", names)
+ }
+
+ removeAll(topTmpdir)
+ }
+
os.Exit(r)
}
obj := tg.path("main")
tg.run("build", "-x", "-o", obj, src)
sh := tg.path("test.sh")
- err := ioutil.WriteFile(sh, []byte("set -e\n"+tg.getStderr()), 0666)
+ cmds := tg.getStderr()
+ err := ioutil.WriteFile(sh, []byte("set -e\n"+cmds), 0666)
if err != nil {
t.Fatal(err)
}
if string(out) != "hello" {
t.Fatalf("got %q; want %q", out, "hello")
}
+
+ matches := regexp.MustCompile(`^WORK=(.*)\n`).FindStringSubmatch(cmds)
+ if len(matches) == 0 {
+ t.Fatal("no WORK directory")
+ }
+ tg.must(os.RemoveAll(matches[1]))
}
func TestParallelNumber(t *testing.T) {
func (c *Command) Usage() {
fmt.Fprintf(os.Stderr, "usage: %s\n", c.UsageLine)
fmt.Fprintf(os.Stderr, "Run 'go help %s' for details.\n", c.LongName())
- os.Exit(2)
+ SetExitStatus(2)
+ Exit()
}
// Runnable reports whether the command can be run; otherwise
} else {
fmt.Fprintf(os.Stderr, `run "go help %s" for more information`+"\n", cmd)
}
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
// AddKnownFlags registers the flags in defns with base.AddKnownFlag.
helpSuccess = " " + strings.Join(args[:i], " ")
}
fmt.Fprintf(os.Stderr, "go help %s: unknown help topic. Run '%s'.\n", strings.Join(args, " "), helpSuccess)
- os.Exit(2) // failed at 'go help cmd'
+ base.SetExitStatus(2) // failed at 'go help cmd'
+ base.Exit()
}
if len(cmd.Commands) > 0 {
if ew.err != nil {
// I/O error writing. Ignore write on closed pipe.
if strings.Contains(ew.err.Error(), "pipe") {
- os.Exit(1)
+ base.SetExitStatus(1)
+ base.Exit()
}
base.Fatalf("writing output: %v", ew.err)
}
vetcmd.Stdout = out
if err := vetcmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "go vet: can't execute %s -flags: %v\n", tool, err)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
var analysisFlags []struct {
Name string
}
if err := json.Unmarshal(out.Bytes(), &analysisFlags); err != nil {
fmt.Fprintf(os.Stderr, "go vet: can't unmarshal JSON from %s -flags: %v", tool, err)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
// Add vet's flags to vetflagDefn.
if f == nil {
fmt.Fprintf(os.Stderr, "vet: flag %q not defined\n", args[i])
fmt.Fprintf(os.Stderr, "Run \"go help vet\" for more information\n")
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
if f.Value != nil {
if err := f.Value.Set(value); err != nil {
}
fmt.Fprintf(os.Stderr, "Run '%s -help' for the vet tool's flags.\n", cmd)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
if _, ok := cfg.OSArchSupportsCgo[cfg.Goos+"/"+cfg.Goarch]; !ok && cfg.BuildContext.Compiler == "gc" {
fmt.Fprintf(os.Stderr, "cmd/go: unsupported GOOS/GOARCH pair %s/%s\n", cfg.Goos, cfg.Goarch)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
for _, tag := range cfg.BuildContext.BuildTags {
if strings.Contains(tag, ",") {
fmt.Fprintf(os.Stderr, "cmd/go: -tags space-separated list contains comma\n")
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
}
}
// version of GCC, so some systems have frozen on it.
// Now we pass an empty file on stdin, which should work at least for
// GCC and clang.
- cmdArgs := str.StringList(compiler, flag, "-c", "-x", "c", "-")
+ cmdArgs := str.StringList(compiler, flag, "-c", "-x", "c", "-", "-o", os.DevNull)
if cfg.BuildN || cfg.BuildX {
b.Showcmd(b.WorkDir, "%s || true", joinUnambiguously(cmdArgs))
if cfg.BuildN {
return
}
fmt.Fprintf(os.Stderr, "cmd/go: gccgo: %s\n", gccgoErr)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
func (tools gccgoToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, symabis string, asmhdr bool, gofiles []string) (ofile string, output []byte, err error) {
p, err := filepath.Abs(cfg.BuildPkgdir)
if err != nil {
fmt.Fprintf(os.Stderr, "go %s: evaluating -pkgdir: %v\n", flag.Args()[0], err)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
cfg.BuildPkgdir = p
}
}
if cfg.BuildRace && cfg.BuildMSan {
fmt.Fprintf(os.Stderr, "go %s: may not use -race and -msan simultaneously\n", flag.Args()[0])
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
if cfg.BuildMSan && !sys.MSanSupported(cfg.Goos, cfg.Goarch) {
fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
if cfg.BuildRace {
if !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0])
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
}
mode := "race"
if !cfg.BuildContext.CgoEnabled {
fmt.Fprintf(os.Stderr, "go %s: %s requires cgo; enable cgo by setting CGO_ENABLED=1\n", flag.Args()[0], modeFlag)
- os.Exit(2)
+ base.SetExitStatus(2)
+ base.Exit()
}
forcedGcflags = append(forcedGcflags, modeFlag)
forcedLdflags = append(forcedLdflags, modeFlag)
var b work.Builder
b.Init()
ts.cmdExec(neg, append(b.GccCmd(".", ""), args...))
+ os.RemoveAll(b.WorkDir)
}
// cd changes to a different directory.