]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix a portability issue in the cd script command
authorManlio Perillo <manlio.perillo@gmail.com>
Thu, 13 May 2021 14:08:59 +0000 (16:08 +0200)
committerBryan C. Mills <bcmills@google.com>
Fri, 14 May 2021 15:35:28 +0000 (15:35 +0000)
Currently all script tests use the UNIX path separator with the cd
command, causing the PWD environment variable to have the incorrect path
separator on Windows.

Call filepath.FromSlash on the cd command argument.
Update the testdata/script/README to document that the cd argument must
use slashes.

Add a regression test.

To reproduce this issue, a test must use the cd command followed by a
stdout or stderr command containing the pattern $PWD.

Change-Id: Ib2dc5f185cc2476451402787996d14df91f7dddb
Reviewed-on: https://go-review.googlesource.com/c/go/+/319311
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/go/script_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/test_script_cmdcd.txt [new file with mode: 0644]

index 327eaff44501b0451ff76567ddac712ba766e7e8..639e907db075159dd5aba227d38e7ec9261127bf 100644 (file)
@@ -517,7 +517,7 @@ func (ts *testScript) cmdCd(want simpleStatus, args []string) {
                ts.fatalf("usage: cd dir")
        }
 
-       dir := args[0]
+       dir := filepath.FromSlash(args[0])
        if !filepath.IsAbs(dir) {
                dir = filepath.Join(ts.cd, dir)
        }
index d7e67bb7b60c2566d00b67628d6987decc871b6c..48e4055b0bdb971397be7dd2b0b909205a46a588 100644 (file)
@@ -102,6 +102,7 @@ The commands are:
 
 - cd dir
   Change to the given directory for future commands.
+  The directory must use slashes as path separator.
 
 - chmod perm path...
   Change the permissions of the files or directories named by the path arguments
diff --git a/src/cmd/go/testdata/script/test_script_cmdcd.txt b/src/cmd/go/testdata/script/test_script_cmdcd.txt
new file mode 100644 (file)
index 0000000..6e6f67e
--- /dev/null
@@ -0,0 +1,13 @@
+# Tests that after a cd command, where usually the UNIX path separator is used,
+# a match against $PWD does not fail on Windows.
+
+cd $WORK/a/b/c/pkg
+
+go list -find -f {{.Root}}
+stdout $PWD
+
+-- $WORK/a/b/c/pkg/go.mod --
+module pkg
+
+-- $WORK/a/b/c/pkg/pkg.go --
+package pkg