1#!/bin/sh23cd "$(dirname "$0")"45if [ -n "$TMUX" ] || ! command -v tmux 1>/dev/null 2>&1; then6 echo "Skipping interactive tests" 1>&27 exit 08fi910EDWARD="${EDWARD:-$(pwd)/../../bin/edward}"11[ -x "${EDWARD}" ] || \12 abort "Couldn't find edward executable '${EDWARD}'."1314session="ed-test"15cmd="sh -c 'stty -echo && tmux wait-for -S term-setup; env CHICKEN_REPOSITORY_PATH="${CHICKEN_REPOSITORY_PATH}" ${EDWARD}'"1617read_cmd() {18 [ $# -eq 0 ] || return 11920 # Terminate all lines with an Enter key unless the line escapes21 # the newline with a '\' which is useful for sending control keys.22 sed -e 's/\([^\]\)$/\1\nEnter/' -e 's/\\$//'23}2425run_tmux() {26 tmux new-session -d -s "${session}" "${cmd}" \; \27 set-option -t "${session}" -w remain-on-exit "on" \; \28 set-option -t "${session}" -w remain-on-exit-format "" \; \29 \30 set-hook -w pane-died \31 "wait-for -S exit-channel" \; \32 \33 wait-for term-setup \; \34 send-keys -t "${session}" $(read_cmd) \; \35 \36 wait-for exit-channel \; \37 capture-pane -S - -E - -t "${session}" -p -C38}3940ret=041for test in *; do42 [ -d "${test}" ] || continue4344 name="${test##*/}"45 printf "Running test case '%s': " "${name}"4647 run_tmux < "${test}/cmds" | awk '48 # Filter out all empty lines between the last non-empty line and EOF.49 {50 output = output $051 if (length($0) != 0) {52 print(output)53 output = ""54 }55 }56 ' | cmp -s "${test}/expected" -5758 if [ $? -eq 0 ]; then59 printf "OK\n"60 else61 printf "FAIL\n"62 ret=163 fi6465 tmux kill-session -t "${session}"66done6768exit "${ret}"