diff --git a/main.go b/main.go index 5396fa4..824a3f2 100644 --- a/main.go +++ b/main.go @@ -972,6 +972,14 @@ func processImportCfg(flags []string) (newImportCfg string, _ error) { impPath, pkgfile := pair[0], pair[1] lpkg, err := listPackage(impPath) if err != nil { + // TODO: it's unclear why an importcfg can include an import path + // that's not a dependency in an edge case with "go test ./...". + // See exporttest/*.go in testdata/scripts/test.txt. + // For now, spot the pattern and avoid the unnecessary error; + // the dependency is unused, so the packagefile line is redundant. + if strings.HasSuffix(curPkg.ImportPath, ".test]") && strings.HasPrefix(curPkg.ImportPath, impPath) { + continue + } panic(err) // shouldn't happen } if lpkg.Name != "main" { diff --git a/testdata/scripts/test.txt b/testdata/scripts/test.txt index 2fb7f4b..ea87019 100644 --- a/testdata/scripts/test.txt +++ b/testdata/scripts/test.txt @@ -14,9 +14,18 @@ stdout 'package bar_test, func name:' [short] stop # no need to verify this with -short -# also check that many packages test fine, including a main package and multiple -# test packages -garble test -v . ./somemain ./sometest +# Also check that many packages test fine, including a main package and multiple +# test packages. +# +# Exporttest is special, as it: +# +# * uses an external test package +# * exports unexported APIs via export_test.go +# * is imported by another package, also tested via "./..." +# +# The combination of those used to result in "refusing to list non-dependency +# package" errors, which we've currently worked around. +garble test -v ./... stdout 'ok\s+test/bar\s' stdout 'PASS.*TestFoo' stdout 'PASS.*TestSeparateFoo' @@ -26,6 +35,7 @@ stdout 'package bar_test, func name:' ! stdout 'OriginalFuncName' stdout '\?\s+test/bar/somemain\s' stdout 'ok\s+test/bar/sometest\s' +stdout 'ok\s+test/bar/exporttest\s' # verify that non-build flags are kept garble test -withflag -v @@ -47,6 +57,8 @@ package bar import "runtime" +import _ "test/bar/exporttest" + func LocalFoo() string { return "Foo" } var ImportedVar = "imported var value" @@ -115,3 +127,17 @@ package sometest import "testing" func TestFoo(t *testing.T) {} +-- exporttest/foo.go -- +package exporttest + +type foo int +-- exporttest/export_test.go -- +package exporttest + +type Foo = foo +-- exporttest/foo_test.go -- +package exporttest_test + +import "testing" + +func TestFoo(t *testing.T) {}