]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add a test that reproduces an unstable 'go mod tidy'
authorBryan C. Mills <bcmills@google.com>
Fri, 19 May 2023 20:01:02 +0000 (16:01 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 22 May 2023 21:02:28 +0000 (21:02 +0000)
For #60313.

Change-Id: I76e48f52341e9962de9b809741a677d61baae6a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/496518
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

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

diff --git a/src/cmd/go/testdata/script/mod_tidy_issue60313.txt b/src/cmd/go/testdata/script/mod_tidy_issue60313.txt
new file mode 100644 (file)
index 0000000..1ae2c13
--- /dev/null
@@ -0,0 +1,76 @@
+# Regression test for https://go.dev/issue/60313: 'go mod tidy' did not preserve
+# dependencies needed to prevent 'ambiguous import' errors in external test
+# dependencies.
+
+go mod tidy
+cp go.mod tidy1.mod
+
+! go mod tidy  # BUG: This should succeed and leave go.mod unchanged.
+       # cmp go.mod tidy1.mod
+stderr 'ambiguous import'
+
+-- go.mod --
+module example
+
+go 1.21
+
+require (
+       example.net/a v0.1.0
+       example.net/b v0.1.0
+)
+
+require example.net/outer/inner v0.1.0 // indirect
+
+replace (
+       example.net/a v0.1.0 => ./a
+       example.net/b v0.1.0 => ./b
+       example.net/outer v0.1.0 => ./outer1
+       example.net/outer/inner v0.1.0 => ./inner
+)
+-- example.go --
+package example
+
+import (
+       _ "example.net/a"
+       _ "example.net/b"
+)
+-- a/go.mod --
+module example.net/a
+
+go 1.21
+
+require example.net/outer/inner v0.1.0
+-- a/a.go --
+package a
+-- a/a_test.go --
+package a_test
+
+import _ "example.net/outer/inner"
+-- b/go.mod --
+module example.net/b
+
+go 1.21
+
+require example.net/outer v0.1.0
+-- b/b.go --
+package b
+-- b/b_test.go --
+package b_test
+
+import _ "example.net/outer/inner"
+-- inner/go.mod --
+module example.net/outer/inner
+
+go 1.21
+-- inner/inner.go --
+package inner
+-- outer1/go.mod --
+module example.net/outer
+
+go 1.21
+-- outer1/inner/inner.go --
+package inner
+-- outer2/go.mod --
+module example.net/outer
+
+go 1.21