Skip to content

Commit

Permalink
build test directory when tests run to make Windows happy
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatcuk committed Jul 6, 2019
1 parent a8e0502 commit eae5cbd
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ _testmain.go
*.exe
*.test
*.prof

# test directory
test/
68 changes: 68 additions & 0 deletions doublestar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package doublestar

import (
"log"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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())
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module github.com/bmatcuk/doublestar

go 1.12
Empty file removed test/-
Empty file.
1 change: 0 additions & 1 deletion test/README.md

This file was deleted.

Empty file removed test/]
Empty file.
Empty file removed test/a/abc
Empty file.
Empty file removed test/a/b/c/d
Empty file.
Empty file removed test/a/c/b
Empty file.
Empty file removed test/abc/b
Empty file.
Empty file removed test/abcd
Empty file.
Empty file removed test/abcde
Empty file.
Empty file removed test/abxbbxdbxebxczzx
Empty file.
Empty file removed test/abxbbxdbxebxczzy
Empty file.
Empty file removed test/axbxcxdxe/f
Empty file.
Empty file removed test/axbxcxdxe/xxx/f
Empty file.
Empty file removed test/axbxcxdxexxx/f
Empty file.
Empty file removed test/axbxcxdxexxx/fff
Empty file.
Empty file removed test/a☺b
Empty file.
Empty file removed test/b/c
Empty file.
1 change: 0 additions & 1 deletion test/b/symlink-dir

This file was deleted.

1 change: 0 additions & 1 deletion test/broken-symlink

This file was deleted.

Empty file removed test/c
Empty file.
Empty file removed test/go.mod
Empty file.
1 change: 0 additions & 1 deletion test/working-symlink

This file was deleted.

Empty file removed test/x
Empty file.
Empty file removed test/xxx
Empty file.
Empty file removed test/z
Empty file.
Empty file removed test/α
Empty file.

0 comments on commit eae5cbd

Please sign in to comment.