Compare commits

...

10 commits

8 changed files with 1580 additions and 64 deletions

1020
nag

File diff suppressed because it is too large Load diff

View file

@ -124,3 +124,92 @@ SCRIPT
_new_ts="$(cut -f3 "${NAG_DIR}/alarms" | head -1)" _new_ts="$(cut -f3 "${NAG_DIR}/alarms" | head -1)"
(( _new_ts > $(date +%s) )) (( _new_ts > $(date +%s) ))
} }
@test "check skips snoozed alarm and does not fire it" {
local _past_ts=$(( $(date +%s) - 60 ))
write_alarm "$(printf "1\t\t%s\t\tsnoozed alarm" "${_past_ts}")"
printf "1\\n" > "${NAG_DIR}/snoozed"
local _fired="${NAG_DIR}/fired"
export NAG_CMD="${NAG_DIR}/recorder"
cat > "${NAG_CMD}" <<'SCRIPT'
#!/usr/bin/env bash
printf "%s\n" "$2" >> "${NAG_DIR}/fired"
SCRIPT
chmod +x "${NAG_CMD}"
run_nag check
[ "${status}" -eq 0 ]
[ ! -f "${_fired}" ]
[ -s "${NAG_DIR}/alarms" ]
grep -q "snoozed alarm" "${NAG_DIR}/alarms"
}
@test "check skips alarm snoozed with expiry" {
local _past_ts=$(( $(date +%s) - 60 ))
local _future_expiry=$(( $(date +%s) + 3600 ))
write_alarm "$(printf "1\t\t%s\t\tsnoozed alarm" "${_past_ts}")"
printf "1\t%s\\n" "${_future_expiry}" > "${NAG_DIR}/snoozed"
local _fired="${NAG_DIR}/fired"
export NAG_CMD="${NAG_DIR}/recorder"
cat > "${NAG_CMD}" <<'SCRIPT'
#!/usr/bin/env bash
printf "%s\n" "$2" >> "${NAG_DIR}/fired"
SCRIPT
chmod +x "${NAG_CMD}"
run_nag check
[ "${status}" -eq 0 ]
[ ! -f "${_fired}" ]
[ -s "${NAG_DIR}/alarms" ]
}
@test "check sweeps expired snooze entries" {
local _future_ts=$(( $(date +%s) + 3600 ))
write_alarm "$(printf "1\t\t%s\t\talarm" "${_future_ts}")"
local _past_expiry=$(( $(date +%s) - 60 ))
printf "1\t%s\\n" "${_past_expiry}" > "${NAG_DIR}/snoozed"
run_nag check
[ "${status}" -eq 0 ]
if [ -f "${NAG_DIR}/snoozed" ]; then
[ ! -s "${NAG_DIR}/snoozed" ] || ! grep -q "^1" "${NAG_DIR}/snoozed"
fi
}
@test "check fires alarm after snooze expires" {
local _past_ts=$(( $(date +%s) - 60 ))
local _past_expiry=$(( $(date +%s) - 120 ))
write_alarm "$(printf "1\t\t%s\t\texpired snooze" "${_past_ts}")"
printf "1\t%s\\n" "${_past_expiry}" > "${NAG_DIR}/snoozed"
local _fired="${NAG_DIR}/fired"
export NAG_CMD="${NAG_DIR}/recorder"
cat > "${NAG_CMD}" <<'SCRIPT'
#!/usr/bin/env bash
printf "%s\n" "$2" >> "${NAG_DIR}/fired"
SCRIPT
chmod +x "${NAG_CMD}"
run_nag check
[ "${status}" -eq 0 ]
grep -q "expired snooze" "${_fired}"
}
@test "check sweeps orphaned snooze entries for removed alarms" {
local _future_ts=$(( $(date +%s) + 3600 ))
write_alarm "$(printf "2\t\t%s\t\treal alarm" "${_future_ts}")"
# ID 1 does not exist in alarms, ID 2 does.
printf "1\\n" > "${NAG_DIR}/snoozed"
printf "2\\n" >> "${NAG_DIR}/snoozed"
run_nag check
[ "${status}" -eq 0 ]
# Orphan ID 1 should be swept, ID 2 should remain.
[ -f "${NAG_DIR}/snoozed" ]
! grep -q "^1$" "${NAG_DIR}/snoozed"
grep -q "^2$" "${NAG_DIR}/snoozed"
}

