Skip to content

Commit

Permalink
internal/quic/cmd/interop: skip tests when exec is unavailable
Browse files Browse the repository at this point in the history
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 <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
neild committed Nov 1, 2023
1 parent 4865e2a commit 5791239
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/quic/cmd/interop/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"
"testing"
)

Expand All @@ -26,13 +27,31 @@ func init() {
}
}

var (
tryExecOnce sync.Once
tryExecErr error
)

// needsExec skips the test if we can't use exec.Command.
func needsExec(t *testing.T) {
tryExecOnce.Do(func() {
cmd := exec.Command(os.Args[0], "-test.list=^$")
cmd.Env = []string{}
tryExecErr = cmd.Run()
})
if tryExecErr != nil {
t.Skipf("skipping test: cannot exec subprocess: %v", tryExecErr)
}
}

type interopTest struct {
donec chan struct{}
addr string
cmd *exec.Cmd
}

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

0 comments on commit 5791239

Please sign in to comment.