#!/bin/bash # # Copyright (C) 2026 Danilo M. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # Usage: ./test-notify-snooze.sh set -u here="$(cd "$(dirname "$0")" && pwd)" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT export XDG_RUNTIME_DIR="$tmp" export HOME="$tmp/home" mkdir -p "$HOME/.local/state" pass=0; fail=0 check() { if [[ "$2" == "$3" ]]; then echo "ok $1"; pass=$((pass+1)); else echo "FAIL $1: want $2 got $3"; fail=$((fail+1)); fi; } before=$(date +%s) bash "$here/scripts/notify-snooze.sh" 30 snooze="$tmp/notifyd/snooze" check "writes the snooze file" "yes" "$([[ -f "$snooze" ]] && echo yes)" delta=$(( $(cat "$snooze") - before )) check "is about 30 minutes out" "yes" "$([[ $delta -ge 1700 && $delta -le 1900 ]] && echo yes)" check "remembers the minutes" "30" "$(cat "$HOME/.local/state/notify-snooze.minutes")" bash "$here/scripts/notify-snooze.sh" off check "off removes the file" "no" "$([[ -f "$snooze" ]] && echo yes || echo no)" bash "$here/scripts/notify-snooze.sh" nope >/dev/null 2>&1 check "rejects a bad argument" "1" "$?" printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]]