diff --git a/.gitignore b/.gitignore index 76d92ba..af212ec 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ _testmain.go *.exe *.test *.prof + +# test directory +test/ diff --git a/doublestar_test.go b/doublestar_test.go index bc3502e..85b1877 100644 --- a/doublestar_test.go +++ b/doublestar_test.go @@ -3,6 +3,7 @@ package doublestar import ( + "log" "os" "path" "path/filepath" @@ -268,3 +269,70 @@ func compareSlices(a, b []string) bool { return len(diff) == 0 } + +func mkdirp(parts ...string) { + dirs := path.Join(parts...) + err := os.MkdirAll(dirs, 0755) + if err != nil { + log.Fatalf("Could not create test directories %v: %v\n", dirs, err) + } +} + +func touch(parts ...string) { + filename := path.Join(parts...) + f, err := os.Create(filename) + if err != nil { + log.Fatalf("Could not create test file %v: %v\n", filename, err) + } + f.Close() +} + +func symlink(oldname, newname string) { + // since this will only run on non-windows, we can assume "/" as path separator + err := os.Symlink(oldname, newname) + if err != nil && !os.IsExist(err) { + log.Fatalf("Could not create symlink %v -> %v: %v\n", oldname, newname, err) + } +} + +func TestMain(m *testing.M) { + // create the test directory + mkdirp("test", "a", "b", "c") + mkdirp("test", "a", "c") + mkdirp("test", "abc") + mkdirp("test", "axbxcxdxe", "xxx") + mkdirp("test", "axbxcxdxexxx") + mkdirp("test", "b") + + // create test files + touch("test", "a", "abc") + touch("test", "a", "b", "c", "d") + touch("test", "a", "c", "b") + touch("test", "abc", "b") + touch("test", "abcd") + touch("test", "abcde") + touch("test", "abxbbxdbxebxczzx") + touch("test", "abxbbxdbxebxczzy") + touch("test", "axbxcxdxe", "f") + touch("test", "axbxcxdxe", "xxx", "f") + touch("test", "axbxcxdxexxx", "f") + touch("test", "axbxcxdxexxx", "fff") + touch("test", "a☺b") + touch("test", "b", "c") + touch("test", "c") + touch("test", "x") + touch("test", "xxx") + touch("test", "z") + touch("test", "α") + + if !onWindows { + // these files/symlinks won't work on Windows + touch("test", "-") + touch("test", "]") + symlink("../axbxcxdxe/", "test/b/symlink-dir") + symlink("/tmp/nonexistant-file-20160902155705", "test/broken-symlink") + symlink("a/b", "test/working-symlink") + } + + os.Exit(m.Run()) +} diff --git a/go.mod b/go.mod index 1d0378b..ce1688f 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,3 @@ module github.com/bmatcuk/doublestar + +go 1.12 diff --git a/test/- b/test/- deleted file mode 100644 index e69de29..0000000 diff --git a/test/README.md b/test/README.md deleted file mode 100644 index 7312628..0000000 --- a/test/README.md +++ /dev/null @@ -1 +0,0 @@ -This directory and associated subdirectories and files are for testing the Glob() function. diff --git a/test/] b/test/] deleted file mode 100644 index e69de29..0000000 diff --git a/test/a/abc b/test/a/abc deleted file mode 100644 index e69de29..0000000 diff --git a/test/a/b/c/d b/test/a/b/c/d deleted file mode 100644 index e69de29..0000000 diff --git a/test/a/c/b b/test/a/c/b deleted file mode 100644 index e69de29..0000000 diff --git a/test/abc/b b/test/abc/b deleted file mode 100644 index e69de29..0000000 diff --git a/test/abcd b/test/abcd deleted file mode 100644 index e69de29..0000000 diff --git a/test/abcde b/test/abcde deleted file mode 100644 index e69de29..0000000 diff --git a/test/abxbbxdbxebxczzx b/test/abxbbxdbxebxczzx deleted file mode 100644 index e69de29..0000000 diff --git a/test/abxbbxdbxebxczzy b/test/abxbbxdbxebxczzy deleted file mode 100644 index e69de29..0000000 diff --git a/test/axbxcxdxe/f b/test/axbxcxdxe/f deleted file mode 100644 index e69de29..0000000 diff --git a/test/axbxcxdxe/xxx/f b/test/axbxcxdxe/xxx/f deleted file mode 100644 index e69de29..0000000 diff --git a/test/axbxcxdxexxx/f b/test/axbxcxdxexxx/f deleted file mode 100644 index e69de29..0000000 diff --git a/test/axbxcxdxexxx/fff b/test/axbxcxdxexxx/fff deleted file mode 100644 index e69de29..0000000 diff --git "a/test/a\342\230\272b" "b/test/a\342\230\272b" deleted file mode 100644 index e69de29..0000000 diff --git a/test/b/c b/test/b/c deleted file mode 100644 index e69de29..0000000 diff --git a/test/b/symlink-dir b/test/b/symlink-dir deleted file mode 120000 index 4a07501..0000000 --- a/test/b/symlink-dir +++ /dev/null @@ -1 +0,0 @@ -../axbxcxdxe/ \ No newline at end of file diff --git a/test/broken-symlink b/test/broken-symlink deleted file mode 120000 index 0b8ae1d..0000000 --- a/test/broken-symlink +++ /dev/null @@ -1 +0,0 @@ -/tmp/nonexistant-file-20160902155705 \ No newline at end of file diff --git a/test/c b/test/c deleted file mode 100644 index e69de29..0000000 diff --git a/test/go.mod b/test/go.mod deleted file mode 100644 index e69de29..0000000 diff --git a/test/working-symlink b/test/working-symlink deleted file mode 120000 index db89c97..0000000 --- a/test/working-symlink +++ /dev/null @@ -1 +0,0 @@ -a/b \ No newline at end of file diff --git a/test/x b/test/x deleted file mode 100644 index e69de29..0000000 diff --git a/test/xxx b/test/xxx deleted file mode 100644 index e69de29..0000000 diff --git a/test/z b/test/z deleted file mode 100644 index e69de29..0000000 diff --git "a/test/\316\261" "b/test/\316\261" deleted file mode 100644 index e69de29..0000000