]> Cypherpunks repositories - gostls13.git/commitdiff
test: chdir before running go tool, cleanup afterwards.
authorRahul Chaudhry <rahulchaudhry@chromium.org>
Tue, 3 Feb 2015 20:41:52 +0000 (12:41 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 6 Feb 2015 05:16:34 +0000 (05:16 +0000)
issue9355 generated a file a.[568] in test/ directory and left it there.
For tests like these, it is best to chdir to a test specific directory
before generating any temporary files, since the tests are running
in parallel and might otherwise race with each other for the same files.

Change-Id: I58d96256d4d8ee3fda70d81077f19006064a7425
Reviewed-on: https://go-review.googlesource.com/3813
Reviewed-by: Ian Lance Taylor <iant@golang.org>
test/fixedbugs/issue9355.go

index 607197fe9565efdcd4647cff42ffac6e112a9a7b..bdc0dd06c683ab2a2db3a327f962b346df788774 100644 (file)
@@ -21,11 +21,14 @@ func main() {
                return
        }
        a, err := build.ArchChar(runtime.GOARCH)
-       if err != nil {
-               fmt.Println("BUG:", err)
-               os.Exit(1)
-       }
-       out := run("go", "tool", a+"g", "-S", filepath.Join("fixedbugs", "issue9355.dir", "a.go"))
+       check(err)
+
+       err = os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
+       check(err)
+
+       out := run("go", "tool", a+"g", "-S", "a.go")
+       os.Remove("a." + a)
+
        // 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
        patterns := []string{
                `rel 0\+\d t=1 \"\"\.x\+8\r?\n`,       // y = &x.b
@@ -50,3 +53,10 @@ func run(cmd string, args ...string) []byte {
        }
        return out
 }
+
+func check(err error) {
+       if err != nil {
+               fmt.Println("BUG:", err)
+               os.Exit(1)
+       }
+}