mirror of
https://github.com/golang/go
synced 2024-11-26 18:06:55 -07:00
go/parser: ignore subdirectories in ParseDir
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
30ba798093
commit
be59d85fe2
@ -140,7 +140,7 @@ func ParseDir(fset *token.FileSet, path string, filter func(fs.FileInfo) bool, m
|
||||
|
||||
pkgs = make(map[string]*ast.Package)
|
||||
for _, d := range list {
|
||||
if strings.HasSuffix(d.Name(), ".go") && (filter == nil || filter(d)) {
|
||||
if !d.IsDir() && strings.HasSuffix(d.Name(), ".go") && (filter == nil || filter(d)) {
|
||||
filename := filepath.Join(path, d.Name())
|
||||
if src, err := ParseFile(fset, filename, nil, mode); err == nil {
|
||||
name := src.Name.Name
|
||||
|
@ -82,6 +82,14 @@ func TestParseDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue42951(t *testing.T) {
|
||||
path := "./testdata/issue42951"
|
||||
_, err := ParseDir(token.NewFileSet(), path, nil, 0)
|
||||
if err != nil {
|
||||
t.Errorf("ParseDir(%s): %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseExpr(t *testing.T) {
|
||||
// just kicking the tires:
|
||||
// a valid arithmetic expression
|
||||
|
1
src/go/parser/testdata/issue42951/not_a_file.go/invalid.go
vendored
Normal file
1
src/go/parser/testdata/issue42951/not_a_file.go/invalid.go
vendored
Normal file
@ -0,0 +1 @@
|
||||
This file should not be parsed by ParseDir.
|
Loading…
Reference in New Issue
Block a user