edward

An extensible POSIX-compatible implementation of the ed(1) text editor

git clone https://git.8pit.net/edward.git

 1#!/bin/sh
 2
 3cd "$(dirname "$0")"
 4
 5if [ -n "$TMUX" ] || ! command -v tmux 1>/dev/null 2>&1; then
 6	echo "Skipping interactive tests" 1>&2
 7	exit 0
 8fi
 9
10EDWARD="${EDWARD:-$(pwd)/../../bin/edward}"
11[ -x "${EDWARD}" ] || \
12	abort "Couldn't find edward executable '${EDWARD}'."
13
14session="ed-test"
15cmd="sh -c 'stty -echo && tmux wait-for -S term-setup; env CHICKEN_REPOSITORY_PATH="${CHICKEN_REPOSITORY_PATH}" ${EDWARD}'"
16
17read_cmd() {
18	[ $# -eq 0 ] || return 1
19
20	# Terminate all lines with an Enter key unless the line escapes
21	# the newline with a '\' which is useful for sending control keys.
22	sed -e 's/\([^\]\)$/\1\nEnter/' -e 's/\\$//'
23}
24
25run_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 -C
38}
39
40ret=0
41for test in *; do
42	[ -d "${test}" ] || continue
43
44	name="${test##*/}"
45	printf "Running test case '%s': " "${name}"
46
47	run_tmux < "${test}/cmds" | awk '
48	# Filter out all empty lines between the last non-empty line and EOF.
49	{
50		output = output $0
51		if (length($0) != 0) {
52			print(output)
53			output = ""
54		}
55	}
56	' | cmp -s "${test}/expected" -
57
58	if [ $? -eq 0 ]; then
59		printf "OK\n"
60	else
61		printf "FAIL\n"
62		ret=1
63	fi
64
65	tmux kill-session -t "${session}"
66done
67
68exit "${ret}"