@@ -675,7 +675,7 @@ impl Drop for PollWatcher {
675675#[ cfg( test) ]
676676mod tests {
677677 use super :: PollWatcher ;
678- use crate :: test:: * ;
678+ use crate :: { Error , ErrorKind , RecursiveMode , TargetMode , WatchMode , Watcher , test:: * } ;
679679
680680 fn watcher ( ) -> ( TestWatcher < PollWatcher > , Receiver ) {
681681 poll_watcher_channel ( )
@@ -700,6 +700,62 @@ mod tests {
700700 rx. wait_ordered_exact ( [ expected ( & path) . create_any ( ) ] ) ;
701701 }
702702
703+ #[ test]
704+ #[ ignore = "not implemented" ]
705+ fn create_self_file ( ) {
706+ let tmpdir = testdir ( ) ;
707+ let ( mut watcher, mut rx) = watcher ( ) ;
708+
709+ let path = tmpdir. path ( ) . join ( "entry" ) ;
710+
711+ watcher. watch_nonrecursively ( & path) ;
712+
713+ std:: fs:: File :: create_new ( & path) . expect ( "create" ) ;
714+
715+ rx. sleep_until_exists ( & path) ;
716+ rx. wait_ordered_exact ( [ expected ( & path) . create_any ( ) ] ) ;
717+ }
718+
719+ #[ test]
720+ #[ ignore = "not implemented" ]
721+ fn create_self_file_no_track ( ) {
722+ let tmpdir = testdir ( ) ;
723+ let ( mut watcher, _) = watcher ( ) ;
724+
725+ let path = tmpdir. path ( ) . join ( "entry" ) ;
726+
727+ let result = watcher. watcher . watch (
728+ & path,
729+ WatchMode {
730+ recursive_mode : RecursiveMode :: NonRecursive ,
731+ target_mode : TargetMode :: NoTrack ,
732+ } ,
733+ ) ;
734+ assert ! ( matches!(
735+ result,
736+ Err ( Error {
737+ paths: _,
738+ kind: ErrorKind :: PathNotFound
739+ } )
740+ ) ) ;
741+ }
742+
743+ #[ test]
744+ #[ ignore = "TODO: not implemented" ]
745+ fn create_self_file_nested ( ) {
746+ let tmpdir = testdir ( ) ;
747+ let ( mut watcher, mut rx) = watcher ( ) ;
748+
749+ let path = tmpdir. path ( ) . join ( "entry/nested" ) ;
750+
751+ watcher. watch_nonrecursively ( & path) ;
752+
753+ std:: fs:: create_dir_all ( path. parent ( ) . unwrap ( ) ) . expect ( "create" ) ;
754+ std:: fs:: File :: create_new ( & path) . expect ( "create" ) ;
755+
756+ rx. wait_ordered_exact ( [ expected ( & path) . create_file ( ) ] ) ;
757+ }
758+
703759 #[ test]
704760 fn create_dir ( ) {
705761 let tmpdir = testdir ( ) ;
@@ -731,7 +787,99 @@ mod tests {
731787 }
732788
733789 #[ test]
734- fn remove_file ( ) {
790+ fn rename_file ( ) {
791+ let tmpdir = testdir ( ) ;
792+ let ( mut watcher, mut rx) = watcher ( ) ;
793+ let path = tmpdir. path ( ) . join ( "entry" ) ;
794+ let new_path = tmpdir. path ( ) . join ( "new_entry" ) ;
795+ std:: fs:: File :: create_new ( & path) . expect ( "Unable to create" ) ;
796+
797+ watcher. watch_recursively ( & tmpdir) ;
798+ std:: fs:: rename ( & path, & new_path) . expect ( "Unable to remove" ) ;
799+
800+ rx. sleep_while_exists ( & path) ;
801+ rx. sleep_until_exists ( & new_path) ;
802+
803+ rx. wait_unordered_exact ( [
804+ expected ( & path) . remove_any ( ) ,
805+ expected ( & new_path) . create_any ( ) ,
806+ ] ) ;
807+ }
808+
809+ #[ test]
810+ #[ ignore = "TODO: not implemented" ]
811+ fn rename_self_file ( ) {
812+ let tmpdir = testdir ( ) ;
813+ let ( mut watcher, mut rx) = watcher ( ) ;
814+
815+ let path = tmpdir. path ( ) . join ( "entry" ) ;
816+ std:: fs:: File :: create_new ( & path) . expect ( "create" ) ;
817+
818+ watcher. watch_nonrecursively ( & path) ;
819+ let new_path = tmpdir. path ( ) . join ( "renamed" ) ;
820+
821+ std:: fs:: rename ( & path, & new_path) . expect ( "rename" ) ;
822+
823+ rx. sleep_while_exists ( & path) ;
824+ rx. sleep_until_exists ( & new_path) ;
825+
826+ rx. wait_unordered_exact ( [ expected ( & path) . remove_any ( ) ] )
827+ . ensure_no_tail ( ) ;
828+
829+ std:: fs:: rename ( & new_path, & path) . expect ( "rename2" ) ;
830+
831+ rx. sleep_until_exists ( & new_path) ;
832+ rx. sleep_while_exists ( & path) ;
833+
834+ rx. wait_unordered_exact ( [ expected ( & path) . create_any ( ) ] )
835+ . ensure_no_tail ( ) ;
836+ }
837+
838+ #[ test]
839+ #[ ignore = "TODO: not implemented" ]
840+ fn rename_self_file_no_track ( ) {
841+ let tmpdir = testdir ( ) ;
842+ let ( mut watcher, mut rx) = watcher ( ) ;
843+
844+ let path = tmpdir. path ( ) . join ( "entry" ) ;
845+ std:: fs:: File :: create_new ( & path) . expect ( "create" ) ;
846+
847+ watcher. watch (
848+ & path,
849+ WatchMode {
850+ recursive_mode : RecursiveMode :: NonRecursive ,
851+ target_mode : TargetMode :: NoTrack ,
852+ } ,
853+ ) ;
854+
855+ let new_path = tmpdir. path ( ) . join ( "renamed" ) ;
856+
857+ std:: fs:: rename ( & path, & new_path) . expect ( "rename" ) ;
858+
859+ rx. sleep_while_exists ( & path) ;
860+ rx. sleep_until_exists ( & new_path) ;
861+
862+ rx. wait_unordered_exact ( [ expected ( & path) . remove_any ( ) ] )
863+ . ensure_no_tail ( ) ;
864+
865+ let result = watcher. watcher . watch (
866+ & path,
867+ WatchMode {
868+ recursive_mode : RecursiveMode :: NonRecursive ,
869+ target_mode : TargetMode :: NoTrack ,
870+ } ,
871+ ) ;
872+ assert ! ( matches!(
873+ result,
874+ Err ( Error {
875+ paths: _,
876+ kind: ErrorKind :: PathNotFound
877+ } )
878+ ) ) ;
879+ }
880+
881+ #[ test]
882+ fn delete_file ( ) {
735883 let tmpdir = testdir ( ) ;
736884 let ( mut watcher, mut rx) = watcher ( ) ;
737885 let path = tmpdir. path ( ) . join ( "entry" ) ;
@@ -745,23 +893,50 @@ mod tests {
745893 }
746894
747895 #[ test]
748- fn rename_file ( ) {
896+ #[ ignore = "TODO: not implemented" ]
897+ fn delete_self_file ( ) {
749898 let tmpdir = testdir ( ) ;
750899 let ( mut watcher, mut rx) = watcher ( ) ;
751900 let path = tmpdir. path ( ) . join ( "entry" ) ;
752- let new_path = tmpdir. path ( ) . join ( "new_entry" ) ;
753901 std:: fs:: File :: create_new ( & path) . expect ( "Unable to create" ) ;
754902
755- watcher. watch_recursively ( & tmpdir) ;
756- std:: fs:: rename ( & path, & new_path) . expect ( "Unable to remove" ) ;
903+ watcher. watch_nonrecursively ( & path) ;
904+
905+ std:: fs:: remove_file ( & path) . expect ( "Unable to remove" ) ;
757906
758907 rx. sleep_while_exists ( & path) ;
759- rx. sleep_until_exists ( & new_path ) ;
908+ rx. wait_ordered_exact ( [ expected ( & path ) . remove_any ( ) ] ) ;
760909
761- rx. wait_unordered_exact ( [
762- expected ( & path) . remove_any ( ) ,
763- expected ( & new_path) . create_any ( ) ,
764- ] ) ;
910+ std:: fs:: write ( & path, "" ) . expect ( "write" ) ;
911+
912+ rx. sleep_until_exists ( & path) ;
913+ rx. wait_ordered_exact ( [ expected ( & path) . create_file ( ) ] ) ;
914+ }
915+
916+ #[ test]
917+ #[ ignore = "TODO: not implemented" ]
918+ fn delete_self_file_no_track ( ) {
919+ let tmpdir = testdir ( ) ;
920+ let ( mut watcher, mut rx) = watcher ( ) ;
921+ let path = tmpdir. path ( ) . join ( "entry" ) ;
922+ std:: fs:: File :: create_new ( & path) . expect ( "Unable to create" ) ;
923+
924+ watcher. watch (
925+ & path,
926+ WatchMode {
927+ recursive_mode : RecursiveMode :: NonRecursive ,
928+ target_mode : TargetMode :: NoTrack ,
929+ } ,
930+ ) ;
931+
932+ std:: fs:: remove_file ( & path) . expect ( "Unable to remove" ) ;
933+
934+ rx. sleep_while_exists ( & path) ;
935+ rx. wait_ordered_exact ( [ expected ( & path) . remove_any ( ) ] ) ;
936+
937+ std:: fs:: write ( & path, "" ) . expect ( "write" ) ;
938+
939+ rx. ensure_empty_with_wait ( ) ;
765940 }
766941
767942 #[ test]
0 commit comments