From: Andre Noll Date: Sun, 20 Feb 2011 17:15:51 +0000 (+0100) Subject: Add t0003-writer-init-error-path.sh. X-Git-Tag: v0.4.6~10^2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=87d7882d3bd2e0a0432a2f388050fbbbcfe9fa42;p=paraslash.git Add t0003-writer-init-error-path.sh. This catches the bugs recently found in the alsa and oss writers. We need to test that certain commands fail but must distinguish between failure due to non-zero exit codes and other failures, for example if a command segfaults. Therefore this patch adds test_expect_failure() to test-lib.sh which can be called by the individual tests and DTRT. --- diff --git a/t/t0003-writer-init-error-path.sh b/t/t0003-writer-init-error-path.sh new file mode 100755 index 00000000..15f1dd8e --- /dev/null +++ b/t/t0003-writer-init-error-path.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +test_description='Check if alsa_init() failures are handled gracefully. + +Older parasslash versions contained a bug which caused para_write and para_audiod +to abort if the alsa/oss device could not be opened. This test makes sure we +will not introduce the same bug again.' + +. ${0%/*}/test-lib.sh + +for i in alsa oss; do + test_require_objects "${i}_write" + missing_objects="$result" + if [[ -n "$missing_objects" ]]; then + test_skip "$i" "missing object(s): $missing_objects" + continue + fi + test_expect_failure "$i" " + head -c 100 /dev/zero | $PARA_WRITE -w '$i -d /dev/non_existent' + " +done +test_done diff --git a/t/test-lib.sh b/t/test-lib.sh index e444e578..b7d675ea 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -61,13 +61,36 @@ say() say_color info "$*" } +retval_ok() +{ + local rv="$1" expectation="$2" + + if [[ "$expectation" == "success" ]]; then + (($rv == 0)) && return 0 || return 1 + fi + if (($rv > 129 && $rv <= 192)); then + echo >&2 "died by signal" + return 1 + fi + if (($rv == 127)); then + echo >&2 "command not found" + return 1 + fi + if (($rv == 0)); then + echo >&2 "command was supposed to fail but succeeded" + return 1 + fi + return 0 +} + _test_run() { - local f + local f expectation="$3" ret let test_count++ eval >&3 2>&4 "$2" - if (($? == 0)); then + ret=$? + if retval_ok "$ret" "$expectation"; then let test_success++ say_color ok "ok $test_count - $1" return @@ -140,7 +163,15 @@ test_expect_success() { (($# != 2)) && error "bug: not 2 parameters to test_expect_success()" say >&3 "expecting success: $2" - _test_run "$1" "$2" + _test_run "$1" "$2" "success" + echo >&3 "" +} + +test_expect_failure() +{ + (($# != 2)) && error "bug: not 2 parameters to test_expect_failure()" + say >&3 "expecting failure: $2" + _test_run "$1" "$2" "failure" echo >&3 "" }