Fix for empty directory, assume "."

pull/53/head
rwxrob 2 years ago
parent 961b197203
commit 2cb365f0fa
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -7,6 +7,9 @@ import (
)
func Files(dir string) []string {
if dir == "" {
dir = "."
}
files := []string{}
finfo, _ := os.ReadDir(dir)
for _, f := range finfo {

@ -1,6 +1,8 @@
package util_test
import (
"os"
"github.com/rwxrob/bonzai/filter"
"github.com/rwxrob/bonzai/util"
)
@ -15,6 +17,18 @@ func ExampleFiles() {
// some
}
func ExampleFiles_empty() {
os.Chdir("testdata/files")
defer os.Chdir("../..")
filter.Println(util.Files(""))
// Output:
// bar
// blah
// foo
// other
// some
}
func ExampleFilesWith() {
filter.Println(util.FilesWith("testdata/files", "b"))
// Output:

Loading…
Cancel
Save