diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-19 10:23:45 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-19 10:23:45 +0200 |
| commit | 31f1c15112748eecbdc3ad33891b0c3629504fe7 (patch) | |
| tree | e674ef5fe890e64c274029d86a30956876173f1d /examples/tools/test-mode.sh | |
| parent | ed70f032e30ae13485610a9027371d22d3cab14e (diff) | |
| download | desktop-assistant-31f1c15112748eecbdc3ad33891b0c3629504fe7.tar.gz desktop-assistant-31f1c15112748eecbdc3ad33891b0c3629504fe7.zip | |
mode tool: read and set the desktop modes
dnd, presentation, nolock and quiet through statusctl. The output is
read back after a set, so a set that did not land is not reported as
done, and a running game's hold on presentation is named. test-mode.sh
checks it against a scratch runtime dir.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'examples/tools/test-mode.sh')
| -rwxr-xr-x | examples/tools/test-mode.sh | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/tools/test-mode.sh b/examples/tools/test-mode.sh new file mode 100755 index 0000000..e273f88 --- /dev/null +++ b/examples/tools/test-mode.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# desktop-assistant tool check: mode.sh against a scratch runtime dir. +# 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. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# test-mode.sh: the real modes are never touched, XDG_RUNTIME_DIR is a +# throwaway directory. Prints "ok" or one FAIL line per broken case. + +set -u +here=$(dirname "$0") +XDG_RUNTIME_DIR=$(mktemp -d) +export XDG_RUNTIME_DIR +trap 'rm -rf "$XDG_RUNTIME_DIR"' EXIT +fail=0 +check() { [ "$2" = "$3" ] || { echo "FAIL $1: got '$2', want '$3'"; fail=1; }; } + +check "read missing" "$("$here/mode.sh" dnd "")" "dnd: off" +check "set on" "$("$here/mode.sh" dnd 1)" "dnd: on" +check "file written" "$(cat "$XDG_RUNTIME_DIR/status.dnd")" "1" +check "set off" "$("$here/mode.sh" dnd 0)" "dnd: off" +"$here/mode.sh" dnd yes >/dev/null 2>&1; check "bad value exit" "$?" "1" +"$here/mode.sh" bogus 1 >/dev/null 2>&1; check "bad mode exit" "$?" "1" +echo 1 > "$XDG_RUNTIME_DIR/status.gaming" +check "gaming hold" "$("$here/mode.sh" presentation 0)" \ + "presentation: on (held on by a running game; manual setting off)" +[ $fail = 0 ] && echo "ok" +exit $fail |
