Do not install zsh completion by default
[abduco.git] / testsuite.sh
blobccb86fa10a4d56b2ff148ccd270c57eba5703f60
1 #!/bin/sh
3 ABDUCO="./abduco"
4 # set detach key explicitly in case it was changed in config.h
5 ABDUCO_OPTS="-e ^\\"
7 [ ! -z "$1" ] && ABDUCO="$1"
8 [ ! -x "$ABDUCO" ] && echo "usage: $0 /path/to/abduco" && exit 1
10 detach() {
11 sleep 1
12 printf "\x1c"
15 dvtm_cmd() {
16 printf "\a$1\n"
17 sleep 1
20 dvtm_session() {
21 sleep 1
22 dvtm_cmd 'c'
23 dvtm_cmd 'c'
24 dvtm_cmd 'c'
25 sleep 1
26 dvtm_cmd ' '
27 dvtm_cmd ' '
28 dvtm_cmd ' '
29 sleep 1
30 dvtm_cmd 'qq'
33 expected_abduco_prolog() {
34 printf "\e[?1049h\e[H"
37 # $1 => session-name, $2 => exit status
38 expected_abduco_epilog() {
39 echo "\e[?25h\e[?1049labduco: $1: session terminated with exit status $2"
42 # $1 => session-name, $2 => cmd to run
43 expected_abduco_attached_output() {
44 expected_abduco_prolog
46 expected_abduco_epilog "$1" $?
49 # $1 => session-name, $2 => cmd to run
50 expected_abduco_detached_output() {
51 expected_abduco_prolog
52 $2 >/dev/null 2>&1
53 expected_abduco_epilog "$1" $?
56 check_environment() {
57 [ "`$ABDUCO | wc -l`" -gt 1 ] && echo Abduco session exists && exit 1;
58 pgrep abduco && echo Abduco process exists && exit 1;
59 return 0;
62 test_non_existing_command() {
63 check_environment || return 1;
64 $ABDUCO -c test ./non-existing-command >/dev/null 2>&1
65 check_environment || return 1;
68 # $1 => session-name, $2 => command to execute
69 run_test_attached() {
70 check_environment || return 1;
72 local name="$1"
73 local cmd="$2"
74 local output="$name.out"
75 local output_expected="$name.expected"
77 echo -n "Running test attached: $name "
78 expected_abduco_attached_output "$name" "$cmd" > "$output_expected" 2>&1
79 $ABDUCO -c "$name" $cmd 2>&1 | sed 's/.$//' > "$output"
81 if diff -u "$output_expected" "$output" && check_environment; then
82 rm "$output" "$output_expected"
83 echo "OK"
84 return 0
85 else
86 echo "FAIL"
87 return 1
91 # $1 => session-name, $2 => command to execute
92 run_test_detached() {
93 check_environment || return 1;
95 local name="$1"
96 local cmd="$2"
97 local output="$name.out"
98 local output_expected="$name.expected"
100 echo -n "Running test detached: $name "
101 expected_abduco_detached_output "$name" "$cmd" > "$output_expected" 2>&1
103 if $ABDUCO -n "$name" $cmd >/dev/null 2>&1 && sleep 1 &&
104 $ABDUCO -a "$name" 2>&1 | sed 's/.$//' > "$output" &&
105 diff -u "$output_expected" "$output" && check_environment; then
106 rm "$output" "$output_expected"
107 echo "OK"
108 return 0
109 else
110 echo "FAIL"
111 return 1
115 # $1 => session-name, $2 => command to execute
116 run_test_attached_detached() {
117 check_environment || return 1;
119 local name="$1"
120 local cmd="$2"
121 local output="$name.out"
122 local output_expected="$name.expected"
124 echo -n "Running test: $name "
125 $cmd >/dev/null 2>&1
126 expected_abduco_epilog "$name" $? > "$output_expected" 2>&1
128 if detach | $ABDUCO $ABDUCO_OPTS -c "$name" $cmd >/dev/null 2>&1 && sleep 3 &&
129 $ABDUCO -a "$name" 2>&1 | tail -1 | sed 's/.$//' > "$output" &&
130 diff -u "$output_expected" "$output" && check_environment; then
131 rm "$output" "$output_expected"
132 echo "OK"
133 return 0
134 else
135 echo "FAIL"
136 return 1
140 run_test_dvtm() {
141 echo -n "Running dvtm test: "
142 if ! which dvtm >/dev/null 2>&1; then
143 echo "SKIPPED"
144 return 0;
147 local name="dvtm"
148 local output="$name.out"
149 local output_expected="$name.expected"
151 : > "$output_expected"
152 if dvtm_session | $ABDUCO -c "$name" > "$output" 2>&1 &&
153 diff -u "$output_expected" "$output" && check_environment; then
154 rm "$output" "$output_expected"
155 echo "OK"
156 return 0
157 else
158 echo "FAIL"
159 return 1
163 test_non_existing_command || echo "Execution of non existing command FAILED"
165 run_test_attached "seq" "seq 1 1000"
166 run_test_detached "seq" "seq 1 1000"
168 run_test_attached "false" "false"
169 run_test_detached "false" "false"
171 run_test_attached "true" "true"
172 run_test_detached "true" "true"
174 cat > exit-status.sh <<-EOT
175 #!/bin/sh
176 exit 42
178 chmod +x exit-status.sh
180 run_test_attached "exit-status" "./exit-status.sh"
181 run_test_detached "exit-status" "./exit-status.sh"
183 rm ./exit-status.sh
185 cat > long-running.sh <<-EOT
186 #!/bin/sh
187 echo Start
188 date
189 sleep 3
190 echo Hello World
191 sleep 3
192 echo End
193 date
194 exit 1
196 chmod +x long-running.sh
198 run_test_attached_detached "attach-detach" "./long-running.sh"
200 rm ./long-running.sh
202 run_test_dvtm