]> go.fuhry.dev Git - fsnotify.git/commitdiff
isKqueue() would include illumos, run chmod tests on Windows
authorMartin Tournoij <martin@arp242.net>
Fri, 14 Oct 2022 21:10:32 +0000 (23:10 +0200)
committerMartin Tournoij <martin@arp242.net>
Fri, 14 Oct 2022 22:00:44 +0000 (00:00 +0200)
Instead of a new TestWindowsNoAttributeChanges, just run the regular
chmod tests with a windows: block.

backend_other.go
backend_windows_test.go
fsnotify.go
fsnotify_test.go
helpers_test.go

index ae409b512d36f5bb0b0ddf38c528f5aa7babd40a..e2b21427fc5ceeb3a48bea0a94fe65fd77fe8772 100644 (file)
@@ -17,9 +17,12 @@ func NewWatcher() (*Watcher, error) {
 }
 
 // Close removes all watches and closes the events channel.
-func (w *Watcher) Close() error {
-       return nil
-}
+func (w *Watcher) Close() error { return nil }
+
+// WatchList returns all paths added with [Add] (and are not yet removed).
+//
+// Returns nil if [Watcher.Close] was called.
+func (w *Watcher) WatchList() []string { return nil }
 
 // Add starts monitoring the path for changes.
 //
