os/exec_test: fix test on Plan 9
Plan 9 error strings are different from Windows and Linux ones.
Match them in a way that will work across all of the various
Plan 9 distributions.
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index bf2f3da..149a802 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -1845,23 +1845,16 @@
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",
- } {
+ msg := "fork/exec /bin/nonesuch: no such file or directory"
+ if runtime.GOOS == "windows" {
+ msg = `exec: "/bin/nonesuch": executable file not found in %PATH%`
+ } else if runtime.GOOS == "plan9" {
+ msg = "directory entry not found"
+ }
+ for i, want := range []string{msg, "exec: already started"} {
err := cmd.Start()
- if got := fmt.Sprint(err); got != want {
+ if got := fmt.Sprint(err); !strings.Contains(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
- }
-}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
msg = `exec: "/bin/nonesuch": executable file not found in %PATH%`I don't see any reason to check for specific error text at all. What matters is the "already started" error. The other error doesn't matter.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
This change wouldn't fix the failure in AIX reported as issue #76965 where the error message is different. It wouldn't even fix the failures on the plan9-arm builder (see https://luci-milo.appspot.com/ui/p/golang/builders/ci/gotip-plan9-arm/b8694296900071569313/overview) where the error message is "file does not exist" and not "directory entry not found". That builder currently mounts `/tmp` on the `ramfs` file server, which reports some errors with a different syntax.
As @ia...@golang.org said (and as I had commented on #76965), what matters is just to check that the second iteration reports "already started" and the first iteration doesn't.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
msg = `exec: "/bin/nonesuch": executable file not found in %PATH%`I don't see any reason to check for specific error text at all. What matters is the "already started" error. The other error doesn't matter.
Good point. Let's unroll the loop and discard the result of the first Start call.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |