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
}
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) {
}
// ParseTemplateGlob creates a set by parsing the files matched
-// by the pattern, each of which defines a single template. Each
+// by the pattern, each of which defines a single template. The pattern
+// is processed by filepath.Glob and must match at least one file. Each
// template will be named the base name of its file.
// Unlike with ParseGlob, each file should be a stand-alone template
// definition suitable for Template.Parse (not Set.Parse); that is, the
if err != nil {
return nil, err
}
+ if len(filenames) == 0 {
+ return nil, fmt.Errorf("pattern matches no files: %#q", pattern)
+ }
for _, filename := range filenames {
t, err := ParseFile(filename)
if err != nil {