blob: 8be456cf72c2d38ea56f2f983332259d84e7594f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/bash
#
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# 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"
# A config with the two traps in it: a key containing dots, and a folder
# value containing a bracket. Both are real shapes from qtmaildir.conf, with
# placeholder names.
read -r -d '' fixture <<'EOF'
[general]
theme = dark
[account.simple]
label = Simple
color = #112233
[account.provider-first.last]
folder = [Gmail]/Bozze
label = Dotted
color = #445566
[account.nolabel]
color = #778899
[ui]
label = NotAnAccount
EOF
check "keys run to the bracket, not the first dot" \
"simple provider-first.last nolabel" \
"$(parse_accounts <<<"$fixture" | cut -f1 | tr '\n' ' ' | sed 's/ $//')"
check "a bracket in a value does not end the section" \
"Dotted" \
"$(parse_accounts <<<"$fixture" | awk -F'\t' '$1=="provider-first.last"{print $2}')"
check "a missing label falls back to the key" \
"nolabel" \
"$(parse_accounts <<<"$fixture" | awk -F'\t' '$1=="nolabel"{print $2}')"
check "a non-account section is not an account" \
"" \
"$(parse_accounts <<<"$fixture" | awk -F'\t' '$1=="ui"{print $2}')"
printf '\n%d passed, %d failed\n' "$pass" "$fail"
[[ "$fail" -eq 0 ]]
|