From 2a4829d857047d248ff09852ebd9d5d3040b8d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 3 Nov 2019 12:00:35 +0000 Subject: [PATCH] cmd/gogio: support running e2e with and without -race MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now, we can only run the e2e gio app with -race, not without -race, because the flag is hard-coded in the tests. The reason for this change was that 'GOFLAGS=-race go test' would fail with the JS test, since js/wasm doesn't support the race detector. Fix that by skipping the JS test when -race is used. Now, we can run multiple levels of -race: go test # no -race at all go test -race # -race for the tests, not the e2e gio app GOFLAGS=-race go test # -race for everything (best-effort) To detect the race detector being on, we use a file with a build tag. Signed-off-by: Daniel Martí --- cmd/gogio/e2e_test.go | 2 ++ cmd/gogio/js_test.go | 4 ++++ cmd/gogio/race_test.go | 7 +++++++ cmd/gogio/wayland_test.go | 2 +- cmd/gogio/x11_test.go | 2 +- 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 cmd/gogio/race_test.go diff --git a/cmd/gogio/e2e_test.go b/cmd/gogio/e2e_test.go index de7017f3..e269c5fe 100644 --- a/cmd/gogio/e2e_test.go +++ b/cmd/gogio/e2e_test.go @@ -9,6 +9,8 @@ import ( "testing" ) +var raceEnabled = false + var headless = flag.Bool("headless", true, "run end-to-end tests in headless mode") // TestDriver is implemented by each of the platforms we can run end-to-end diff --git a/cmd/gogio/js_test.go b/cmd/gogio/js_test.go index 627a24af..92cb5882 100644 --- a/cmd/gogio/js_test.go +++ b/cmd/gogio/js_test.go @@ -33,6 +33,10 @@ type JSTestDriver struct { func (d *JSTestDriver) Start(t_ *testing.T, path string, width, height int) (cleanups []func()) { d.t = t_ + if raceEnabled { + d.t.Skipf("js/wasm doesn't support -race; skipping") + } + // First, build the app. dir, err := ioutil.TempDir("", "gio-endtoend-js") if err != nil { diff --git a/cmd/gogio/race_test.go b/cmd/gogio/race_test.go new file mode 100644 index 00000000..07499364 --- /dev/null +++ b/cmd/gogio/race_test.go @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: Unlicense OR MIT + +// +build race + +package main_test + +func init() { raceEnabled = true } diff --git a/cmd/gogio/wayland_test.go b/cmd/gogio/wayland_test.go index d98f2279..bd93aa77 100644 --- a/cmd/gogio/wayland_test.go +++ b/cmd/gogio/wayland_test.go @@ -72,7 +72,7 @@ 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", "-race", "-tags", "nox11", "-o="+bin, path) + cmd := exec.Command("go", "build", "-tags", "nox11", "-o="+bin, path) 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 05a1f147..8df1cf6a 100644 --- a/cmd/gogio/x11_test.go +++ b/cmd/gogio/x11_test.go @@ -69,7 +69,7 @@ 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", "-race", "-tags", "nowayland", "-o="+bin, path) + cmd := exec.Command("go", "build", "-tags", "nowayland", "-o="+bin, path) if out, err := cmd.CombinedOutput(); err != nil { d.t.Fatalf("could not build app: %s:\n%s", err, out) }