diff --git a/race_test.go b/race_test.go index 5c4f150c..87eb770f 100644 --- a/race_test.go +++ b/race_test.go @@ -4,20 +4,19 @@ import ( "io/ioutil" "os" "os/exec" + "path/filepath" "testing" ) func TestRace(t *testing.T) { - tempfile, err := ioutil.TempFile("", "examplerace.*.go") + tempdir, err := ioutil.TempDir("", "race") if err != nil { t.Fatal(err) } - filename := tempfile.Name() - t.Log(filename) + defer os.RemoveAll(tempdir) - defer os.Remove(filename) - - _, err = tempfile.Write([]byte(` + filename := filepath.Join(tempdir, "example.go") + err = ioutil.WriteFile(filename, []byte(` package main import ( @@ -52,15 +51,11 @@ func TestRace(t *testing.T) { wg.Wait() } - `)) + `), 0755) if err != nil { t.Fatal(err) } - if err := tempfile.Close(); err != nil { - t.Fatal(err) - } - result, err := exec.Command("go", "run", "-race", filename).CombinedOutput() if err != nil || len(result) != 0 { t.Log(string(result))