From 5a88eee2910c13bac1b4aca4b54a6ea6adbe62ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 18 Jun 2014 14:30:31 +0200 Subject: [PATCH] Add rudimentary test suite --- testsuite.sh | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100755 testsuite.sh diff --git a/testsuite.sh b/testsuite.sh new file mode 100755 index 0000000..b38849c --- /dev/null +++ b/testsuite.sh @@ -0,0 +1,132 @@ +#!/bin/bash + +ABDUCO="./abduco" + +detach() { + sleep 1 + printf "" +} + +# $1 => session-name, $2 => exit status +expected_abduco_output() { + echo "[?25habduco: $1: session terminated with exit status $2" +} + +check_environment() { + [ "`$ABDUCO | wc -l`" -gt 1 ] && echo Abduco session exists && return 1; + pgrep abduco && echo Abduco process exists && return 1; + return 0; +} + +test_non_existing_command() { + check_environment || return 1; + $ABDUCO -c test ./non-existing-command &> /dev/null + check_environment || return 1; +} + +# $1 => session-name, $2 => command to execute +run_test_attached() { + check_environment || return 1; + + local name="$1" + local cmd="$2" + local output="$name.out" + local output_expected="$name.expected" + + echo -n "Running test attached: $name " + $cmd &> "$output_expected" + expected_abduco_output "$name" $? >> "$output_expected" + $ABDUCO -c "$name" $cmd 2>&1 | head -n -1 | sed 's/.$//' > "$output" + if diff -u "$output_expected" "$output" && check_environment; then + rm "$output" "$output_expected" + echo "OK" + return 0 + else + echo "FAIL" + return 1 + fi +} + +# $1 => session-name, $2 => command to execute +run_test_detached() { + check_environment || return 1; + + local name="$1" + local cmd="$2" + local output="$name.out" + local output_expected="$name.expected" + + echo -n "Running test detached: $name " + $cmd &> /dev/null + expected_abduco_output "$name" $? > "$output_expected" + + if $ABDUCO -n "$name" $cmd &> /dev/null && sleep 1 && + $ABDUCO -a "$name" 2>&1 | head -n -1 | sed 's/.$//' > "$output" && + diff -u "$output_expected" "$output" && check_environment; then + rm "$output" "$output_expected" + echo "OK" + return 0 + else + echo "FAIL" + return 1 + fi +} + +# $1 => session-name, $2 => command to execute +run_test_attached_detached() { + check_environment || return 1; + + local name="$1" + local cmd="$2" + local output="$name.out" + local output_expected="$name.expected" + + echo -n "Running test: $name " + $cmd &> /dev/null + expected_abduco_output "$name" $? > "$output_expected" + + if detach | $ABDUCO -c "$name" $cmd &> /dev/null && sleep 3 && + $ABDUCO -a "$name" 2>&1 | head -n -1 | tail -1 | sed 's/.$//' > "$output" && + diff -u "$output_expected" "$output" && check_environment; then + rm "$output" "$output_expected" + echo "OK" + return 0 + else + echo "FAIL" + return 1 + fi +} + +test_non_existing_command || echo "Execution of non existing command FAILED" + +run_test_attached "seq" "seq 1 1000" +run_test_detached "seq" "seq 1 1000" + +cat > exit-status.sh <<-EOT + #!/bin/sh + echo Hello World + exit 42 +EOT +chmod +x exit-status.sh + +run_test_attached "exit-status" "./exit-status.sh" +run_test_detached "exit-status" "./exit-status.sh" + +rm ./exit-status.sh + +cat > long-running.sh <<-EOT + #!/bin/sh + echo Start + date + sleep 3 + echo Hello World + sleep 3 + echo End + date + exit 1 +EOT +chmod +x long-running.sh + +run_test_attached_detached "attach-detach" "./long-running.sh" + +rm ./long-running.sh -- 2.11.4.GIT