From 1ea32573ddff2d374504dcc8102328ea790af85f Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 19 Apr 2023 10:43:56 -0400 Subject: [PATCH] singleflight: make the check for exec support in TestPanicDoChan platform-agnostic The new wasip1 GOOS does not support exec, but some ios environments (like Corellium) might. Update the test to exec itself with -test.list as a control case. For golang/go#58141. Change-Id: Id69950fc394910620f6c73cb437ca75c09ad8c29 Reviewed-on: https://go-review.googlesource.com/c/sync/+/485980 Run-TryBot: Bryan Mills Commit-Queue: Bryan Mills Reviewed-by: Dmitri Shuralyov Auto-Submit: Bryan Mills Reviewed-by: Johan Brandhorst-Satzkorn TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov --- singleflight/singleflight_test.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/singleflight/singleflight_test.go b/singleflight/singleflight_test.go index 3e51203..4a4e0b8 100644 --- a/singleflight/singleflight_test.go +++ b/singleflight/singleflight_test.go @@ -223,11 +223,24 @@ func TestGoexitDo(t *testing.T) { } } -func TestPanicDoChan(t *testing.T) { - if runtime.GOOS == "js" { - t.Skipf("js does not support exec") +func executable(t testing.TB) string { + exe, err := os.Executable() + if err != nil { + t.Skipf("skipping: test executable not found") } + // Control case: check whether exec.Command works at all. + // (For example, it might fail with a permission error on iOS.) + cmd := exec.Command(exe, "-test.list=^$") + cmd.Env = []string{} + if err := cmd.Run(); err != nil { + t.Skipf("skipping: exec appears not to work on %s: %v", runtime.GOOS, err) + } + + return exe +} + +func TestPanicDoChan(t *testing.T) { if os.Getenv("TEST_PANIC_DOCHAN") != "" { defer func() { recover() @@ -243,7 +256,7 @@ func TestPanicDoChan(t *testing.T) { t.Parallel() - cmd := exec.Command(os.Args[0], "-test.run="+t.Name(), "-test.v") + cmd := exec.Command(executable(t), "-test.run="+t.Name(), "-test.v") cmd.Env = append(os.Environ(), "TEST_PANIC_DOCHAN=1") out := new(bytes.Buffer) cmd.Stdout = out @@ -266,10 +279,6 @@ func TestPanicDoChan(t *testing.T) { } func TestPanicDoSharedByDoChan(t *testing.T) { - if runtime.GOOS == "js" { - t.Skipf("js does not support exec") - } - if os.Getenv("TEST_PANIC_DOCHAN") != "" { blocked := make(chan struct{}) unblock := make(chan struct{}) @@ -297,7 +306,7 @@ func TestPanicDoSharedByDoChan(t *testing.T) { t.Parallel() - cmd := exec.Command(os.Args[0], "-test.run="+t.Name(), "-test.v") + cmd := exec.Command(executable(t), "-test.run="+t.Name(), "-test.v") cmd.Env = append(os.Environ(), "TEST_PANIC_DOCHAN=1") out := new(bytes.Buffer) cmd.Stdout = out