0540b4d23a8f1ce9b1569cde5046d790e9de2260

Author
Jonatan Wallmander <jonatan@vovoid.com>
Committer
GitHub <noreply@github.com>
Date

Message

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 <jonatan.wallmander@kdab.com>

Diff

 1diff --git a/testscript/script_test.go b/testscript/script_test.go
 2index 8f3a6af43497752cae064723faf0ccc1da02c8b1..6162caa3e379816200d9363cc41bd2922bb065e6 100644
 3--- a/testscript/script_test.go
 4+++ b/testscript/script_test.go
 5@@ -34,6 +34,15 @@ var (
 6 	binPath string
 7 )
 8 
 9+func PrepareBuildCommand(binPath string) *exec.Cmd {
10+	_, disableRaceSet := os.LookupEnv("SOFT_SERVE_DISABLE_RACE_CHECKS")
11+	if disableRaceSet {
12+		// don't add the -race flag
13+		return exec.Command("go", "build", "-cover", "-o", binPath, filepath.Join("..", "cmd", "soft"))
14+	}
15+	return exec.Command("go", "build", "-race", "-cover", "-o", binPath, filepath.Join("..", "cmd", "soft"))
16+}
17+
18 func TestMain(m *testing.M) {
19 	tmp, err := os.MkdirTemp("", "soft-serve*")
20 	if err != nil {
21@@ -48,7 +57,7 @@ func TestMain(m *testing.M) {
22 	}
23 
24 	// Build the soft binary with -cover flag.
25-	cmd := exec.Command("go", "build", "-race", "-cover", "-o", binPath, filepath.Join("..", "cmd", "soft"))
26+	cmd := PrepareBuildCommand(binPath)
27 	if err := cmd.Run(); err != nil {
28 		fmt.Fprintf(os.Stderr, "failed to build soft-serve binary: %s", err)
29 		os.Exit(1)