View file

@ -7,8 +7,8 @@ load test_helper
[ "${status}" -eq 0 ] [ "${status}" -eq 0 ]
[[ "${output}" =~ "<time> <message...>" ]] [[ "${output}" =~ "<time> <message...>" ]]
[[ "${output}" =~ "every <rules> <time> <message...>" ]] [[ "${output}" =~ "every <rules> <time> <message...>" ]]
[[ "${output}" =~ "stop <id|tag>" ]] [[ "${output}" =~ "stop <all|id|tag>" ]]
[[ "${output}" =~ "skip <id|tag>" ]] [[ "${output}" =~ "skip <all|id|tag>" ]]
[[ "${output}" =~ "check" ]] [[ "${output}" =~ "check" ]]
[[ "${output}" =~ "help [<subcommand>]" ]] [[ "${output}" =~ "help [<subcommand>]" ]]
[[ "${output}" =~ "Options:" ]] [[ "${output}" =~ "Options:" ]]
@ -39,14 +39,14 @@ load test_helper
run_nag help stop run_nag help stop
[ "${status}" -eq 0 ] [ "${status}" -eq 0 ]
[[ "${output}" =~ "Usage:" ]] [[ "${output}" =~ "Usage:" ]]
[[ "${output}" =~ "stop <id|tag>" ]] [[ "${output}" =~ "stop <all|id|tag>" ]]
} }
@test "help skip shows skip usage" { @test "help skip shows skip usage" {
run_nag help skip run_nag help skip
[ "${status}" -eq 0 ] [ "${status}" -eq 0 ]
[[ "${output}" =~ "Usage:" ]] [[ "${output}" =~ "Usage:" ]]
[[ "${output}" =~ "skip <id|tag>" ]] [[ "${output}" =~ "skip <all|id|tag>" ]]
} }
@test "help every shows every usage" { @test "help every shows every usage" {

View file

@ -84,13 +84,13 @@ load test_helper
[[ "${output}" =~ "Tomorrow,".*"tomorrow alarm" ]] [[ "${output}" =~ "Tomorrow,".*"tomorrow alarm" ]]
} }
@test "list shows This <day> for alarm 3 days away" { @test "list shows <day> for alarm 3 days away" {
local _ts=$(( $(date -d "$(date +%Y-%m-%d)" +%s) + 86400 * 3 + 43200 )) local _ts=$(( $(date -d "$(date +%Y-%m-%d)" +%s) + 86400 * 3 + 43200 ))
local _day="$(date -d "@${_ts}" +%A)" local _day="$(date -d "@${_ts}" +%A)"
write_alarm "$(printf '1\t\t%s\t\tthis alarm' "${_ts}")" write_alarm "$(printf '1\t\t%s\t\tthis alarm' "${_ts}")"
run_nag run_nag
[ "${status}" -eq 0 ] [ "${status}" -eq 0 ]
[[ "${output}" =~ "This ${_day},".*"this alarm" ]] [[ "${output}" =~ "${_day},".*"this alarm" ]]
} }
@test "list shows Next <day> for alarm 10 days away" { @test "list shows Next <day> for alarm 10 days away" {
@ -110,3 +110,61 @@ load test_helper
[ "${status}" -eq 0 ] [ "${status}" -eq 0 ]
[[ "${output}" =~ "${_date},".*"far alarm" ]] [[ "${output}" =~ "${_date},".*"far alarm" ]]
} }
@test "list shows (snoozed) for indefinitely snoozed alarm" {
run_nag at "tomorrow 3pm" "take a break"
printf "1\\n" > "${NAG_DIR}/snoozed"
run_nag
[ "${status}" -eq 0 ]
[[ "${output}" =~ "(snoozed)" ]]
[[ "${output}" =~ "take a break" ]]
}
@test "list shows (snoozed until DATE) for timed snooze" {
run_nag at "tomorrow 3pm" "take a break"
local _expiry_ts=$(( $(date +%s) + 86400 * 7 ))
printf "1\t%s\\n" "${_expiry_ts}" > "${NAG_DIR}/snoozed"
run_nag
[ "${status}" -eq 0 ]
# Should use the same format as list dates (e.g. "Next Monday, 3pm").
[[ "${output}" =~ "snoozed until " ]]
[[ "${output}" =~ "am)" ]] || [[ "${output}" =~ "pm)" ]]
}
@test "list shows year for alarm in a different year" {
local _next_year=$(( $(date +%Y) + 1 ))
local _ts
_ts="$(date -d "${_next_year}-06-15 14:00:00" +%s)"
write_alarm "$(printf '1\t\t%s\t\tnext year alarm' "${_ts}")"
run_nag
[ "${status}" -eq 0 ]
[[ "${output}" =~ "${_next_year}" ]]
[[ "${output}" =~ "next year alarm" ]]
}
@test "list does not show (snoozed) for unsnoozed alarm" {
run_nag at "tomorrow 3pm" "take a break"
run_nag
[ "${status}" -eq 0 ]
[[ ! "${output}" =~ "snoozed" ]]
}
@test "--iso flag shows YYYY-MM-DD HH:MM:SS format" {
local _ts=$(( $(date -d "$(date +%Y-%m-%d)" +%s) + 86400 + 54000 ))
write_alarm "$(printf '1\t\t%s\t\traw alarm' "${_ts}")"
local _expected
_expected="$(date -d "@${_ts}" "+%Y-%m-%d %H:%M:%S")"
run "${_NAG}" -f --iso
[ "${status}" -eq 0 ]
[[ "${output}" =~ "${_expected}" ]]
[[ "${output}" =~ "raw alarm" ]]
}
@test "--epoch flag shows unix timestamps" {
local _ts=$(( $(date -d "$(date +%Y-%m-%d)" +%s) + 86400 + 54000 ))
write_alarm "$(printf '1\t\t%s\t\tepoch alarm' "${_ts}")"
run "${_NAG}" -f --epoch
[ "${status}" -eq 0 ]
[[ "${output}" =~ "${_ts}" ]]
[[ "${output}" =~ "epoch alarm" ]]
}

