Skip to content

Commit

Permalink
Improve tests to fail when no packages / source is found
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed May 29, 2022
1 parent e0c1e01 commit cd0f424
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 6 additions & 1 deletion decorator/restorer_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ func testPackageRestoresCorrectlyWithApplyClone(t *testing.T, path ...string) {
if err != nil {
t.Fatal(err)
}
if len(pkgs) == 0 {
t.Fatal("No packages loaded")
}
for _, p := range pkgs {

if len(p.Syntax) == 0 {
t.Fatalf("Package %s has no syntax", p.PkgPath)
}
t.Run(p.PkgPath, func(t *testing.T) {

r := NewRestorer()
Expand Down
7 changes: 6 additions & 1 deletion decorator/restorer_clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ func testPackageRestoresCorrectlyWithClone(t *testing.T, path ...string) {
if err != nil {
t.Fatal(err)
}
if len(pkgs) == 0 {
t.Fatal("No packages loaded")
}
for _, p := range pkgs {

if len(p.Syntax) == 0 {
t.Fatalf("Package %s has no syntax", p.PkgPath)
}
t.Run(p.PkgPath, func(t *testing.T) {

// must use go/build package resolver for standard library because of https://github.com/golang/go/issues/26924
Expand Down
16 changes: 15 additions & 1 deletion decorator/restorer_std_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ func testPackageRestoresCorrectlyWithImports(t *testing.T, path ...string) {
if err != nil {
t.Fatal(err)
}
if len(pkgs) == 0 {
t.Fatal("No packages loaded")
}
// we skip some packages because they have no source:
skip := map[string]bool{
"unsafe": true,
"embed/internal/embedtest": true,
"os/signal/internal/pty": true,
}
for _, p := range pkgs {

if skip[p.PkgPath] {
continue
}
if len(p.Syntax) == 0 {
t.Fatalf("Package %s has no syntax", p.PkgPath)
}
t.Run(p.PkgPath, func(t *testing.T) {

// must use go/build package resolver for standard library because of https://github.com/golang/go/issues/26924
Expand Down

0 comments on commit cd0f424

Please sign in to comment.