--- /dev/null
+#!/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
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
{
(($# != 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 ""
}