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 00000000000..f435b6a6f43 --- /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 eb47ffe2859..6f7260b78f3 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")] }