]> Cypherpunks repositories - gostls13.git/commitdiff
internal/testenv: MustHaveExec: use sync.OnceValue
authorKir Kolyshkin <kolyshkin@gmail.com>
Thu, 29 Aug 2024 23:46:16 +0000 (16:46 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 30 Aug 2024 16:26:31 +0000 (16:26 +0000)
Change-Id: I048474fc93bb8c149672b66f98d71eec0eb8aad7
Reviewed-on: https://go-review.googlesource.com/c/go/+/609795
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/internal/testenv/exec.go

index 7f6ad5cac4e39b603c0f59b797ff84c926a5bc5d..ebb70a1375f81fe15103d2ba90312e766e9ead98 100644 (file)
@@ -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