aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/dot_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-07-27 14:36:05 -0400
committerRuss Cox <rsc@golang.org>2022-07-28 19:12:40 +0000
commit027855e8d86f461b50946b006ea032d4b4a7d817 (patch)
treecc6bbabb15481f4d669f835c946bfbcf7c2c6313 /src/os/exec/dot_test.go
parent462b78fe7027ef0d2e2b40c3cfd1f5a37d307310 (diff)
downloadgo-027855e8d86f461b50946b006ea032d4b4a7d817.tar.xz
os/exec: add GODEBUG setting to opt out of ErrDot changes
The changes are likely to break users, and we need to make it easy to unbreak without code changes. For #43724. Fixes #53962. Change-Id: I105c5d6c801d354467e0cefd268189c18846858e Reviewed-on: https://go-review.googlesource.com/c/go/+/419794 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/os/exec/dot_test.go')
-rw-r--r--src/os/exec/dot_test.go80
1 files changed, 49 insertions, 31 deletions
diff --git a/src/os/exec/dot_test.go b/src/os/exec/dot_test.go
index e2d2dba7a5..306f98cbaa 100644
--- a/src/os/exec/dot_test.go
+++ b/src/os/exec/dot_test.go
@@ -56,40 +56,58 @@ func TestLookPath(t *testing.T) {
// Add "." to PATH so that exec.LookPath looks in the current directory on all systems.
// And try to trick it with "../testdir" too.
- for _, dir := range []string{".", "../testdir"} {
- t.Run(pathVar+"="+dir, func(t *testing.T) {
- t.Setenv(pathVar, dir+string(filepath.ListSeparator)+origPath)
- good := dir + "/execabs-test"
- if found, err := LookPath(good); err != nil || !strings.HasPrefix(found, good) {
- t.Fatalf(`LookPath(%#q) = %#q, %v, want "%s...", nil`, good, found, err, good)
- }
- if runtime.GOOS == "windows" {
- good = dir + `\execabs-test`
- if found, err := LookPath(good); err != nil || !strings.HasPrefix(found, good) {
- t.Fatalf(`LookPath(%#q) = %#q, %v, want "%s...", nil`, good, found, err, good)
- }
- }
+ for _, errdot := range []string{"1", "0"} {
+ t.Run("GODEBUG=execerrdot="+errdot, func(t *testing.T) {
+ t.Setenv("GODEBUG", "execerrdot="+errdot)
+ for _, dir := range []string{".", "../testdir"} {
+ t.Run(pathVar+"="+dir, func(t *testing.T) {
+ t.Setenv(pathVar, dir+string(filepath.ListSeparator)+origPath)
+ good := dir + "/execabs-test"
+ if found, err := LookPath(good); err != nil || !strings.HasPrefix(found, good) {
+ t.Fatalf(`LookPath(%#q) = %#q, %v, want "%s...", nil`, good, found, err, good)
+ }
+ if runtime.GOOS == "windows" {
+ good = dir + `\execabs-test`
+ if found, err := LookPath(good); err != nil || !strings.HasPrefix(found, good) {
+ t.Fatalf(`LookPath(%#q) = %#q, %v, want "%s...", nil`, good, found, err, good)
+ }
+ }
- if _, err := LookPath("execabs-test"); err == nil {
- t.Fatalf("LookPath didn't fail when finding a non-relative path")
- } else if !errors.Is(err, ErrDot) {
- t.Fatalf("LookPath returned unexpected error: want Is ErrDot, got %q", err)
- }
+ _, err := LookPath("execabs-test")
+ if errdot == "1" {
+ if err == nil {
+ t.Fatalf("LookPath didn't fail when finding a non-relative path")
+ } else if !errors.Is(err, ErrDot) {
+ t.Fatalf("LookPath returned unexpected error: want Is ErrDot, got %q", err)
+ }
+ } else {
+ if err != nil {
+ t.Fatalf("LookPath failed unexpectedly: %v", err)
+ }
+ }
- cmd := Command("execabs-test")
- if cmd.Err == nil {
- t.Fatalf("Command didn't fail when finding a non-relative path")
- } else if !errors.Is(cmd.Err, ErrDot) {
- t.Fatalf("Command returned unexpected error: want Is ErrDot, got %q", cmd.Err)
- }
- cmd.Err = nil
+ cmd := Command("execabs-test")
+ if errdot == "1" {
+ if cmd.Err == nil {
+ t.Fatalf("Command didn't fail when finding a non-relative path")
+ } else if !errors.Is(cmd.Err, ErrDot) {
+ t.Fatalf("Command returned unexpected error: want Is ErrDot, got %q", cmd.Err)
+ }
+ cmd.Err = nil
+ } else {
+ if cmd.Err != nil {
+ t.Fatalf("Command failed unexpectedly: %v", err)
+ }
+ }
- // Clearing cmd.Err should let the execution proceed,
- // and it should fail because it's not a valid binary.
- if err := cmd.Run(); err == nil {
- t.Fatalf("Run did not fail: expected exec error")
- } else if errors.Is(err, ErrDot) {
- t.Fatalf("Run returned unexpected error ErrDot: want error like ENOEXEC: %q", err)
+ // Clearing cmd.Err should let the execution proceed,
+ // and it should fail because it's not a valid binary.
+ if err := cmd.Run(); err == nil {
+ t.Fatalf("Run did not fail: expected exec error")
+ } else if errors.Is(err, ErrDot) {
+ t.Fatalf("Run returned unexpected error ErrDot: want error like ENOEXEC: %q", err)
+ }
+ })
}
})
}