aboutsummaryrefslogtreecommitdiffstats
path: root/test-notifyctl.sh
blob: 7018e2aa9f1b7b3f5ad6e1a536b87b8fbb02d3e9 (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
#!/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 notifyctl. It runs the daemon and the CLI on a
# private session bus with a temporary runtime directory, so nothing here
# touches the live notification state.
#
# Usage: ./test-notifyctl.sh   (exit 0 = all passed)

set -u

here="$(cd "$(dirname "$0")" && pwd)"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT

pass=0
fail=0
check() {
    local label="$1" want="$2" got="$3"
    if [[ "$want" == "$got" ]]; then
        printf 'ok   %s\n' "$label"
        pass=$((pass + 1))
    else
        printf 'FAIL %s: want %q, got %q\n' "$label" "$want" "$got"
        fail=$((fail + 1))
    fi
}

go build -o "$tmp/notifyd" "$here/cmd/notifyd" || exit 1
go build -o "$tmp/notifyctl" "$here/cmd/notifyctl" || exit 1

mkdir -p "$tmp/run"
export XDG_RUNTIME_DIR="$tmp/run"
export PATH="$tmp:$PATH"

dbus-run-session -- bash -c '
    set -u
    "$1/notifyd" >"$1/daemon.log" 2>&1 & daemon=$!
    sleep 0.5
    notifyctl close-all >/dev/null 2>&1
    notify-send -a test -u normal "t1" "b1" || exit 3
    sleep 0.3
    echo "$(notifyctl list | grep -c "\"summary\": \"t1\"")"
    notifyctl close-all
    sleep 0.3
    echo "$(notifyctl list | grep -c "\"summary\": \"t1\"")"
    kill $daemon
' _ "$tmp" > "$tmp/out" 2>"$tmp/err"

check "list shows the notification" "1" "$(sed -n 1p "$tmp/out")"
check "close-all empties the live queue" "0" "$(sed -n 2p "$tmp/out")"
check "no errors on stderr" "" "$(cat "$tmp/err")"

printf '\n%d passed, %d failed\n' "$pass" "$fail"
[[ "$fail" -eq 0 ]]