os/exec_test: fix test on Plan 9

Error strings vary across OSes when trying to execute a file
that does not exist. Since matching them is not the point of
the test, ignore them.

Fixes #76965

Change-Id: I6d220bc2d0289070f3441adb48983c13b2a3e597
Reviewed-on: https://go-review.googlesource.com/c/go/+/732940
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Richard Miller <millerresearch@gmail.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Ori Bernstein 2025-12-27 19:08:26 -05:00 committed by Gopher Robot
parent cbe153806e
commit b7e6d8b923

View file

@ -1845,23 +1845,13 @@ func TestStart_twice(t *testing.T) {
testenv.MustHaveExec(t)
cmd := exec.Command("/bin/nonesuch")
for i, want := range []string{
cond(runtime.GOOS == "windows",
`exec: "/bin/nonesuch": executable file not found in %PATH%`,
"fork/exec /bin/nonesuch: no such file or directory"),
"exec: already started",
} {
err := cmd.Start()
if got := fmt.Sprint(err); got != want {
t.Errorf("Start call #%d return err %q, want %q", i+1, got, want)
}
}
}
func cond[T any](cond bool, t, f T) T {
if cond {
return t
} else {
return f
if err := cmd.Start(); err == nil {
t.Fatalf("running invalid command succeeded")
}
err := cmd.Start()
got := fmt.Sprint(err)
want := "exec: already started"
if got != want {
t.Fatalf("Start call returned err %q, want %q", got, want)
}
}