From 03e6e36be99bb32358fc57e13a744edd88dac2ed Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Mon, 8 Jun 2020 13:15:04 -0400 Subject: [PATCH] internal/testenv: add a NeedsGoBuild function This function will skip tests in test environments where the go command can't be used to build and run binaries. This will be used by the test in golang.org/cl/236758 Change-Id: Ie61e8890084179b0e999dd377148693395043191 Reviewed-on: https://go-review.googlesource.com/c/tools/+/236920 Run-TryBot: Michael Matloob TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick Reviewed-by: Rebecca Stambler --- internal/testenv/testenv.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/testenv/testenv.go b/internal/testenv/testenv.go index ee8ef7199b..f725b959f8 100644 --- a/internal/testenv/testenv.go +++ b/internal/testenv/testenv.go @@ -220,6 +220,27 @@ func NeedsGoPackagesEnv(t Testing, env []string) { NeedsGoPackages(t) } +// NeedsGoBuild skips t if the current system can't build programs with ``go build'' +// and then run them with os.StartProcess or exec.Command. +// android, and darwin/arm systems don't have the userspace go build needs to run, +// and js/wasm doesn't support running subprocesses. +func NeedsGoBuild(t Testing) { + if t, ok := t.(helperer); ok { + t.Helper() + } + + NeedsTool(t, "go") + + switch runtime.GOOS { + case "android", "js": + t.Skipf("skipping test: %v can't build and run Go binaries", runtime.GOOS) + case "darwin": + if strings.HasPrefix(runtime.GOARCH, "arm") { + t.Skipf("skipping test: darwin/arm can't build and run Go binaries") + } + } +} + // ExitIfSmallMachine emits a helpful diagnostic and calls os.Exit(0) if the // current machine is a builder known to have scarce resources. //