test: splits monolith into a bats file for each subcommand

This commit is contained in:
Lewis Wynne 2026-04-02 11:39:48 +01:00
parent b6fde582bb
commit 2a3c9f264f
10 changed files with 535 additions and 458 deletions

43
test/every.bats Normal file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env bats
load test_helper
@test "every creates a repeating alarm" {
run_nag every weekday "tomorrow 3pm" standup meeting
[ "${status}" -eq 0 ]
[[ "${output}" =~ "[1]" ]]
[[ "${output}" =~ "(weekday)" ]]
[[ "${output}" =~ "standup meeting" ]]
# Verify TSV has rule in field 3.
local _rule
_rule="$(cut -f3 "${NAG_DIR}/alarms")"
[ "${_rule}" = "weekday" ]
}
@test "every with comma-separated rules" {
run_nag every "tuesday,thursday" "tomorrow 3pm" standup
[ "${status}" -eq 0 ]
[[ "${output}" =~ "(tue, thu)" ]]
grep -q "tue,thu" "${NAG_DIR}/alarms"
}
@test "every snaps to next matching day" {
# "weekend 3pm" should snap to Saturday or Sunday, not a weekday.
run_nag every weekend "tomorrow 3pm" relax
[ "${status}" -eq 0 ]
local _ts _dow
_ts="$(cut -f2 "${NAG_DIR}/alarms")"
_dow="$(date -d "@${_ts}" +%u)"
# Day-of-week should be 6 (Sat) or 7 (Sun).
[[ "${_dow}" == "6" || "${_dow}" == "7" ]]
}
@test "every with invalid rule fails" {
run_nag every "invalid_rule" "tomorrow 3pm" some message
[ "${status}" -eq 1 ]
}
@test "every without message fails" {
run_nag every weekday "tomorrow 3pm"
[ "${status}" -eq 1 ]
}