about summary refs log tree commit diff stats
path: root/tests/infrastructure/driver.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/infrastructure/driver.sh')
-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
+}