From f6df25d79567923f85cd790839e3fcf83cf227fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 2 May 2023 18:09:11 +0200 Subject: [PATCH] testscript: fix "signal: killed" exec errors on MacOS On `MacOS` there are lots of reports of unexpected failing tests with output similar to this: ``` [signal: killed] FAIL: testscripts/myecho.txt:1: unexpected command failure ``` On CI builds the workaround has been to downgrade to a builder with MacOS <= 11 (e.g. macos-11 on GitHub). In development on a MacBook, this is not an option. This commit works around what seem to be a upstream bug in `os.Link` by adding a small sleep before `TestingM.Run()` to allow the write of the test command symlinks to be ready. See #200 --- testscript/exe.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testscript/exe.go b/testscript/exe.go index ed6bd98d..f40a48a9 100644 --- a/testscript/exe.go +++ b/testscript/exe.go @@ -12,6 +12,7 @@ import ( "path/filepath" "runtime" "strings" + "time" ) // TestingM is implemented by *testing.M. It's defined as an interface @@ -97,6 +98,14 @@ func RunMain(m TestingM, commands map[string]func() int) (exitCode int) { ts.cmdExec(neg, append([]string{name}, args...)) } } + + if runtime.GOOS == "darwin" { + // There seem to be an issue with os.Link on newer versions of macOS. + // Wait a little to make sure the test binaries are ready. + // See issue #200. + time.Sleep(200 * time.Millisecond) + } + return m.Run() } // The command being registered is being invoked, so run it, then exit.