Skip to content

Commit 5791239

Browse files
committed
internal/quic/cmd/interop: skip tests when exec is unavailable
Some platforms, such as js and wasip1, can't exec. Skip tests that need exec when it isn't available. Change-Id: Id3787b28c2ffe780eb24800c59fe69d12e04bbdd Reviewed-on: https://go-review.googlesource.com/c/net/+/539035 Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 4865e2a commit 5791239

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/quic/cmd/interop/main_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os/exec"
1616
"path/filepath"
1717
"strings"
18+
"sync"
1819
"testing"
1920
)
2021

@@ -26,13 +27,31 @@ func init() {
2627
}
2728
}
2829

30+
var (
31+
tryExecOnce sync.Once
32+
tryExecErr error
33+
)
34+
35+
// needsExec skips the test if we can't use exec.Command.
36+
func needsExec(t *testing.T) {
37+
tryExecOnce.Do(func() {
38+
cmd := exec.Command(os.Args[0], "-test.list=^$")
39+
cmd.Env = []string{}
40+
tryExecErr = cmd.Run()
41+
})
42+
if tryExecErr != nil {
43+
t.Skipf("skipping test: cannot exec subprocess: %v", tryExecErr)
44+
}
45+
}
46+
2947
type interopTest struct {
3048
donec chan struct{}
3149
addr string
3250
cmd *exec.Cmd
3351
}
3452

3553
func run(ctx context.Context, t *testing.T, name, testcase string, args []string) *interopTest {
54+
needsExec(t)
3655
ctx, cancel := context.WithCancel(ctx)
3756
cmd := exec.CommandContext(ctx, os.Args[0], args...)
3857
out, err := cmd.StderrPipe()

0 commit comments

Comments
 (0)