test: only enable race detector when supported

Closes: #1228
This commit is contained in:
Aloïs Micard
2021-08-27 15:50:13 +02:00
committed by GitHub
parent b7f9a39eff
commit 7b77b0fa22

View File

@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
@@ -49,7 +50,15 @@ func TestYaegiCmdCancel(t *testing.T) {
}()
yaegi := filepath.Join(tmp, "yaegi")
build := exec.Command("go", "build", "-race", "-o", yaegi, ".")
args := []string{"build"}
if raceDetectorSupported(runtime.GOOS, runtime.GOARCH) {
args = append(args, "-race")
}
args = append(args, "-o", yaegi, ".")
build := exec.Command("go", args...)
out, err := build.CombinedOutput()
if err != nil {
t.Fatalf("failed to build yaegi command: %v: %s", err, out)
@@ -115,3 +124,16 @@ func TestYaegiCmdCancel(t *testing.T) {
}
}
}
func raceDetectorSupported(goos, goarch string) bool {
switch goos {
case "linux":
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
case "darwin":
return goarch == "amd64" || goarch == "arm64"
case "freebsd", "netbsd", "openbsd", "windows":
return goarch == "amd64"
default:
return false
}
}