Skip to content

Commit 8fa2b6d

Browse files
committed
cmd/go: convert TestShadowingLogic to the script framework
Part of converting all tests to script framework to improve test parallelism. Updates #36320 Updates #17751 Change-Id: I6db652a4a515daf6e87645d34191dc9a441f5720 Reviewed-on: https://go-review.googlesource.com/c/go/+/214431 Reviewed-by: Bryan C. Mills <[email protected]>
1 parent c4c73ce commit 8fa2b6d

File tree

5 files changed

+25
-48
lines changed

5 files changed

+25
-48
lines changed

src/cmd/go/go_test.go

-45
Original file line numberDiff line numberDiff line change
@@ -1639,51 +1639,6 @@ func TestSymlinkWarning(t *testing.T) {
16391639
tg.grepStderr("ignoring symlink", "list should have reported symlink")
16401640
}
16411641

1642-
func TestShadowingLogic(t *testing.T) {
1643-
skipIfGccgo(t, "gccgo has no standard packages")
1644-
tg := testgo(t)
1645-
defer tg.cleanup()
1646-
pwd := tg.pwd()
1647-
sep := string(filepath.ListSeparator)
1648-
tg.setenv("GOPATH", filepath.Join(pwd, "testdata", "shadow", "root1")+sep+filepath.Join(pwd, "testdata", "shadow", "root2"))
1649-
1650-
// The math in root1 is not "math" because the standard math is.
1651-
tg.run("list", "-f", "({{.ImportPath}}) ({{.ConflictDir}})", "./testdata/shadow/root1/src/math")
1652-
pwdForwardSlash := strings.ReplaceAll(pwd, string(os.PathSeparator), "/")
1653-
if !strings.HasPrefix(pwdForwardSlash, "/") {
1654-
pwdForwardSlash = "/" + pwdForwardSlash
1655-
}
1656-
// The output will have makeImportValid applies, but we only
1657-
// bother to deal with characters we might reasonably see.
1658-
for _, r := range " :" {
1659-
pwdForwardSlash = strings.ReplaceAll(pwdForwardSlash, string(r), "_")
1660-
}
1661-
want := "(_" + pwdForwardSlash + "/testdata/shadow/root1/src/math) (" + filepath.Join(runtime.GOROOT(), "src", "math") + ")"
1662-
if strings.TrimSpace(tg.getStdout()) != want {
1663-
t.Error("shadowed math is not shadowed; looking for", want)
1664-
}
1665-
1666-
// The foo in root1 is "foo".
1667-
tg.run("list", "-f", "({{.ImportPath}}) ({{.ConflictDir}})", "./testdata/shadow/root1/src/foo")
1668-
if strings.TrimSpace(tg.getStdout()) != "(foo) ()" {
1669-
t.Error("unshadowed foo is shadowed")
1670-
}
1671-
1672-
// The foo in root2 is not "foo" because the foo in root1 got there first.
1673-
tg.run("list", "-f", "({{.ImportPath}}) ({{.ConflictDir}})", "./testdata/shadow/root2/src/foo")
1674-
want = "(_" + pwdForwardSlash + "/testdata/shadow/root2/src/foo) (" + filepath.Join(pwd, "testdata", "shadow", "root1", "src", "foo") + ")"
1675-
if strings.TrimSpace(tg.getStdout()) != want {
1676-
t.Error("shadowed foo is not shadowed; looking for", want)
1677-
}
1678-
1679-
// The error for go install should mention the conflicting directory.
1680-
tg.runFail("install", "./testdata/shadow/root2/src/foo")
1681-
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")
1682-
if strings.TrimSpace(tg.getStderr()) != want {
1683-
t.Error("wrong shadowed install error; looking for", want)
1684-
}
1685-
}
1686-
16871642
func TestCgoDependsOnSyscall(t *testing.T) {
16881643
if testing.Short() {
16891644
t.Skip("skipping test that removes $GOROOT/pkg/*_race in short mode")
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
env GO111MODULE=off
2+
env GOPATH=$WORK/gopath/src/shadow/root1${:}$WORK/gopath/src/shadow/root2
3+
4+
# The math in root1 is not "math" because the standard math is.
5+
go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root1/src/math
6+
stdout '^\(.*(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)math\) \('$GOROOT'(\\|/)?src(\\|/)math\)$'
7+
8+
# The foo in root1 is "foo".
9+
go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root1/src/foo
10+
stdout '^\(foo\) \(\)$'
11+
12+
# The foo in root2 is not "foo" because the foo in root1 got there first.
13+
go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root2/src/foo
14+
stdout '^\(.*gopath(\\|/)src(\\|/)shadow(\\|/)root2(\\|/)src(\\|/)foo\) \('$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)foo\)$'
15+
16+
# The error for go install should mention the conflicting directory.
17+
! go install -n ./shadow/root2/src/foo
18+
stderr 'go install: no install location for '$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root2(\\|/)src(\\|/)foo: hidden by '$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)foo'
19+
20+
-- shadow/root1/src/foo/foo.go --
21+
package foo
22+
-- shadow/root1/src/math/math.go --
23+
package math
24+
-- shadow/root2/src/foo/foo.go --
25+
package foo

src/cmd/go/testdata/shadow/root1/src/foo/foo.go

-1
This file was deleted.

src/cmd/go/testdata/shadow/root1/src/math/math.go

-1
This file was deleted.

src/cmd/go/testdata/shadow/root2/src/foo/foo.go

-1
This file was deleted.

0 commit comments

Comments
 (0)