Skip to content

Commit

Permalink
feat: test framework supports turning off -race flag (#605)
Browse files Browse the repository at this point in the history
This is useful on Windows where gcc is not always
available.

Co-authored-by: Jonatan Wallmander <[email protected]>
  • Loading branch information
jaw and Jonatan Wallmander authored Dec 6, 2024
1 parent 069db27 commit 0540b4d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion testscript/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 0540b4d

Please sign in to comment.