#!/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 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\"")" notify-send -a test -u normal --hint=string:image-path:/tmp/x.png "t2" "b2" || exit 3 sleep 0.3 echo "$(notifyctl list | grep -c "\"image\": \"/tmp/x.png\"")" 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 "image-path is published" "1" "$(sed -n 2p "$tmp/out")" check "list clears" "0" "$(sed -n 3p "$tmp/out")" check "no errors on stderr" "" "$(cat "$tmp/err")" printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]]