// containing no buildable Go source files. (It may still contain
// test files, files hidden by build tags, and so on.)
type NoGoError struct {
- Dir string
+ Dir string
+ Ignored bool // whether any Go files were ignored due to build tags
}
func (e *NoGoError) Error() string {
- return "no buildable Go source files in " + e.Dir
+ msg := "no buildable Go source files in " + e.Dir
+ if e.Ignored {
+ msg += " (.go files ignored due to build tags)"
+ }
+ return msg
}
// MultiplePackageError describes a directory containing
return p, badGoError
}
if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
- return p, &NoGoError{p.Dir}
+ return p, &NoGoError{Dir: p.Dir, Ignored: len(p.IgnoredGoFiles) > 0}
}
for tag := range allTags {
}
}
+func TestIgnoredGoFilesImport(t *testing.T) {
+ _, err := Import(".", "testdata/ignored", 0)
+ e, ok := err.(*NoGoError)
+ if !ok {
+ t.Fatal(`Import("testdata/ignored") did not return NoGoError.`)
+ }
+ if !e.Ignored {
+ t.Fatal(`Import("testdata/ignored") should have ignored Go files.`)
+ }
+}
+
func TestMultiplePackageImport(t *testing.T) {
_, err := Import(".", "testdata/multi", 0)
mpe, ok := err.(*MultiplePackageError)