| 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_change = .false. |
| 79 |
trigger = devloop_watch_trigger(summary, options) |
| 80 |
if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) then |
| 81 |
error stop "restart-on-change policy should suppress watch triggers" |
| 82 |
end if |
| 83 |
|
| 84 |
options = clear_devloop_options() |
| 85 |
options%restart_on_directory_change = .false. |
| 86 |
options%min_restart_changes = 4 |
| 87 |
trigger = devloop_watch_trigger(summary, options) |
| 88 |
if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) then |
| 89 |
error stop "directory-filtered changes below threshold should not restart" |
| 90 |
end if |
| 91 |
|
| 92 |
options%min_restart_changes = 3 |
| 93 |
trigger = devloop_watch_trigger(summary, options, "filtered watch") |
| 94 |
if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_CHANGE) error stop "file changes at threshold should restart" |
| 95 |
if (trigger%change_count /= 3) error stop "filtered watch trigger should carry file count" |
| 96 |
if (trigger%reason /= "filtered watch") error stop "watch trigger should preserve custom reason" |
| 97 |
|
| 98 |
summary = devloop_watch_failure_summary(7, "snapshot failed") |
| 99 |
if (.not. summary%watch_failed) error stop "watch failure summary should record failure" |
| 100 |
trigger = devloop_watch_trigger(summary) |
| 101 |
if (trigger%kind /= FGOF_DEVLOOP_TRIGGER_NONE) error stop "watch failures should not force restart triggers" |
| 102 |
|
| 103 |
call start_devloop(state) |
| 104 |
summary = devloop_summarize_watch_events(events(1:2)) |
| 105 |
trigger = devloop_watch_trigger(summary) |
| 106 |
cycle = begin_devloop_cycle(state, trigger) |
| 107 |
if (.not. cycle%started) error stop "watch trigger should drive the devloop cycle model" |
| 108 |
if (cycle%change_count /= 2) error stop "watch cycle should preserve trigger change count" |
| 109 |
end program test_devloop_watch |
| 110 |
|