#! /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 ;; "SetGolden") msg "Trying to set '$args' as golden file." [ -f "$args" ] || { msg "Argument is not a file!" exit 1 } printf "%s" "$args" >"$__TEST_EVAL_GOLDEN_FILE" msg "Set golden file to: '$args'" ;; *) msg "Unrecognized command: '$cmd'" exit 1 ;; esac done }