@@ -0,0 +1,102 @@ |
| 1 | +program test_devloop_watch |
| 2 | + use fgof_devloop, only : & |
| 3 | + FGOF_DEVLOOP_TRIGGER_CHANGE, & |
| 4 | + FGOF_DEVLOOP_TRIGGER_NONE, & |
| 5 | + begin_devloop_cycle, & |
| 6 | + clear_devloop_options, & |
| 7 | + devloop_summarize_watch_events, & |
| 8 | + devloop_watch_failure_summary, & |
| 9 | + devloop_watch_options, & |
| 10 | + devloop_watch_trigger, & |
| 11 | + start_devloop |
| 12 | + use fgof_devloop_types, only : & |
| 13 | + devloop_cycle, & |
| 14 | + devloop_options, & |
| 15 | + devloop_state, & |
| 16 | + devloop_trigger, & |
| 17 | + devloop_watch_summary |
| 18 | + use fgof_watch_types, only : & |
| 19 | + FGOF_WATCH_EVT_CREATED, & |
| 20 | + FGOF_WATCH_EVT_MODIFIED, & |
| 21 | + FGOF_WATCH_EVT_MOVED, & |
| 22 | + FGOF_WATCH_EVT_NONE, & |
| 23 | + FGOF_WATCH_EVT_REMOVED, & |
| 24 | + watch_event, & |
| 25 | + watch_options |
| 26 | + implicit none |
| 27 | + |
| 28 | + type(watch_event) :: events(5) |
| 29 | + type(devloop_watch_summary) :: summary |
| 30 | + type(devloop_options) :: options |
| 31 | + type(devloop_trigger) :: trigger |
| 32 | + type(devloop_state) :: state |
| 33 | + type(devloop_cycle) :: cycle |
| 34 | + type(watch_options) :: watch_config |
| 35 | + |
| 36 | + events(1)%kind = FGOF_WATCH_EVT_CREATED |
| 37 | + events(1)%path = "src/main.f90" |
| 38 | + events(2)%kind = FGOF_WATCH_EVT_MODIFIED |
| 39 | + events(2)%path = "src/lib.f90" |
| 40 | + events(3)%kind = FGOF_WATCH_EVT_REMOVED |
| 41 | + events(3)%path = "build" |
| 42 | + events(3)%is_directory = .true. |
| 43 | + events(4)%kind = FGOF_WATCH_EVT_MOVED |
| 44 | + events(4)%path = "test/new.f90" |
| 45 | + events(4)%previous_path = "test/old.f90" |
| 46 | + events(5)%kind = FGOF_WATCH_EVT_NONE |
| 47 | + |
| 48 | + summary = devloop_summarize_watch_events(events) |
| 49 | + if (summary%event_count /= 5) error stop "watch summary should preserve event count" |
| 50 | + if (summary%change_count /= 4) error stop "watch summary should count meaningful changes" |
| 51 | + if (summary%file_change_count /= 3) error stop "watch summary should count file changes" |
| 52 | + if (summary%directory_change_count /= 1) error stop "watch summary should count directory changes" |
| 53 | + if (summary%created_count /= 1) error stop "watch summary should count creates" |
| 54 | + if (summary%modified_count /= 1) error stop "watch summary should count modifies" |
| 55 | + if (summary%removed_count /= 1) error stop "watch summary should count removes" |
| 56 | + if (summary%moved_count /= 1) error stop "watch summary should count moves" |
| 57 | + if (summary%ignored_none_count /= 1) error stop "watch summary should ignore none events" |
| 58 | + if (.not. summary%has_changes) error stop "watch summary should report changes" |
| 59 | + |
| 60 | + options = clear_devloop_options() |
| 61 | + options%debounce_polls = 2 |
| 62 | + options%ignore_hidden = .true. |
| 63 | + options%restart_on_directory_change = .false. |
| 64 | + watch_config = devloop_watch_options(options) |
| 65 | + if (watch_config%debounce_polls /= 2) error stop "watch options should carry debounce policy" |
| 66 | + if (.not. watch_config%ignore_hidden) error stop "watch options should carry hidden-path policy" |
| 67 | + if (watch_config%emit_directory_events) error stop "watch options should suppress directory events when requested" |
| 68 | + |
| 69 | + options%debounce_polls = -3 |
| 70 | + watch_config = devloop_watch_options(options) |
| 71 | + if (watch_config%debounce_polls /= 0) error stop "watch options should clamp negative debounce" |
| 72 | + |
| 73 | + trigger = devloop_watch_trigger(summary) |
| 74 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "watch changes should create a change trigger" |
| 75 | + if (trigger%change_count /= 4) error stop "watch trigger should carry the change count" |
| 76 | + |
| 77 | + options = clear_devloop_options() |
| 78 | + options%restart_on_directory_change = .false. |
| 79 | + options%min_restart_changes = 4 |
| 80 | + trigger = devloop_watch_trigger(summary, options) |
| 81 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) then |
| 82 | + error stop "directory-filtered changes below threshold should not restart" |
| 83 | + end if |
| 84 | + |
| 85 | + options%min_restart_changes = 3 |
| 86 | + trigger = devloop_watch_trigger(summary, options, "filtered watch") |
| 87 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "file changes at threshold should restart" |
| 88 | + if (trigger%change_count /= 3) error stop "filtered watch trigger should carry file count" |
| 89 | + if (trigger%reason /= "filtered watch") error stop "watch trigger should preserve custom reason" |
| 90 | + |
| 91 | + summary = devloop_watch_failure_summary(7, "snapshot failed") |
| 92 | + if (.not. summary%watch_failed) error stop "watch failure summary should record failure" |
| 93 | + trigger = devloop_watch_trigger(summary) |
| 94 | + if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) error stop "watch failures should not force restart triggers" |
| 95 | + |
| 96 | + call start_devloop(state) |
| 97 | + summary = devloop_summarize_watch_events(events(1:2)) |
| 98 | + trigger = devloop_watch_trigger(summary) |
| 99 | + cycle = begin_devloop_cycle(state, trigger) |
| 100 | + if (.not. cycle%started) error stop "watch trigger should drive the devloop cycle model" |
| 101 | + if (cycle%change_count /= 2) error stop "watch cycle should preserve trigger change count" |
| 102 | +end program test_devloop_watch |