@@ -53,9 +56,7 @@ func (w *Watcher) Close() error {
 //
 // Instead, watch the parent directory and use Event.Name to filter out files
 // you're not interested in. There is an example of this in [cmd/fsnotify/file.go].
-func (w *Watcher) Add(name string) error {
-       return nil
-}
+func (w *Watcher) Add(name string) error { return nil }
 
 // Remove stops monitoring the path for changes.
 //
@@ -63,6 +64,4 @@ func (w *Watcher) Add(name string) error {
 // /tmp/dir and /tmp/dir/subdir then you will need to remove both.
 //
 // Removing a path that has not yet been added returns [ErrNonExistentWatch].
-func (w *Watcher) Remove(name string) error {
-       return nil
-}
+func (w *Watcher) Remove(name string) error { return nil }
index dd593dc26019cc80cce7bac821fc8272753046c7..213f14cb5db893502ec349195515959652879393 100644 (file)
@@ -50,18 +50,3 @@ func TestRemoveState(t *testing.T) {
        }
        check(0)
 }
-
-func TestWindowsNoAttributeChanges(t *testing.T) {
-       tmp := t.TempDir()
-       file := filepath.Join(tmp, "TestFsnotifyEventsExisting.testfile")
-
-       touch(t, file) // Create a file before watching directory
-       w := newCollector(t, tmp)
-       w.collect(t)
-       chmod(t, 0o400, file) // Make the file read-only, which is an attribute change
-
-       have := w.stop(t)
-       if len(have) != 0 {
-               t.Fatalf("should not have received any events, received:\n%s", have)
-       }
-}
index c93b5b84f382f1b1a4d435bbbe93273b0ef445cb..5b6f74e0f08225c43626af38a16abf52d5424748 100644 (file)
@@ -1,6 +1,3 @@
-//go:build !plan9
-// +build !plan9
-
 // Package fsnotify provides a cross-platform interface for file system
 // notifications.
 package fsnotify
index d2710b8d0d0055485d4739fbb03017899a334808..e846fd6341dcf222a7db1647c6eaddbdf1b1f1d7 100644 (file)
@@ -1,6 +1,3 @@
-//go:build !plan9
-// +build !plan9
-
 package fsnotify
 
 import (
@@ -108,7 +105,7 @@ func TestWatch(t *testing.T) {
 
                {"file in directory is not readable", func(t *testing.T, w *Watcher, tmp string) {
                        if runtime.GOOS == "windows" {
-                               t.Skip("attributes don't work on Windows")
+                               t.Skip("attributes don't work on Windows") // Figure out how to make a file unreadable
                        }
 
                        touch(t, tmp, "file-unreadable")
@@ -129,6 +126,9 @@ func TestWatch(t *testing.T) {
                        kqueue:
                                WRITE    "/file"
                                REMOVE   "/file"
+
+                       windows:
+                               empty
                `},
 
                {"watch same dir twice", func(t *testing.T, w *Watcher, tmp string) {
@@ -193,7 +193,6 @@ func TestWatch(t *testing.T) {
                                // CREATE "/private/var/.../TestWatchwatch_a_symlink_to_a_dir2551725268/001/dir/file"
                                // Pretty sure this is caused by the broken symlink-follow
                                // behaviour too.
-
                                t.Skip("broken on macOS")
                        }
 
@@ -263,7 +262,7 @@ func TestWatchCreate(t *testing.T) {
                // FIFO
                {"create new named pipe", func(t *testing.T, w *Watcher, tmp string) {
                        if runtime.GOOS == "windows" {
-                               t.Skip("no named pipes on windows")
+                               t.Skip() // No named pipes on Windows.
                        }
                        touch(t, tmp, "file")
                        addWatch(t, w, tmp)
@@ -274,11 +273,17 @@ func TestWatchCreate(t *testing.T) {
                // Device node
                {"create new device node pipe", func(t *testing.T, w *Watcher, tmp string) {
                        if runtime.GOOS == "windows" {
-                               t.Skip("no device nodes on windows")
+                               t.Skip() // No device nodes on Windows.
                        }
                        if isKqueue() {
+                               // Don't want to use os/user to check uid, since that pulls in
+                               // cgo by default and stuff that uses fsnotify won't be
+                               // statically linked by default.
                                t.Skip("needs root on BSD")
                        }
+                       if isSolaris() {
+                               t.Skip(`"mknod fails with "not owner"`)
+                       }
                        touch(t, tmp, "file")
                        addWatch(t, w, tmp)
 
@@ -530,7 +535,7 @@ func TestWatchSymlink(t *testing.T) {
                                // kqueue.go does a lot of weird things with symlinks that I
                                // don't think are necessarily correct, but need to test a bit
                                // more.
-                               t.Skip()
+                               t.Skip("broken on macOS")
                        }
 
                        symlink(t, ".", tmp, "link")
@@ -554,7 +559,7 @@ func TestWatchSymlink(t *testing.T) {
                                // TODO: fix it; this seems a bit hard though; the entire way
                                //       kqueue backend deals with symlinks is meh, and need to
                                //       be careful not to break compatibility.
-                               t.Skip("broken")
+                               t.Skip("broken on kqueue")
                        }
 
                        touch(t, tmp, "file1")
@@ -585,10 +590,6 @@ func TestWatchSymlink(t *testing.T) {
 }
 
 func TestWatchAttrib(t *testing.T) {
-       if runtime.GOOS == "windows" {
-               t.Skip("attributes don't work on Windows")
-       }
-
        tests := []testCase{
                {"chmod", func(t *testing.T, w *Watcher, tmp string) {
                        file := filepath.Join(tmp, "file")
@@ -598,6 +599,9 @@ func TestWatchAttrib(t *testing.T) {
                        chmod(t, 0o700, file)
                }, `
                        CHMOD   "/file"
+
+                       windows:
+                               empty
                `},
 
                {"write does not trigger CHMOD", func(t *testing.T, w *Watcher, tmp string) {
@@ -606,11 +610,13 @@ func TestWatchAttrib(t *testing.T) {
                        cat(t, "data", file)
                        addWatch(t, w, file)
                        chmod(t, 0o700, file)
-
                        cat(t, "more data", file)
                }, `
                        CHMOD   "/file"
                        WRITE   "/file"
+
+                       windows:
+                               write /file
                `},
 
                {"chmod after write", func(t *testing.T, w *Watcher, tmp string) {
@@ -625,6 +631,9 @@ func TestWatchAttrib(t *testing.T) {
                        CHMOD   "/file"
                        WRITE   "/file"
                        CHMOD   "/file"
+
+                       windows:
+                               write /file
                `},
        }
 
@@ -862,7 +871,7 @@ func TestClose(t *testing.T) {
 
        t.Run("closes channels after read", func(t *testing.T) {
                if runtime.GOOS == "netbsd" {
-                       t.Skip("flaky") // TODO
+                       t.Skip("flaky")
                }
 
                t.Parallel()
@@ -907,7 +916,7 @@ func TestClose(t *testing.T) {
 func TestAdd(t *testing.T) {
        t.Run("permission denied", func(t *testing.T) {
                if runtime.GOOS == "windows" {
-                       t.Skip("attributes don't work on Windows")
+                       t.Skip("chmod doesn't work on Windows") // See if we can make a file unreadable
                }
 
                t.Parallel()
@@ -1042,14 +1051,6 @@ func TestEventString(t *testing.T) {
        }
 }
 
-func isKqueue() bool {
-       switch runtime.GOOS {
-       case "linux", "windows":
-               return false
-       }
-       return true
-}
-
 // Verify the watcher can keep up with file creations/deletions when under load.
 func TestWatchStress(t *testing.T) {
        if isCI() {
@@ -1208,7 +1209,7 @@ func TestWatchStress(t *testing.T) {
 func TestWatchList(t *testing.T) {
        if runtime.GOOS == "windows" {
                // TODO: probably should I guess...
-               t.Skip("WatchList has always beek broken on Windows and I don't feel like fixing it")
+               t.Skip("WatchList has always been broken on Windows and I don't feel like fixing it")
        }
 
        t.Parallel()
index 3edda65af1dc38ac34187852462f72fc055e0338..0be25fbcbffedab072831d99deffc9150b8d77f0 100644 (file)
@@ -557,3 +557,19 @@ func isCI() bool {
        _, ok := os.LookupEnv("CI")
        return ok
 }
+
+func isKqueue() bool {
+       switch runtime.GOOS {
+       case "darwin", "freebsd", "openbsd", "netbsd", "dragonfly":
+               return true
+       }
+       return false
+}
+
+func isSolaris() bool {
+       switch runtime.GOOS {
+       case "illumos", "solaris":
+               return true
+       }
+       return false
+}