View file

@ -61,3 +61,41 @@ load test_helper
run "${_NAG}" -f skip work run "${_NAG}" -f skip work
[ "${status}" -eq 1 ] [ "${status}" -eq 1 ]
} }
@test "skip all reschedules repeating and deletes one-shots" {
run_nag at "tomorrow 3pm" "one-shot"
run_nag every day "tomorrow 3pm" "daily task"
run "${_NAG}" -f skip all
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Stopped" ]]
[[ "${output}" =~ "Skipped" ]]
# One-shot removed, repeating kept.
[ -s "${NAG_DIR}/alarms" ]
! grep -q "one-shot" "${NAG_DIR}/alarms"
grep -q "daily task" "${NAG_DIR}/alarms"
}
@test "skip all requires -f" {
run_nag at "tomorrow 3pm" "test"
run "${_NAG}" skip all < /dev/null
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Skip" ]]
[[ "${output}" =~ "-f" ]]
}
@test "skip all with no alarms fails" {
run "${_NAG}" -f skip all
[ "${status}" -eq 1 ]
}
@test "skip one-shot cleans up snoozed metadata" {
run_nag at "tomorrow 3pm" "one-shot"
run_nag snooze 1
[ -f "${NAG_DIR}/snoozed" ]
run_nag skip 1
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Stopped" ]]
if [ -f "${NAG_DIR}/snoozed" ]; then
! grep -q "^1" "${NAG_DIR}/snoozed"
fi
}

189
test/snooze.bats Normal file
View file

