From: Kir Kolyshkin Date: Thu, 29 Aug 2024 23:46:16 +0000 (-0700) Subject: internal/testenv: MustHaveExec: use sync.OnceValue X-Git-Tag: go1.24rc1~1085 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=46985f4ec2a83241de4c0cec522df0ed19a3635d;p=gostls13.git internal/testenv: MustHaveExec: use sync.OnceValue Change-Id: I048474fc93bb8c149672b66f98d71eec0eb8aad7 Reviewed-on: https://go-review.googlesource.com/c/go/+/609795 Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Alan Donovan Auto-Submit: Ian Lance Taylor --- diff --git a/src/internal/testenv/exec.go b/src/internal/testenv/exec.go index 7f6ad5cac4..ebb70a1375 100644 --- a/src/internal/testenv/exec.go +++ b/src/internal/testenv/exec.go @@ -31,20 +31,12 @@ import ( // If exec is not supported, testenv.SyscallIsNotSupported will return true // for the resulting error. func MustHaveExec(t testing.TB) { - tryExecOnce.Do(func() { - tryExecErr = tryExec() - }) - if tryExecErr != nil { - t.Skipf("skipping test: cannot exec subprocess on %s/%s: %v", runtime.GOOS, runtime.GOARCH, tryExecErr) + if err := tryExec(); err != nil { + t.Skipf("skipping test: cannot exec subprocess on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err) } } -var ( - tryExecOnce sync.Once - tryExecErr error -) - -func tryExec() error { +var tryExec = sync.OnceValue(func() error { switch runtime.GOOS { case "wasip1", "js", "ios": default: @@ -77,7 +69,7 @@ func tryExec() error { cmd := exec.Command(exe, "-test.list=^$") cmd.Env = origEnv return cmd.Run() -} +}) var execPaths sync.Map // path -> error