diff options
| author | Michael Shields <mshields@google.com> | 2011-09-16 20:30:54 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2011-09-16 20:30:54 -0700 |
| commit | 44f12eb5ad7c08b8303ec2ab2f7013b675d725fa (patch) | |
| tree | 9acdd113be9291c8151353c0c85b47b396d90f6b /src/pkg/path/filepath | |
| parent | 46eb718c99355315f7a26de4745b95eac8a54081 (diff) | |
| download | go-44f12eb5ad7c08b8303ec2ab2f7013b675d725fa.tar.xz | |
filepath: fix Glob to return no error on nonmatching patterns
filepath.Glob is documented to return nil if no files match
and an error only if the pattern is invalid. This change
fixes it to work as documented and adds a regression test.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5040045
Diffstat (limited to 'src/pkg/path/filepath')
| -rw-r--r-- | src/pkg/path/filepath/match.go | 2 | ||||
| -rw-r--r-- | src/pkg/path/filepath/match_test.go | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/pkg/path/filepath/match.go b/src/pkg/path/filepath/match.go index 7fcc214c05..0ccc87e656 100644 --- a/src/pkg/path/filepath/match.go +++ b/src/pkg/path/filepath/match.go @@ -215,7 +215,7 @@ func getEsc(chunk string) (r int, nchunk string, err os.Error) { func Glob(pattern string) (matches []string, err os.Error) { if !hasMeta(pattern) { if _, err = os.Stat(pattern); err != nil { - return + return nil, nil } return []string{pattern}, nil } diff --git a/src/pkg/path/filepath/match_test.go b/src/pkg/path/filepath/match_test.go index a1c8333f37..711e835fb7 100644 --- a/src/pkg/path/filepath/match_test.go +++ b/src/pkg/path/filepath/match_test.go @@ -124,6 +124,16 @@ func TestGlob(t *testing.T) { t.Errorf("Glob(%#q) = %#v want %v", tt.pattern, matches, tt.result) } } + for _, pattern := range []string{"no_match", "../*/no_match"} { + matches, err := Glob(pattern) + if err != nil { + t.Errorf("Glob error for %q: %s", pattern, err) + continue + } + if len(matches) != 0 { + t.Errorf("Glob(%#q) = %#v want []", pattern, matches) + } + } } func TestGlobError(t *testing.T) { |
