#!/usr/bin/env bash # Smoke tests for the front ends. Run: tests/smoke.sh # # These exist because every bug found in the first review of this repo was in # the shell and Python around the QML, not in the QML: a --format field that # raised, an installer that aborted where it said it was continuing, an error # path that exited non-zero so waybar hid the message it was trying to show. # None of it was covered by anything. set -uo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" waybar="$root/bin/horologion-waybar" install="$root/bin/horologion-install" pass=0 fail=0 tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; } bad() { fail=$((fail+1)); printf ' FAIL %s\n %s\n' "$1" "${2:-}"; } check() { # check local name="$1" want="$2"; shift 2 local out; out="$("$@" 2>&1)"; local got=$? [ "$got" = "$want" ] || { bad "$name" "exit $got, wanted $want"; return; } ok "$name" } json() { # json -- stdout must parse local name="$1"; shift local out; out="$("$@" 2>/dev/null)" if printf '%s' "$out" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null then ok "$name"; else bad "$name" "not JSON: ${out:0:80}"; fi } echo echo " waybar module" command -v typikon >/dev/null 2>&1 || { echo " SKIP: typikon not on PATH"; exit 77; } json "plain run emits JSON" "$waybar" json "an unknown --format field" "$waybar" --format '{nosuchfield}' json "a positional --format field" "$waybar" --format '{0}' json "an unclosed --format brace" "$waybar" --format '{' json "--no-emoji" "$waybar" --no-emoji json "--days 1" "$waybar" --days 1 json "an unknown jurisdiction" "$waybar" -j atlantis # waybar hides a module whose script exits non-zero, so every path must be 0 # or the error JSON is never read. # A PATH that still has an interpreter but no typikon -- typikon installs to # ~/.local/bin, which this leaves out. Emptying PATH entirely would only prove # that the shebang cannot find python3. check "exit 0 when typikon is missing" 0 env PATH=/usr/bin:/bin "$waybar" json "JSON when typikon is missing" env PATH=/usr/bin:/bin "$waybar" check "exit 0 on a bad jurisdiction" 0 "$waybar" -j atlantis out="$("$waybar" --format '{daysToPascha}' 2>/dev/null)" case "$out" in *'"text": ""'*) bad "a zero field is not blanked" "daysToPascha rendered empty" ;; *) ok "a zero field is not blanked" ;; esac echo echo " installer" check "--help without typikon" 0 env PATH=/usr/bin:/bin "$install" --help check "an unknown subcommand" 2 "$install" nonsense mkdir -p "$tmp/a/.config/quickshell" "$tmp/a/.config/waybar" check "a clean run with eww absent" 0 env HOME="$tmp/a" XDG_CONFIG_HOME="$tmp/a/.config" "$install" all mkdir -p "$tmp/b/.local/bin" "$tmp/b/.config"; : > "$tmp/b/.local/bin/horologion-waybar" check "a real file at the target" 1 env HOME="$tmp/b" XDG_CONFIG_HOME="$tmp/b/.config" "$install" all [ -L "$tmp/a/.local/bin/horologion-waybar" ] \ && ok "the clean run actually linked" || bad "the clean run actually linked" echo echo " syntax" check "installer parses" 0 bash -n "$install" check "waybar module compiles" 0 python3 -m py_compile "$waybar" rm -rf "$root/bin/__pycache__" for f in "$root"/quickshell/*.qml "$root"/quickshell/*/*.qml; do [ -f "$f" ] || continue grep -q . "$f" || bad "empty QML: $f" done ok "QML files are non-empty" echo printf ' %d passed, %d failed\n\n' "$pass" "$fail" [ "$fail" -eq 0 ]