Merge pull request #77 from ghouscht/issue-76

fix pkger error if a project contains a .go directory #76
This commit is contained in:
Mark Bates 2020-03-04 09:55:04 -05:00 committed by GitHub
commit 5b8abbabca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -108,9 +108,12 @@ func (p *Parser) ParseDir(abs string, mode parser.Mode) ([]*ParsedSource, error)
return nil, fmt.Errorf("%s: here.Parse failed %s", err, abs)
}
fset := token.NewFileSet()
filter := func(f os.FileInfo) bool {
return !f.IsDir()
}
pkgs, err := parser.ParseDir(fset, abs, nil, 0)
fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, abs, filter, 0)
if err != nil {
return nil, fmt.Errorf("%s: ParseDir failed %s", err, abs)
}

View File

@ -71,6 +71,27 @@ func Test_Parser_Ref_Include(t *testing.T) {
r.Equal(26, l)
}
func Test_Parser_dotGo_Directory(t *testing.T) {
r := require.New(t)
ref, err := pkgtest.NewRef()
r.NoError(err)
defer os.RemoveAll(ref.Dir)
err = os.Mkdir(filepath.Join(ref.Dir, ".go"), 0755)
r.NoError(err)
disk, err := stdos.New(ref.Info)
r.NoError(err)
_, err = pkgtest.LoadFiles("/", ref, disk)
r.NoError(err)
res, err := Parse(ref.Info)
r.NoError(err)
r.Equal(11, len(res))
}
func Test_Parser_Example_HTTP(t *testing.T) {
r := require.New(t)