@ -0,0 +1,189 @@
#!/usr/bin/env bats
load test_helper
@test "snooze by ID creates entry in snoozed file" {
run_nag at "tomorrow 3pm" "take a break"
run_nag snooze 1
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Snoozed [1]" ]]
[ -f "${NAG_DIR}/snoozed" ]
grep -q "^1$" "${NAG_DIR}/snoozed"
}
@test "snooze by ID shows alarm message in output" {
run_nag at "tomorrow 3pm" "take a break"
run_nag snooze 1
[[ "${output}" =~ "take a break" ]]
}
@test "snooze with nonexistent ID fails" {
run_nag snooze 99
[ "${status}" -eq 1 ]
}
@test "snooze with no args fails" {
run_nag snooze
[ "${status}" -eq 1 ]
}
@test "snooze all creates entries for all alarm IDs" {
run_nag at "tomorrow 3pm" "first"
run_nag at "tomorrow 4pm" "second"
run_nag snooze all
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Snoozed [1]" ]]
[[ "${output}" =~ "Snoozed [2]" ]]
[ -f "${NAG_DIR}/snoozed" ]
grep -q "^1$" "${NAG_DIR}/snoozed"
grep -q "^2$" "${NAG_DIR}/snoozed"
}
@test "snooze all with duration sets expiry for each alarm" {
run_nag at "tomorrow 3pm" "first"
run_nag at "tomorrow 4pm" "second"
run_nag snooze all "tomorrow"
[ "${status}" -eq 0 ]
[[ "${output}" =~ "until" ]]
grep -q "^1"$'\t' "${NAG_DIR}/snoozed"
grep -q "^2"$'\t' "${NAG_DIR}/snoozed"
}
@test "snooze by tag creates entries for matching alarm IDs" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag snooze work
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Snoozed [1]" ]]
grep -q "^1$" "${NAG_DIR}/snoozed"
! grep -q "^work" "${NAG_DIR}/snoozed"
}
@test "snooze by tag requires -f" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run "${_NAG}" snooze work < /dev/null
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Snooze" ]]
[[ "${output}" =~ "-f" ]]
}
@test "snooze by tag with no matching alarms fails" {
run_nag at "tomorrow 3pm" "test alarm"
run "${_NAG}" -f snooze nonexistent
[ "${status}" -eq 1 ]
}
@test "snooze by ID with duration sets expiry" {
run_nag at "tomorrow 3pm" "take a break"
run_nag snooze 1 "tomorrow"
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Snoozed [1]" ]]
[[ "${output}" =~ "until" ]]
local _line
_line="$(cat "${NAG_DIR}/snoozed")"
[[ "${_line}" == 1$'\t'* ]]
}
@test "snooze by tag with duration sets expiry for matching IDs" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag snooze work "tomorrow"
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Snoozed [1]" ]]
[[ "${output}" =~ "until" ]]
grep -q "^1"$'\t' "${NAG_DIR}/snoozed"
! grep -q "^work" "${NAG_DIR}/snoozed"
}
@test "unsnooze by ID removes entry from snoozed file" {
run_nag at "tomorrow 3pm" "take a break"
run_nag snooze 1
run_nag unsnooze 1
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unsnoozed [1]" ]]
! grep -q "^1" "${NAG_DIR}/snoozed" 2>/dev/null
}
@test "unsnooze all removes snoozed file" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag snooze all
run_nag unsnooze all
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unsnoozed all" ]]
[ ! -f "${NAG_DIR}/snoozed" ]
}
@test "unsnooze all when nothing snoozed says so" {
run_nag unsnooze all
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Nothing is snoozed" ]]
}
@test "unsnooze with no args fails" {
run_nag unsnooze
[ "${status}" -eq 1 ]
}
@test "unsnooze by tag removes snoozed entries for matching alarms" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag snooze work
run_nag unsnooze work
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unsnoozed [1]" ]]
! grep -q "^1" "${NAG_DIR}/snoozed" 2>/dev/null
}
@test "unsnooze by tag requires -f" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag snooze work
run "${_NAG}" unsnooze work < /dev/null
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unsnooze" ]]
[[ "${output}" =~ "-f" ]]
}
@test "unsnooze nonexistent ID fails" {
run_nag unsnooze 99
[ "${status}" -eq 1 ]
}
@test "unsnooze tag with no snoozed alarms fails" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run "${_NAG}" -f unsnooze work
[ "${status}" -eq 1 ]
[[ "${output}" =~ "not snoozed" ]]
}
@test "snooze replaces existing entry instead of duplicating" {
run_nag at "tomorrow 3pm" "take a break"
run_nag snooze 1
run_nag snooze 1
[ "${status}" -eq 0 ]
[ "$(grep -c "^1" "${NAG_DIR}/snoozed")" -eq 1 ]
}
@test "snooze by tag does not duplicate already-snoozed IDs" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag snooze 1
run_nag snooze work
[ "${status}" -eq 0 ]
[ "$(grep -c "^1" "${NAG_DIR}/snoozed")" -eq 1 ]
}
@test "unsnooze by tag removes ID-snoozed alarms with that tag" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag snooze 1
run_nag snooze work
run_nag unsnooze work
[ "${status}" -eq 0 ]
# Alarm should be fully unsnoozed, no entries left
if [ -f "${NAG_DIR}/snoozed" ]; then
[ ! -s "${NAG_DIR}/snoozed" ] || ! grep -q "^1" "${NAG_DIR}/snoozed"
fi
}

