Fortran · 1795 bytes Raw Blame History
1 program test_watch_recursive
2 use fgof_watch, only : init_watch, poll_watch, reset_watch
3 use fgof_watch_types, only : FGOF_WATCH_EVT_CREATED, watch_event, watch_options, watch_session
4 use watch_test_support, only : &
5 ensure_clean_dir, &
6 expect_no_events, &
7 expect_single_event, &
8 make_dir, &
9 remove_tree, &
10 write_text
11 implicit none
12
13 character(len=*), parameter :: nonrecursive_root = "build/watch-tests-nonrecursive"
14 character(len=*), parameter :: recursive_root = "build/watch-tests-recursive"
15 character(len=*), parameter :: nested_path_nonrecursive = "build/watch-tests-nonrecursive/child/nested.txt"
16 character(len=*), parameter :: nested_path_recursive = "build/watch-tests-recursive/child/nested.txt"
17 type(watch_event), allocatable :: events(:)
18 type(watch_options) :: options
19 type(watch_session) :: session
20
21 call ensure_clean_dir(nonrecursive_root)
22 call make_dir(nonrecursive_root // "/child")
23
24 options = watch_options(recursive=.false.)
25 call init_watch(session, nonrecursive_root, options)
26 call write_text(nested_path_nonrecursive, "alpha")
27 events = poll_watch(session)
28 call expect_no_events(events, "nonrecursive watch should ignore nested file creation")
29 call reset_watch(session)
30 call remove_tree(nonrecursive_root)
31
32 call ensure_clean_dir(recursive_root)
33 call make_dir(recursive_root // "/child")
34
35 options = watch_options(recursive=.true.)
36 call init_watch(session, recursive_root, options)
37 call write_text(nested_path_recursive, "alpha")
38 events = poll_watch(session)
39 call expect_single_event(events, FGOF_WATCH_EVT_CREATED, nested_path_recursive, "", .false., "recursive watch should detect nested file creation")
40 call reset_watch(session)
41 call remove_tree(recursive_root)
42 end program test_watch_recursive
43