Make client termination more robust by explicitly sending exit messages
[abduco.git] / testsuite.sh
blob1702fcd7c18c1e54de352d563e1a9274f60767a6
1 #!/bin/bash
3 ABDUCO="./abduco"
5 detach() {
6 sleep 1
7 printf "\x1c"
10 dvtm_cmd() {
11 printf "\a$1\n"
12 sleep 1
15 dvtm_session() {
16 sleep 1
17 dvtm_cmd 'c'
18 dvtm_cmd 'c'
19 dvtm_cmd 'c'
20 sleep 1
21 dvtm_cmd ' '
22 dvtm_cmd ' '
23 dvtm_cmd ' '
24 sleep 1
25 dvtm_cmd 'q'
28 # $1 => session-name, $2 => exit status
29 expected_abduco_output() {
30 echo "\e[?25h\e[999Habduco: $1: session terminated with exit status $2"
33 check_environment() {
34 [ "`$ABDUCO | wc -l`" -gt 1 ] && echo Abduco session exists && exit 1;
35 pgrep abduco && echo Abduco process exists && exit 1;
36 return 0;
39 test_non_existing_command() {
40 check_environment || return 1;
41 $ABDUCO -c test ./non-existing-command &> /dev/null
42 check_environment || return 1;
45 # $1 => session-name, $2 => command to execute
46 run_test_attached() {
47 check_environment || return 1;
49 local name="$1"
50 local cmd="$2"
51 local output="$name.out"
52 local output_expected="$name.expected"
54 echo -n "Running test attached: $name "
55 $cmd &> "$output_expected"
56 expected_abduco_output "$name" $? >> "$output_expected"
57 $ABDUCO -c "$name" $cmd 2>&1 | head -n -1 | sed 's/.$//' > "$output"
58 if diff -u "$output_expected" "$output" && check_environment; then
59 rm "$output" "$output_expected"
60 echo "OK"
61 return 0
62 else
63 echo "FAIL"
64 return 1
68 # $1 => session-name, $2 => command to execute
69 run_test_detached() {
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 detached: $name "
78 $cmd &> /dev/null
79 expected_abduco_output "$name" $? > "$output_expected"
81 if $ABDUCO -n "$name" $cmd &> /dev/null && sleep 1 &&
82 $ABDUCO -a "$name" 2>&1 | head -n -1 | sed 's/.$//' > "$output" &&
83 diff -u "$output_expected" "$output" && check_environment; then
84 rm "$output" "$output_expected"
85 echo "OK"
86 return 0
87 else
88 echo "FAIL"
89 return 1
93 # $1 => session-name, $2 => command to execute
94 run_test_attached_detached() {
95 check_environment || return 1;
97 local name="$1"
98 local cmd="$2"
99 local output="$name.out"
100 local output_expected="$name.expected"
102 echo -n "Running test: $name "
103 $cmd &> /dev/null
104 expected_abduco_output "$name" $? > "$output_expected"
106 if detach | $ABDUCO -c "$name" $cmd &> /dev/null && sleep 3 &&
107 $ABDUCO -a "$name" 2>&1 | head -n -1 | tail -1 | sed 's/.$//' > "$output" &&
108 diff -u "$output_expected" "$output" && check_environment; then
109 rm "$output" "$output_expected"
110 echo "OK"
111 return 0
112 else
113 echo "FAIL"
114 return 1
118 run_test_dvtm() {
119 echo -n "Running dvtm test: "
120 if ! which dvtm &> /dev/null; then
121 echo "SKIPPED"
122 return 0;
125 local name="dvtm"
126 local output="$name.out"
127 local output_expected="$name.expected"
129 echo exit | dvtm &> /dev/null
130 expected_abduco_output "$name" $? > "$output_expected"
131 local len=`wc -c "$output_expected" | awk '{ print $1 }'`
132 len=$((len+1))
133 if dvtm_session | $ABDUCO -c "$name" 2>&1 | head -n -1 | tail -c $len | sed 's/.$//' > "$output" &&
134 diff -u "$output_expected" "$output" && check_environment; then
135 rm "$output" "$output_expected"
136 echo "OK"
137 return 0
138 else
139 echo "FAIL"
140 return 1
144 test_non_existing_command || echo "Execution of non existing command FAILED"
146 run_test_attached "seq" "seq 1 1000"
147 run_test_detached "seq" "seq 1 1000"
149 run_test_attached "false" "false"
150 run_test_detached "false" "false"
152 run_test_attached "true" "true"
153 run_test_detached "true" "true"
155 cat > exit-status.sh <<-EOT
156 #!/bin/sh
157 exit 42
159 chmod +x exit-status.sh
161 run_test_attached "exit-status" "./exit-status.sh"
162 run_test_detached "exit-status" "./exit-status.sh"
164 rm ./exit-status.sh
166 cat > long-running.sh <<-EOT
167 #!/bin/sh
168 echo Start
169 date
170 sleep 3
171 echo Hello World
172 sleep 3
173 echo End
174 date
175 exit 1
177 chmod +x long-running.sh
179 run_test_attached_detached "attach-detach" "./long-running.sh"
181 rm ./long-running.sh
183 run_test_dvtm