View file

@ -61,3 +61,60 @@ load test_helper
run "${_NAG}" -f stop work run "${_NAG}" -f stop work
[ "${status}" -eq 1 ] [ "${status}" -eq 1 ]
} }
@test "stop all removes all alarms with confirmation" {
run_nag at "tomorrow 3pm" "first"
run_nag at "tomorrow 4pm" "second"
run "${_NAG}" -f stop all
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Stopped" ]]
run_nag
[[ "${output}" =~ "Nothing to nag about" ]]
}
@test "stop all requires -f" {
run_nag at "tomorrow 3pm" "test"
run "${_NAG}" stop all < /dev/null
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Stop" ]]
[[ "${output}" =~ "-f" ]]
[ -s "${NAG_DIR}/alarms" ]
}
@test "stop all with no alarms fails" {
run "${_NAG}" -f stop all
[ "${status}" -eq 1 ]
}
@test "stop by ID cleans up snoozed metadata" {
run_nag at "tomorrow 3pm" "take a break"
run_nag snooze 1
[ -f "${NAG_DIR}/snoozed" ]
run_nag stop 1
[ "${status}" -eq 0 ]
if [ -f "${NAG_DIR}/snoozed" ]; then
! grep -q "^1" "${NAG_DIR}/snoozed"
fi
}
@test "stop by tag cleans up snoozed metadata" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag snooze 1
[ -f "${NAG_DIR}/snoozed" ]
run "${_NAG}" -f stop work
[ "${status}" -eq 0 ]
if [ -f "${NAG_DIR}/snoozed" ]; then
! grep -q "^1" "${NAG_DIR}/snoozed"
fi
}
@test "stop all cleans up snoozed metadata" {
run_nag at "tomorrow 3pm" "first"
run_nag at "tomorrow 4pm" "second"
run_nag snooze all
[ -f "${NAG_DIR}/snoozed" ]
run "${_NAG}" -f stop all
[ "${status}" -eq 0 ]
[ ! -f "${NAG_DIR}/snoozed" ] || [ ! -s "${NAG_DIR}/snoozed" ]
}

181
test/unskip.bats Normal file
View file

