From 0540b4d23a8f1ce9b1569cde5046d790e9de2260 Mon Sep 17 00:00:00 2001 From: Jonatan Wallmander Date: Fri, 6 Dec 2024 23:14:59 +0100 Subject: [PATCH] feat: test framework supports turning off -race flag (#605) This is useful on Windows where gcc is not always available. Co-authored-by: Jonatan Wallmander --- testscript/script_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/testscript/script_test.go b/testscript/script_test.go index 8f3a6af43497752cae064723faf0ccc1da02c8b1..6162caa3e379816200d9363cc41bd2922bb065e6 100644 --- a/testscript/script_test.go +++ b/testscript/script_test.go @@ -34,6 +34,15 @@ var ( binPath string ) +func PrepareBuildCommand(binPath string) *exec.Cmd { + _, disableRaceSet := os.LookupEnv("SOFT_SERVE_DISABLE_RACE_CHECKS") + if disableRaceSet { + // don't add the -race flag + return exec.Command("go", "build", "-cover", "-o", binPath, filepath.Join("..", "cmd", "soft")) + } + return exec.Command("go", "build", "-race", "-cover", "-o", binPath, filepath.Join("..", "cmd", "soft")) +} + func TestMain(m *testing.M) { tmp, err := os.MkdirTemp("", "soft-serve*") if err != nil { @@ -48,7 +57,7 @@ func TestMain(m *testing.M) { } // Build the soft binary with -cover flag. - cmd := exec.Command("go", "build", "-race", "-cover", "-o", binPath, filepath.Join("..", "cmd", "soft")) + cmd := PrepareBuildCommand(binPath) if err := cmd.Run(); err != nil { fmt.Fprintf(os.Stderr, "failed to build soft-serve binary: %s", err) os.Exit(1)