Use more descriptive execvp error message
[abduco.git] / testsuite.sh
blobec7b943dff38e3fcbf7fe145b65bf8f17f50e91f
1 #!/bin/bash
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 'q'
33 # $1 => session-name, $2 => exit status
34 expected_abduco_output() {
35 echo "\e[?25h\e[999Habduco: $1: session terminated with exit status $2"
38 check_environment() {
39 [ "`$ABDUCO | wc -l`" -gt 1 ] && echo Abduco session exists && exit 1;
40 pgrep abduco && echo Abduco process exists && exit 1;
41 return 0;
44 test_non_existing_command() {
45 check_environment || return 1;
46 $ABDUCO -c test ./non-existing-command &> /dev/null
47 check_environment || return 1;
50 # $1 => session-name, $2 => command to execute
51 run_test_attached() {
52 check_environment || return 1;
54 local name="$1"
55 local cmd="$2"
56 local output="$name.out"
57 local output_expected="$name.expected"
59 echo -n "Running test attached: $name "
60 $cmd &> "$output_expected"
61 expected_abduco_output "$name" $? >> "$output_expected"
62 $ABDUCO -c "$name" $cmd 2>&1 | head -n -1 | sed 's/.$//' > "$output"
63 if diff -u "$output_expected" "$output" && check_environment; then
64 rm "$output" "$output_expected"
65 echo "OK"
66 return 0
67 else
68 echo "FAIL"
69 return 1
73 # $1 => session-name, $2 => command to execute
74 run_test_detached() {
75 check_environment || return 1;
77 local name="$1"
78 local cmd="$2"
79 local output="$name.out"
80 local output_expected="$name.expected"
82 echo -n "Running test detached: $name "
83 $cmd &> /dev/null
84 expected_abduco_output "$name" $? > "$output_expected"
86 if $ABDUCO -n "$name" $cmd &> /dev/null && sleep 1 &&
87 $ABDUCO -a "$name" 2>&1 | head -n -1 | sed 's/.$//' > "$output" &&
88 diff -u "$output_expected" "$output" && check_environment; then
89 rm "$output" "$output_expected"
90 echo "OK"
91 return 0
92 else
93 echo "FAIL"
94 return 1
98 # $1 => session-name, $2 => command to execute
99 run_test_attached_detached() {
100 check_environment || return 1;
102 local name="$1"
103 local cmd="$2"
104 local output="$name.out"
105 local output_expected="$name.expected"
107 echo -n "Running test: $name "
108 $cmd &> /dev/null
109 expected_abduco_output "$name" $? > "$output_expected"
111 if detach | $ABDUCO $ABDUCO_OPTS -c "$name" $cmd &> /dev/null && sleep 3 &&
112 $ABDUCO -a "$name" 2>&1 | head -n -1 | tail -1 | sed 's/.$//' > "$output" &&
113 diff -u "$output_expected" "$output" && check_environment; then
114 rm "$output" "$output_expected"
115 echo "OK"
116 return 0
117 else
118 echo "FAIL"
119 return 1
123 run_test_dvtm() {
124 echo -n "Running dvtm test: "
125 if ! which dvtm &> /dev/null; then
126 echo "SKIPPED"
127 return 0;
130 local name="dvtm"
131 local output="$name.out"
132 local output_expected="$name.expected"
134 echo exit | dvtm &> /dev/null
135 expected_abduco_output "$name" $? > "$output_expected"
136 local len=`wc -c "$output_expected" | awk '{ print $1 }'`
137 len=$((len+1))
138 if dvtm_session | $ABDUCO -c "$name" 2>&1 | head -n -1 | tail -c $len | sed 's/.$//' > "$output" &&
139 diff -u "$output_expected" "$output" && check_environment; then
140 rm "$output" "$output_expected"
141 echo "OK"
142 return 0
143 else
144 echo "FAIL"
145 return 1
149 test_non_existing_command || echo "Execution of non existing command FAILED"
151 run_test_attached "seq" "seq 1 1000"
152 run_test_detached "seq" "seq 1 1000"
154 run_test_attached "false" "false"
155 run_test_detached "false" "false"
157 run_test_attached "true" "true"
158 run_test_detached "true" "true"
160 cat > exit-status.sh <<-EOT
161 #!/bin/sh
162 exit 42
164 chmod +x exit-status.sh
166 run_test_attached "exit-status" "./exit-status.sh"
167 run_test_detached "exit-status" "./exit-status.sh"
169 rm ./exit-status.sh
171 cat > long-running.sh <<-EOT
172 #!/bin/sh
173 echo Start
174 date
175 sleep 3
176 echo Hello World
177 sleep 3
178 echo End
179 date
180 exit 1
182 chmod +x long-running.sh
184 run_test_attached_detached "attach-detach" "./long-running.sh"
186 rm ./long-running.sh
188 run_test_dvtm