Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Add test, fixture for listing missing packages
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed Jul 7, 2016
1 parent 3d88312 commit ff3062f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
14 changes: 14 additions & 0 deletions _testdata/src/missing/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package simple

import (
"sort"

"github.com/sdboyer/vsolver"
"simple/missing"
)

var (
_ = sort.Strings
_ = vsolver.Solve
_ = missing.Foo
)
12 changes: 12 additions & 0 deletions _testdata/src/missing/m1p/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package m1p

import (
"sort"

"github.com/sdboyer/vsolver"
)

var (
_ = sort.Strings
_ = vsolver.Solve
)
11 changes: 11 additions & 0 deletions _testdata/src/missing/m1p/b.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package m1p

import (
"os"
"sort"
)

var (
_ = sort.Strings
_ = os.PathSeparator
)
38 changes: 36 additions & 2 deletions analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit ff3062f

Please sign in to comment.