aboutsummaryrefslogtreecommitdiffstats
path: root/tests/infrastructure/driver.sh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-23 10:24:56 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-23 10:25:15 +0100
commit55b3baa54a9b5253a3de90f1917808582cd5fa94 (patch)
tree132b997514bfb50668c92d3e5d72f45e01dfee27 /tests/infrastructure/driver.sh
parentbuild(flake): Update (diff)
downloadnixos-config-55b3baa54a9b5253a3de90f1917808582cd5fa94.zip
tests(tests): Initialize infrastructure and documentation for it
Diffstat (limited to '')
-rw-r--r--tests/infrastructure/driver.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/infrastructure/driver.sh b/tests/infrastructure/driver.sh
new file mode 100644
index 00000000..52f7d3ad
--- /dev/null
+++ b/tests/infrastructure/driver.sh
@@ -0,0 +1,72 @@
+#! /usr/bin/env sh
+set -e
+
+msg() {
+ if [ "$#" -ne 0 ]; then
+ echo "$@" | tee --append "$__TEST_EVAL_LOG_FILE" >&2
+ else
+ cat | tee --append "$__TEST_EVAL_LOG_FILE" >&2
+ fi
+}
+
+__test_eval() {
+ tmux="$__TEST_TMUX"
+ tpane="$__TEST_TMUX_PANE"
+ file="$1"
+
+ awk --file "$__TEST_EVAL_AWK_CLEAN_FILE" "$file" | while read -r cmd args; do
+ case "$cmd" in
+ "Type")
+ msg "Sending keys to application '$args'.."
+ "$tmux" send-keys -t "$tpane": "$args"
+ ;;
+ "Sleep")
+ msg "Sleeping for '$args' seconds.."
+ sleep "$args"
+ ;;
+ "Expect" | "ExpectNot")
+ msg "Trying to match regex ('$args') for currently visible content.."
+
+ matched=""
+ if "$tmux" capture-pane -t "$tpane" -p -S 0 -E - | grep "$args"; then
+ matched=true
+ else
+ matched=false
+ fi
+
+ case "$cmd" in
+ "Expect")
+ if [ "$matched" = true ]; then
+ msg "Regex matched."
+ else
+ msg "Failed to find string, matched by regex '$args' on the screen"
+ msg current screen:
+ "$tmux" capture-pane -t "$tpane" -p -S 0 -E - | msg
+
+ exit 1
+ fi
+ ;;
+ "ExpectNot")
+ if [ "$matched" = false ]; then
+ msg "Regex successfully not matched."
+ else
+ msg "Found to find string, matched by regex '$args' on the screen. But expected none"
+ msg current screen:
+ "$tmux" capture-pane -t "$tpane" -p -S 0 -E - | msg
+
+ exit 1
+ fi
+ ;;
+ *)
+ msg "Entered unrechable code. This is a bug."
+ exit 1
+ ;;
+ esac
+ ;;
+ *)
+ msg "Unrecognized command: '$cmd'"
+ exit 1
+ ;;
+ esac
+ done
+}