}
check(0)
}
+
+func TestWindowsRemWatch(t *testing.T) {
+ tmp := t.TempDir()
+
+ touch(t, tmp, "file")
+
+ w := newWatcher(t)
+ defer w.Close()
+
+ addWatch(t, w, tmp)
+ if err := w.Remove(tmp); err != nil {
+ t.Fatalf("Could not remove the watch: %v\n", err)
+ }
+ if err := w.remWatch(tmp); err == nil {
+ t.Fatal("Should be fail with closed handle\n")
+ }
+}
}
})
+ // Make sure file handles are correctly released.
+ //
+ // regression test for #42 see https://gist.github.com/timshannon/603f92824c5294269797
+ t.Run("", func(t *testing.T) {
+ w := newWatcher(t)
+ defer w.Close()
+
+ // consume the events
+ var werr error
+ var wg sync.WaitGroup
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case werr = <-w.Errors:
+ return
+ case <-w.Events:
+ }
+ }
+ }()
+
+ tmp := t.TempDir()
+ dir := join(tmp, "child")
+ addWatch(t, w, tmp)
+ mkdir(t, dir)
+ addWatch(t, w, dir) // start watching child
+ rmWatch(t, w, dir) // stop watching child
+ rmAll(t, dir) // delete child dir
+
+ // Child dir should no longer exist
+ _, err := os.Stat(dir)
+ if err == nil {
+ t.Fatalf("dir %q should no longer exist!", dir)
+ }
+ if _, ok := err.(*os.PathError); err != nil && !ok {
+ t.Errorf("Expected a PathError, got %v", err)
+ }
+
+ w.Close()
+ wg.Wait()
+
+ if werr != nil {
+ t.Fatal(werr)
+ }
+ })
+
t.Run("remove with ... when non-recursive", func(t *testing.T) {
recurseOnly(t)
t.Parallel()
t.Fatal(err)
}
})
-
}
func TestEventString(t *testing.T) {
}
}
+// rmWatch removes a watch.
+func rmWatch(t *testing.T, watcher *Watcher, path ...string) {
+ t.Helper()
+ if len(path) < 1 {
+ t.Fatalf("rmWatch: path must have at least one element: %s", path)
+ }
+ err := watcher.Remove(join(path...))
+ if err != nil {
+ t.Fatalf("rmWatch(%q): %s", join(path...), err)
+ }
+}
+
const noWait = ""
func shouldWait(path ...string) bool {