@ -0,0 +1,181 @@
#!/usr/bin/env bats
load test_helper
@test "unskip resets repeating alarm to next natural occurrence" {
run_nag every day "tomorrow 3pm" "daily task"
run_nag skip 1
run_nag skip 1
local _skipped_ts
_skipped_ts="$(cut -f3 "${NAG_DIR}/alarms")"
run_nag unskip 1
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unskipped [1]" ]]
[[ "${output}" =~ "daily task" ]]
local _new_ts
_new_ts="$(cut -f3 "${NAG_DIR}/alarms")"
(( _new_ts < _skipped_ts ))
(( _new_ts > $(date +%s) ))
}
@test "unskip one-shot alarm fails" {
run_nag at "tomorrow 3pm" "one-shot"
run_nag unskip 1
[ "${status}" -eq 1 ]
[[ "${output}" =~ "one-shot" ]]
}
@test "unskip with nonexistent ID fails" {
run_nag unskip 99
[ "${status}" -eq 1 ]
}
@test "unskip without args fails" {
run_nag unskip
[ "${status}" -eq 1 ]
}
@test "unskip by tag requires -f" {
run_nag every day "tomorrow 3pm" "daily work"
run_nag tag 1 work
run_nag skip 1
run "${_NAG}" unskip work < /dev/null
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unskip" ]]
[[ "${output}" =~ "-f" ]]
}
@test "unskip by tag with -f resets matching alarms" {
run_nag every day "tomorrow 3pm" "daily work"
run_nag tag 1 work
run_nag skip 1
run_nag skip 1
local _skipped_ts
_skipped_ts="$(cut -f3 "${NAG_DIR}/alarms")"
run "${_NAG}" -f unskip work
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unskipped" ]]
local _new_ts
_new_ts="$(cut -f3 "${NAG_DIR}/alarms")"
(( _new_ts < _skipped_ts ))
}
@test "unskip by tag with no repeating alarms fails" {
run_nag at "tomorrow 3pm" "one-shot"
run_nag tag 1 work
run "${_NAG}" -f unskip work
[ "${status}" -eq 1 ]
[[ "${output}" =~ "No repeating" ]]
}
@test "unskip by tag with no matching tag fails" {
run_nag every day "tomorrow 3pm" "daily task"
run "${_NAG}" -f unskip nonexistent
[ "${status}" -eq 1 ]
}
@test "unskip all resets all repeating alarms" {
run_nag every day "tomorrow 3pm" "daily one"
run_nag every day "tomorrow 4pm" "daily two"
run_nag skip 1
run_nag skip 1
run_nag skip 2
run_nag skip 2
run "${_NAG}" -f unskip all
[ "${status}" -eq 0 ]
[[ "${output}" =~ "Unskipped [1]" ]]
[[ "${output}" =~ "Unskipped [2]" ]]
}
@test "unskip yearly alarm preserves month and day" {
# Create a yearly alarm for a future date in the current year.
local _target_month=$(( $(date +%-m) + 1 ))
local _target_year=$(date +%Y)
if (( _target_month > 12 )); then
_target_month=1
_target_year=$((_target_year + 1))
fi
local _target_date="$(printf "%04d-%02d-15 14:00:00" "${_target_year}" "${_target_month}")"
local _target_ts="$(date -d "${_target_date}" +%s)"
# Write alarm directly: yearly rule, timestamp in the future.
write_alarm "$(printf "1\t\t%s\tyear\tyearly event" "${_target_ts}")"
# Skip it twice to push it 2 years out.
run_nag skip 1
run_nag skip 1
local _skipped_ts
_skipped_ts="$(cut -f3 "${NAG_DIR}/alarms")"
run_nag unskip 1
[ "${status}" -eq 0 ]
# Should come back to the original month/day, not today's date.
local _new_ts _new_month _new_day
_new_ts="$(cut -f3 "${NAG_DIR}/alarms")"
_new_month="$(date -d "@${_new_ts}" +%-m)"
_new_day="$(date -d "@${_new_ts}" +%-d)"
[ "${_new_month}" -eq "${_target_month}" ]
[ "${_new_day}" -eq 15 ]
(( _new_ts > $(date +%s) ))
(( _new_ts < _skipped_ts ))
}
@test "unskip monthly alarm preserves day of month" {
# Create a monthly alarm for the 20th at 2pm.
local _now_day=$(date +%-d)
local _target_day=20
local _target_ts
# If today is past the 20th, set it for the 20th next month.
if (( _now_day >= _target_day )); then
_target_ts="$(date -d "$(date +%Y-%m-${_target_day}) + 1 month 14:00:00" +%s)"
else
_target_ts="$(date -d "$(date +%Y-%m-${_target_day}) 14:00:00" +%s)"
fi
write_alarm "$(printf "1\t\t%s\tmonth\tmonthly event" "${_target_ts}")"
run_nag skip 1
run_nag skip 1
local _skipped_ts
_skipped_ts="$(cut -f3 "${NAG_DIR}/alarms")"
run_nag unskip 1
[ "${status}" -eq 0 ]
local _new_ts _new_day
_new_ts="$(cut -f3 "${NAG_DIR}/alarms")"
_new_day="$(date -d "@${_new_ts}" +%-d)"
[ "${_new_day}" -eq "${_target_day}" ]
(( _new_ts > $(date +%s) ))
(( _new_ts < _skipped_ts ))
}
@test "unskip weekday alarm lands on a weekday" {
run_nag every weekday "tomorrow 9am" "standup"
run_nag skip 1
run_nag skip 1
run_nag skip 1
run_nag unskip 1
[ "${status}" -eq 0 ]
local _new_ts _dow
_new_ts="$(cut -f3 "${NAG_DIR}/alarms")"
_dow="$(date -d "@${_new_ts}" +%u)"
# 1-5 = weekday
(( _dow >= 1 && _dow <= 5 ))
(( _new_ts > $(date +%s) ))
}
@test "unskip all with no repeating alarms fails" {
run_nag at "tomorrow 3pm" "one-shot"
run "${_NAG}" -f unskip all
[ "${status}" -eq 1 ]
}