#!/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. # # The one runnable check for mail-notify.sh. No framework: it sources the # script as a library and asserts on the pure functions, the ones that take # text and print text. Nothing here calls notmuch, dunstify or inotify, which # is why it runs in milliseconds and needs no mail to arrive. # # Usage: ./test-mail-notify.sh (exit 0 = all passed) set -u MAIL_NOTIFY_LIB=1 . "$(dirname "$0")/mail-notify.sh" pass=0 fail=0 # Compares two strings and reports. Multi-line values are printed with their # newlines intact, because half the assertions here are about line structure. check() { local name="$1" want="$2" got="$3" if [[ "$want" == "$got" ]]; then pass=$((pass + 1)) else fail=$((fail + 1)) printf 'FAIL: %s\n want: %s\n got: %s\n' "$name" "$want" "$got" fi } check "library guard does not run main" "loaded" "loaded" printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]]