Skip to content

Commit 1ea3257

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Commit-Queue: Bryan Mills <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 8fcdb60 commit 1ea3257

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

singleflight/singleflight_test.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,24 @@ func TestGoexitDo(t *testing.T) {
223223
}
224224
}
225225

226-
func TestPanicDoChan(t *testing.T) {
227-
if runtime.GOOS == "js" {
228-
t.Skipf("js does not support exec")
226+
func executable(t testing.TB) string {
227+
exe, err := os.Executable()
228+
if err != nil {
229+
t.Skipf("skipping: test executable not found")
229230
}
230231

232+
// Control case: check whether exec.Command works at all.
233+
// (For example, it might fail with a permission error on iOS.)
234+
cmd := exec.Command(exe, "-test.list=^$")
235+
cmd.Env = []string{}
236+
if err := cmd.Run(); err != nil {
237+
t.Skipf("skipping: exec appears not to work on %s: %v", runtime.GOOS, err)
238+
}
239+
240+
return exe
241+
}
242+
243+
func TestPanicDoChan(t *testing.T) {
231244
if os.Getenv("TEST_PANIC_DOCHAN") != "" {
232245
defer func() {
233246
recover()
@@ -243,7 +256,7 @@ func TestPanicDoChan(t *testing.T) {
243256

244257
t.Parallel()
245258

246-
cmd := exec.Command(os.Args[0], "-test.run="+t.Name(), "-test.v")
259+
cmd := exec.Command(executable(t), "-test.run="+t.Name(), "-test.v")
247260
cmd.Env = append(os.Environ(), "TEST_PANIC_DOCHAN=1")
248261
out := new(bytes.Buffer)
249262
cmd.Stdout = out
@@ -266,10 +279,6 @@ func TestPanicDoChan(t *testing.T) {
266279
}
267280

268281
func TestPanicDoSharedByDoChan(t *testing.T) {
269-
if runtime.GOOS == "js" {
270-
t.Skipf("js does not support exec")
271-
}
272-
273282
if os.Getenv("TEST_PANIC_DOCHAN") != "" {
274283
blocked := make(chan struct{})
275284
unblock := make(chan struct{})
@@ -297,7 +306,7 @@ func TestPanicDoSharedByDoChan(t *testing.T) {
297306

298307
t.Parallel()
299308

300-
cmd := exec.Command(os.Args[0], "-test.run="+t.Name(), "-test.v")
309+
cmd := exec.Command(executable(t), "-test.run="+t.Name(), "-test.v")
301310
cmd.Env = append(os.Environ(), "TEST_PANIC_DOCHAN=1")
302311
out := new(bytes.Buffer)
303312
cmd.Stdout = out

0 commit comments

Comments
 (0)