]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "cmd/go: convert TestShadowingLogic to the script framework"
authorMichael Matloob <matloob@golang.org>
Thu, 20 Feb 2020 00:30:48 +0000 (00:30 +0000)
committerMichael Matloob <matloob@golang.org>
Thu, 20 Feb 2020 00:34:12 +0000 (00:34 +0000)
This reverts commit 8fa2b6dcde6008c107c097e44eb0ee94a2a8af3d.

Reason for revert: broke the build

Change-Id: Iae703b1b3dad6b363f57541641357eabca45e9e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/220217
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/list_shadow.txt [deleted file]
src/cmd/go/testdata/shadow/root1/src/foo/foo.go [new file with mode: 0644]
src/cmd/go/testdata/shadow/root1/src/math/math.go [new file with mode: 0644]
src/cmd/go/testdata/shadow/root2/src/foo/foo.go [new file with mode: 0644]

index 57c0c6580c7838dd1aa884db16325009210ee670..9da94360f9ffb9ff6287d0c9ca77ea29aff5b170 100644 (file)
@@ -1639,6 +1639,51 @@ func TestSymlinkWarning(t *testing.T) {
        tg.grepStderr("ignoring symlink", "list should have reported symlink")
 }
 
+func TestShadowingLogic(t *testing.T) {
+       skipIfGccgo(t, "gccgo has no standard packages")
+       tg := testgo(t)
+       defer tg.cleanup()
+       pwd := tg.pwd()
+       sep := string(filepath.ListSeparator)
+       tg.setenv("GOPATH", filepath.Join(pwd, "testdata", "shadow", "root1")+sep+filepath.Join(pwd, "testdata", "shadow", "root2"))
+
+       // The math in root1 is not "math" because the standard math is.
+       tg.run("list", "-f", "({{.ImportPath}}) ({{.ConflictDir}})", "./testdata/shadow/root1/src/math")
+       pwdForwardSlash := strings.ReplaceAll(pwd, string(os.PathSeparator), "/")
+       if !strings.HasPrefix(pwdForwardSlash, "/") {
+               pwdForwardSlash = "/" + pwdForwardSlash
+       }
+       // The output will have makeImportValid applies, but we only
+       // bother to deal with characters we might reasonably see.
+       for _, r := range " :" {
+               pwdForwardSlash = strings.ReplaceAll(pwdForwardSlash, string(r), "_")
+       }
+       want := "(_" + pwdForwardSlash + "/testdata/shadow/root1/src/math) (" + filepath.Join(runtime.GOROOT(), "src", "math") + ")"
+       if strings.TrimSpace(tg.getStdout()) != want {
+               t.Error("shadowed math is not shadowed; looking for", want)
+       }
+
+       // The foo in root1 is "foo".
+       tg.run("list", "-f", "({{.ImportPath}}) ({{.ConflictDir}})", "./testdata/shadow/root1/src/foo")
+       if strings.TrimSpace(tg.getStdout()) != "(foo) ()" {
+               t.Error("unshadowed foo is shadowed")
+       }
+
+       // The foo in root2 is not "foo" because the foo in root1 got there first.
+       tg.run("list", "-f", "({{.ImportPath}}) ({{.ConflictDir}})", "./testdata/shadow/root2/src/foo")
+       want = "(_" + pwdForwardSlash + "/testdata/shadow/root2/src/foo) (" + filepath.Join(pwd, "testdata", "shadow", "root1", "src", "foo") + ")"
+       if strings.TrimSpace(tg.getStdout()) != want {
+               t.Error("shadowed foo is not shadowed; looking for", want)
+       }
+
+       // The error for go install should mention the conflicting directory.
+       tg.runFail("install", "./testdata/shadow/root2/src/foo")
+       want = "go install: no install location for " + filepath.Join(pwd, "testdata", "shadow", "root2", "src", "foo") + ": hidden by " + filepath.Join(pwd, "testdata", "shadow", "root1", "src", "foo")
+       if strings.TrimSpace(tg.getStderr()) != want {
+               t.Error("wrong shadowed install error; looking for", want)
+       }
+}
+
 func TestCgoDependsOnSyscall(t *testing.T) {
        if testing.Short() {
                t.Skip("skipping test that removes $GOROOT/pkg/*_race in short mode")
diff --git a/src/cmd/go/testdata/script/list_shadow.txt b/src/cmd/go/testdata/script/list_shadow.txt
deleted file mode 100644 (file)
index 7b24d93..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-env GO111MODULE=off
-env GOPATH=$WORK/gopath/src/shadow/root1${:}$WORK/gopath/src/shadow/root2
-
-# The math in root1 is not "math" because the standard math is.
-go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root1/src/math
-stdout '^\(.*(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)math\) \('$GOROOT'(\\|/)?src(\\|/)math\)$'
-
-# The foo in root1 is "foo".
-go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root1/src/foo
-stdout '^\(foo\) \(\)$'
-
-# The foo in root2 is not "foo" because the foo in root1 got there first.
-go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root2/src/foo
-stdout '^\(.*gopath(\\|/)src(\\|/)shadow(\\|/)root2(\\|/)src(\\|/)foo\) \('$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)foo\)$'
-
-# The error for go install should mention the conflicting directory.
-! go install -n ./shadow/root2/src/foo
-stderr 'go install: no install location for '$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root2(\\|/)src(\\|/)foo: hidden by '$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)foo'
-
--- shadow/root1/src/foo/foo.go --
-package foo
--- shadow/root1/src/math/math.go --
-package math
--- shadow/root2/src/foo/foo.go --
-package foo
\ No newline at end of file
diff --git a/src/cmd/go/testdata/shadow/root1/src/foo/foo.go b/src/cmd/go/testdata/shadow/root1/src/foo/foo.go
new file mode 100644 (file)
index 0000000..f52652b
--- /dev/null
@@ -0,0 +1 @@
+package foo
diff --git a/src/cmd/go/testdata/shadow/root1/src/math/math.go b/src/cmd/go/testdata/shadow/root1/src/math/math.go
new file mode 100644 (file)
index 0000000..c91c24e
--- /dev/null
@@ -0,0 +1 @@
+package math
diff --git a/src/cmd/go/testdata/shadow/root2/src/foo/foo.go b/src/cmd/go/testdata/shadow/root2/src/foo/foo.go
new file mode 100644 (file)
index 0000000..f52652b
--- /dev/null
@@ -0,0 +1 @@
+package foo