From: Martin Tournoij Date: Fri, 14 Oct 2022 21:10:32 +0000 (+0200) Subject: isKqueue() would include illumos, run chmod tests on Windows X-Git-Tag: v1.7.2~44 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=f7b5154d9e4dd897111b4b4610c509b6487f29e6;p=fsnotify.git isKqueue() would include illumos, run chmod tests on Windows Instead of a new TestWindowsNoAttributeChanges, just run the regular chmod tests with a windows: block. --- diff --git a/backend_other.go b/backend_other.go index ae409b5..e2b2142 100644 --- a/backend_other.go +++ b/backend_other.go @@ -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 } diff --git a/backend_windows_test.go b/backend_windows_test.go index dd593dc..213f14c 100644 --- a/backend_windows_test.go +++ b/backend_windows_test.go @@ -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) - } -} diff --git a/fsnotify.go b/fsnotify.go index c93b5b8..5b6f74e 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -1,6 +1,3 @@ -//go:build !plan9 -// +build !plan9 - // Package fsnotify provides a cross-platform interface for file system // notifications. package fsnotify diff --git a/fsnotify_test.go b/fsnotify_test.go index d2710b8..e846fd6 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -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() diff --git a/helpers_test.go b/helpers_test.go index 3edda65..0be25fb 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -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 +}