diff --git a/_testdata/src/missing/a.go b/_testdata/src/missing/a.go new file mode 100644 index 0000000000..df1be3c50d --- /dev/null +++ b/_testdata/src/missing/a.go @@ -0,0 +1,14 @@ +package simple + +import ( + "sort" + + "github.com/sdboyer/vsolver" + "simple/missing" +) + +var ( + _ = sort.Strings + _ = vsolver.Solve + _ = missing.Foo +) diff --git a/_testdata/src/missing/m1p/a.go b/_testdata/src/missing/m1p/a.go new file mode 100644 index 0000000000..cf8d759f93 --- /dev/null +++ b/_testdata/src/missing/m1p/a.go @@ -0,0 +1,12 @@ +package m1p + +import ( + "sort" + + "github.com/sdboyer/vsolver" +) + +var ( + _ = sort.Strings + _ = vsolver.Solve +) diff --git a/_testdata/src/missing/m1p/b.go b/_testdata/src/missing/m1p/b.go new file mode 100644 index 0000000000..83674b9778 --- /dev/null +++ b/_testdata/src/missing/m1p/b.go @@ -0,0 +1,11 @@ +package m1p + +import ( + "os" + "sort" +) + +var ( + _ = sort.Strings + _ = os.PathSeparator +) diff --git a/analysis_test.go b/analysis_test.go index 4ca25f5d5c..23bfc9704c 100644 --- a/analysis_test.go +++ b/analysis_test.go @@ -557,6 +557,40 @@ func TestListPackages(t *testing.T) { }, }, }, + // imports a missing pkg + "missing import": { + fileRoot: j("missing"), + importRoot: "missing", + out: PackageTree{ + ImportRoot: "missing", + Packages: map[string]PackageOrErr{ + "missing": { + P: Package{ + ImportPath: "missing", + CommentPath: "", + Name: "simple", + Imports: []string{ + "github.com/sdboyer/vsolver", + "simple/missing", + "sort", + }, + }, + }, + "missing/m1p": { + P: Package{ + ImportPath: "missing/m1p", + CommentPath: "", + Name: "m1p", + Imports: []string{ + "github.com/sdboyer/vsolver", + "os", + "sort", + }, + }, + }, + }, + }, + }, // This case mostly exists for the PackageTree methods, but it does // cover a bit of range "varied": { @@ -678,7 +712,7 @@ func TestListPackages(t *testing.T) { for path, perr := range fix.out.Packages { seen[path] = true if operr, exists := out.Packages[path]; !exists { - t.Errorf("listPackages(%q): Expected PackageOrErr for path %s was missing from output:\n\t%s", path, perr) + t.Errorf("listPackages(%q): Expected PackageOrErr for path %s was missing from output:\n\t%s", name, path, perr) } else { if !reflect.DeepEqual(perr, operr) { t.Errorf("listPackages(%q): PkgOrErr for path %s was not as expected:\n\t(GOT): %s\n\t(WNT): %s", name, path, operr, perr) @@ -691,7 +725,7 @@ func TestListPackages(t *testing.T) { continue } - t.Errorf("listPackages(%q): Got PackageOrErr for path %s, but none was expected:\n\t%s", path, operr) + t.Errorf("listPackages(%q): Got PackageOrErr for path %s, but none was expected:\n\t%s", name, path, operr) } } }