testsuite.sh (4567B)
1 #!/bin/sh 2 3 ABDUCO="./abduco" 4 # set detach key explicitly in case it was changed in config.h 5 ABDUCO_OPTS="-e ^\\" 6 7 [ ! -z "$1" ] && ABDUCO="$1" 8 [ ! -x "$ABDUCO" ] && echo "usage: $0 /path/to/abduco" && exit 1 9 10 TESTS_OK=0 11 TESTS_RUN=0 12 13 detach() { 14 sleep 1 15 printf "" 16 } 17 18 dvtm_cmd() { 19 printf "$1\n" 20 sleep 1 21 } 22 23 dvtm_session() { 24 sleep 1 25 dvtm_cmd 'c' 26 dvtm_cmd 'c' 27 dvtm_cmd 'c' 28 sleep 1 29 dvtm_cmd ' ' 30 dvtm_cmd ' ' 31 dvtm_cmd ' ' 32 sleep 1 33 dvtm_cmd 'qq' 34 } 35 36 expected_abduco_prolog() { 37 printf "[?1049h[H" 38 } 39 40 # $1 => session-name, $2 => exit status 41 expected_abduco_epilog() { 42 echo "[?25h[?1049labduco: $1: session terminated with exit status $2" 43 } 44 45 # $1 => session-name, $2 => cmd to run 46 expected_abduco_attached_output() { 47 expected_abduco_prolog 48 $2 49 expected_abduco_epilog "$1" $? 50 } 51 52 # $1 => session-name, $2 => cmd to run 53 expected_abduco_detached_output() { 54 expected_abduco_prolog 55 $2 >/dev/null 2>&1 56 expected_abduco_epilog "$1" $? 57 } 58 59 check_environment() { 60 [ "`$ABDUCO | wc -l`" -gt 1 ] && echo Abduco session exists && exit 1; 61 pgrep abduco && echo Abduco process exists && exit 1; 62 return 0; 63 } 64 65 test_non_existing_command() { 66 check_environment || return 1; 67 $ABDUCO -c test ./non-existing-command >/dev/null 2>&1 68 check_environment || return 1; 69 } 70 71 # $1 => session-name, $2 => command to execute 72 run_test_attached() { 73 check_environment || return 1; 74 75 local name="$1" 76 local cmd="$2" 77 local output="$name.out" 78 local output_expected="$name.expected" 79 80 TESTS_RUN=$((TESTS_RUN + 1)) 81 echo -n "Running test attached: $name " 82 expected_abduco_attached_output "$name" "$cmd" > "$output_expected" 2>&1 83 84 if $ABDUCO -c "$name" $cmd 2>&1 | sed 's/.$//' > "$output" && sleep 1 && 85 diff -u "$output_expected" "$output" && check_environment; then 86 rm "$output" "$output_expected" 87 TESTS_OK=$((TESTS_OK + 1)) 88 echo "OK" 89 return 0 90 else 91 echo "FAIL" 92 return 1 93 fi 94 } 95 96 # $1 => session-name, $2 => command to execute 97 run_test_detached() { 98 check_environment || return 1; 99 100 local name="$1" 101 local cmd="$2" 102 local output="$name.out" 103 local output_expected="$name.expected" 104 105 TESTS_RUN=$((TESTS_RUN + 1)) 106 echo -n "Running test detached: $name " 107 expected_abduco_detached_output "$name" "$cmd" > "$output_expected" 2>&1 108 109 if $ABDUCO -n "$name" $cmd >/dev/null 2>&1 && sleep 1 && 110 $ABDUCO -a "$name" 2>&1 | sed 's/.$//' > "$output" && 111 diff -u "$output_expected" "$output" && check_environment; then 112 rm "$output" "$output_expected" 113 TESTS_OK=$((TESTS_OK + 1)) 114 echo "OK" 115 return 0 116 else 117 echo "FAIL" 118 return 1 119 fi 120 } 121 122 # $1 => session-name, $2 => command to execute 123 run_test_attached_detached() { 124 check_environment || return 1; 125 126 local name="$1" 127 local cmd="$2" 128 local output="$name.out" 129 local output_expected="$name.expected" 130 131 TESTS_RUN=$((TESTS_RUN + 1)) 132 echo -n "Running test: $name " 133 $cmd >/dev/null 2>&1 134 expected_abduco_epilog "$name" $? > "$output_expected" 2>&1 135 136 if detach | $ABDUCO $ABDUCO_OPTS -c "$name" $cmd >/dev/null 2>&1 && sleep 3 && 137 $ABDUCO -a "$name" 2>&1 | tail -1 | sed 's/.$//' > "$output" && 138 diff -u "$output_expected" "$output" && check_environment; then 139 rm "$output" "$output_expected" 140 TESTS_OK=$((TESTS_OK + 1)) 141 echo "OK" 142 return 0 143 else 144 echo "FAIL" 145 return 1 146 fi 147 } 148 149 run_test_dvtm() { 150 echo -n "Running dvtm test: " 151 if ! which dvtm >/dev/null 2>&1; then 152 echo "SKIPPED" 153 return 0; 154 fi 155 156 TESTS_RUN=$((TESTS_RUN + 1)) 157 local name="dvtm" 158 local output="$name.out" 159 local output_expected="$name.expected" 160 161 : > "$output_expected" 162 if dvtm_session | $ABDUCO -c "$name" > "$output" 2>&1 && 163 diff -u "$output_expected" "$output" && check_environment; then 164 rm "$output" "$output_expected" 165 TESTS_OK=$((TESTS_OK + 1)) 166 echo "OK" 167 return 0 168 else 169 echo "FAIL" 170 return 1 171 fi 172 } 173 174 test_non_existing_command || echo "Execution of non existing command FAILED" 175 176 run_test_attached "awk" "awk 'BEGIN {for(i=1;i<=1000;i++) print i}'" 177 run_test_detached "awk" "awk 'BEGIN {for(i=1;i<=1000;i++) print i}'" 178 179 run_test_attached "false" "false" 180 run_test_detached "false" "false" 181 182 run_test_attached "true" "true" 183 run_test_detached "true" "true" 184 185 cat > exit-status.sh <<-EOT 186 #!/bin/sh 187 exit 42 188 EOT 189 chmod +x exit-status.sh 190 191 run_test_attached "exit-status" "./exit-status.sh" 192 run_test_detached "exit-status" "./exit-status.sh" 193 194 rm ./exit-status.sh 195 196 cat > long-running.sh <<-EOT 197 #!/bin/sh 198 echo Start 199 date 200 sleep 3 201 echo Hello World 202 sleep 3 203 echo End 204 date 205 exit 1 206 EOT 207 chmod +x long-running.sh 208 209 run_test_attached_detached "attach-detach" "./long-running.sh" 210 211 rm ./long-running.sh 212 213 run_test_dvtm 214 215 [ $TESTS_OK -eq $TESTS_RUN ]