From 4d7c89fec32afc7422872e735097c3270d854da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 4 Nov 2019 18:44:54 +0000 Subject: [PATCH] cmd/gogio: simplify the test -race setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In an earlier commit, we made it possible to run the e2e tests with the race detector enabled everywhere via GOFLAGS=-race go test. However, that's not at all standard; most users will simply use 'go test -race'. Moreover, having 'go test -race' run the test program with the race detector, but not the e2e gio app, is a bit useless. Instead, have the tests detect when they run with the race detector, and enable the race detector in the test app too. As before, the JS test is skipped whenever -race is used. This also means we can test with -race in the same way in each of the modules, which simplifies CI. Signed-off-by: Daniel Martí --- .builds/linux.yml | 2 +- cmd/gogio/wayland_test.go | 7 ++++++- cmd/gogio/x11_test.go | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.builds/linux.yml b/.builds/linux.yml index c7922bc5..e0a5af23 100644 --- a/.builds/linux.yml +++ b/.builds/linux.yml @@ -36,7 +36,7 @@ tasks: - test_cmd: | cd gio/cmd go test ./... - GOFLAGS=-race go test ./... + go test -race ./... - check_gofmt: | cd gio test -z $(gofmt -s -l .) diff --git a/cmd/gogio/wayland_test.go b/cmd/gogio/wayland_test.go index bd93aa77..5294d07d 100644 --- a/cmd/gogio/wayland_test.go +++ b/cmd/gogio/wayland_test.go @@ -72,7 +72,12 @@ func (d *WaylandTestDriver) Start(t_ *testing.T, path string, width, height int) cleanups = append(cleanups, func() { os.RemoveAll(dir) }) bin := filepath.Join(dir, "red") - cmd := exec.Command("go", "build", "-tags", "nox11", "-o="+bin, path) + flags := []string{"build", "-tags", "nox11", "-o="+bin} + if raceEnabled { + flags = append(flags, "-race") + } + flags = append(flags, path) + cmd := exec.Command("go", flags...) if out, err := cmd.CombinedOutput(); err != nil { d.t.Fatalf("could not build app: %s:\n%s", err, out) } diff --git a/cmd/gogio/x11_test.go b/cmd/gogio/x11_test.go index 8df1cf6a..88b965fd 100644 --- a/cmd/gogio/x11_test.go +++ b/cmd/gogio/x11_test.go @@ -69,7 +69,12 @@ func (d *X11TestDriver) Start(t_ *testing.T, path string, width, height int) (cl cleanups = append(cleanups, func() { os.RemoveAll(dir) }) bin := filepath.Join(dir, "red") - cmd := exec.Command("go", "build", "-tags", "nowayland", "-o="+bin, path) + flags := []string{"build", "-tags", "nowayland", "-o="+bin} + if raceEnabled { + flags = append(flags, "-race") + } + flags = append(flags, path) + cmd := exec.Command("go", flags...) if out, err := cmd.CombinedOutput(); err != nil { d.t.Fatalf("could not build app: %s:\n%s", err, out) }