Files
nocal/tests/cli_recovery_test.sh

84 lines
2.1 KiB
Bash

#!/bin/sh
set -eu
if [ "$#" -ne 1 ]; then
echo "usage: cli_recovery_test.sh /path/to/nocal" >&2
exit 2
fi
nocal=$1
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/nocal-cli-recovery.XXXXXX")
trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM
calendar=$tmpdir/calendar.ics
backup=$calendar.bak
expected=$tmpdir/expected.ics
cat >"$calendar" <<'EOF'
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Nocal CLI test//EN
BEGIN:VEVENT
UID:current@nocal.test
DTSTART:20260717T090000
DTEND:20260717T100000
SUMMARY:Current appointment
END:VEVENT
END:VCALENDAR
EOF
cat >"$backup" <<'EOF'
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Nocal CLI test//EN
BEGIN:VEVENT
UID:backup@nocal.test
DTSTART:20260718T140000
DTEND:20260718T150000
SUMMARY:Recovered appointment
END:VEVENT
END:VCALENDAR
EOF
cp "$backup" "$expected"
help=$("$nocal" --help)
case $help in
*--restore-backup*"u undoes the last change, Ctrl-R redoes it"*) ;;
*)
echo "help does not document recovery and undo/redo" >&2
exit 1
;;
esac
if "$nocal" --restore-backup --demo --calendar "$calendar" >"$tmpdir/out" 2>"$tmpdir/err"; then
echo "--restore-backup with --demo unexpectedly succeeded" >&2
exit 1
fi
grep -F -- "--restore-backup cannot be combined with --demo" "$tmpdir/err" >/dev/null
if "$nocal" --restore-backup --print --calendar "$calendar" >"$tmpdir/out" 2>"$tmpdir/err"; then
echo "--restore-backup with --print unexpectedly succeeded" >&2
exit 1
fi
grep -F -- "--restore-backup cannot be combined with --print" "$tmpdir/err" >/dev/null
missing_calendar=$tmpdir/missing-backup.ics
cp "$calendar" "$missing_calendar"
cp "$missing_calendar" "$tmpdir/missing-before.ics"
if "$nocal" --restore-backup --calendar "$missing_calendar" \
>"$tmpdir/out" 2>"$tmpdir/err"; then
echo "restore without an adjacent backup unexpectedly succeeded" >&2
exit 1
fi
cmp "$missing_calendar" "$tmpdir/missing-before.ics"
actual=$("$nocal" --restore-backup --calendar "$calendar")
expected_summary="Restored backup $backup to $calendar"
if [ "$actual" != "$expected_summary" ]; then
echo "unexpected restore summary: $actual" >&2
exit 1
fi
cmp "$calendar" "$expected"
cmp "$backup" "$expected"