]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: allow a package that ends with _test having an internal test package
authorRyan Leung <rleungx@gmail.com>
Mon, 22 Nov 2021 02:41:07 +0000 (02:41 +0000)
committerBryan C. Mills <bcmills@google.com>
Mon, 22 Nov 2021 22:35:55 +0000 (22:35 +0000)
Fixes #45477

Change-Id: I2f1ed281515ec40d31fd07ce9f4901777691bfa7
GitHub-Last-Rev: 7894d9400c95b8d84efe88f401fa75c3dd01921a
GitHub-Pull-Request: golang/go#49673
Reviewed-on: https://go-review.googlesource.com/c/go/+/365534
Trust: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

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

diff --git a/src/cmd/go/testdata/script/test_issue45477.txt b/src/cmd/go/testdata/script/test_issue45477.txt
new file mode 100644 (file)
index 0000000..f435b6a
--- /dev/null
@@ -0,0 +1,12 @@
+[short] skip  # links and runs a test binary
+
+go test -v .
+
+-- go.mod --
+module example.com/pkg_test
+
+-- pkg.go --
+package pkg_test
+
+-- pkg_test.go --
+package pkg_test
index eb47ffe2859c4fa84a905cdfe6afb70c93e473fc..6f7260b78f37ca490a01892123397ba9f626a63c 100644 (file)
@@ -894,7 +894,7 @@ Found:
 
                isTest := strings.HasSuffix(name, "_test.go")
                isXTest := false
-               if isTest && strings.HasSuffix(pkg, "_test") {
+               if isTest && strings.HasSuffix(pkg, "_test") && p.Name != pkg {
                        isXTest = true
                        pkg = pkg[:len(pkg)-len("_test")]
                }