From: Ryan Leung Date: Mon, 22 Nov 2021 02:41:07 +0000 (+0000) Subject: cmd/go: allow a package that ends with _test having an internal test package X-Git-Tag: go1.18beta1~209 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=11972353a67456d776cf891a9e46873e8a1fe630;p=gostls13.git cmd/go: allow a package that ends with _test having an internal test package 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 Reviewed-by: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot --- diff --git a/src/cmd/go/testdata/script/test_issue45477.txt b/src/cmd/go/testdata/script/test_issue45477.txt new file mode 100644 index 0000000000..f435b6a6f4 --- /dev/null +++ b/src/cmd/go/testdata/script/test_issue45477.txt @@ -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 diff --git a/src/go/build/build.go b/src/go/build/build.go index eb47ffe285..6f7260b78f 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -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")] }