3 # paraslash test suite helper functions
4 # Licensed under the GPL v2. For licencing details see COPYING.
5 # uses ideas and code from git's test-lib.sh, Copyright (c) 2005 Junio C Hamano
13 result
=$
(find "$test_audio_file_dir" -type f
)
15 result
=$
(find "$test_audio_file_dir" -type f
-name "*.$suffix")
21 if [[ "$o_nocolor" != "true" && -n "$1" ]]; then
22 export TERM
=$ORIGINAL_TERM
24 error
) tput bold
; tput setaf
1;;
27 (($o_verbose == 0)) && return
29 pass
) tput bold
; tput setaf
2;;
32 (($o_verbose == 0)) && return
38 if [[ "$o_nocolor" != "true" && -n "$1" ]]; then
47 [[ "$exit_ok" == "true" ]] && exit $code
48 say_color error
"FATAL: Unexpected exit with code $code"
54 say_color error
"error: $*"
66 local rv
="$1" expectation
="$2"
68 if [[ "$expectation" == "success" ]]; then
69 (($rv == 0)) && return 0 ||
return 1
71 if (($rv > 129 && $rv <= 192)); then
72 echo >&2 "died by signal"
75 if (($rv == 127)); then
76 echo >&2 "command not found"
80 echo >&2 "command was supposed to fail but succeeded"
88 local f expectation
="$3" ret
93 if retval_ok
"$ret" "$expectation"; then
95 say_color ok
"ok $test_count - $1"
99 say_color error
"not ok - $test_count $1"
100 f
="$o_results_dir/${0##*/}-$$.out"
101 if [[ -s "$f" ]]; then
102 sed -e 's/^/# /' < "$f"
104 sed -e 's/^/# /' <<< "$2"
106 [[ "$o_immediate" != "true" ]] && return
113 (($# != 2)) && error
"bug: not 2 parameters to test_skip()"
116 say_color skip
>&3 "skipping test $this_test.$test_count ($1): $2"
117 say_color skip
"ok $test_count - $1 # skipped ($2)"
120 test_require_objects
()
125 # if no objects were given, we assume this test is run manually
126 # rather than via "make test". We won't check anything in this case
127 [[ -z "$o_objects" ]] && return
131 for o2
in $o_objects; do
132 [[ "$o1" != "$o2" ]] && continue
136 [[ "$found" == "true" ]] && continue
137 [[ -n "$result" ]] && result
+=" "
143 test_require_executables
()
149 [[ -n "$(builtin type -t "$i")" ]] && continue
150 [[ -n "$result" ]] && result
+=" "
158 local t
=$
(exec 2>&1 1>/dev
/null
; time -p "$@")
159 result
=$
(awk '{print $2 * 1000}' <<< $t)
162 test_expect_success
()
164 (($# != 2)) && error
"bug: not 2 parameters to test_expect_success()"
165 echo >&3 "expecting success: $2"
166 _test_run
"$1" "$2" "success"
170 test_expect_failure
()
172 (($# != 2)) && error
"bug: not 2 parameters to test_expect_failure()"
173 echo >&3 "expecting failure: $2"
174 _test_run
"$1" "$2" "failure"
180 test_results_path
="$o_results_dir/${0##*/}-$$.counts"
182 echo "total $test_count"
183 echo "success $test_success"
184 echo "failed $test_failure"
185 echo "skipped $test_skipped"
187 } > $test_results_path
190 msg
="$test_count test(s) ($test_skipped test(s) skipped)"
191 if (($test_failure == 0)); then
192 say_color pass
"# ${0##*/}: passed all $msg"
195 say_color error
"# ${0##*/}: failed $test_failure among $msg"
200 sanitize_environment
()
219 [[ "$TERM" == "dumb" ]] && return
221 tput bold
>/dev
/null
2>&1 ||
return
222 tput setaf
1 >/dev
/null
2>&1 ||
return
223 tput sgr0
>/dev
/null
2>&1 ||
return
231 -i|
--immediate) o_immediate
="true"; shift;;
232 -l|
--long) export o_long
="true"; shift;;
233 -h|
--help) o_help
="true"; shift;;
234 -v=0|
--verbose=0) o_verbose
="0"; shift;;
235 -v=1|
--verbose=1) o_verbose
="1"; shift;;
236 -v|
--verbose|
-v=2|
--verbose=2) o_verbose
="2"; shift;;
237 --no-color) o_nocolor
="true"; shift;;
238 --results-dir) o_results_dir
="$2"; shift; shift;;
239 --trash-dir) o_trash_dir
="$2"; shift; shift;;
240 --executables-dir) export o_executables_dir
="$2"; shift; shift;;
241 --executables) export o_executables
="$2"; shift; shift;;
242 --objects) export o_objects
="$2"; shift; shift;;
243 *) echo "error: unknown test option '$1'" >&2; exit 1;;
246 [[ -z "$o_verbose" ]] && o_verbose
=1
249 create_trash_dir_and_cd
()
251 local trash
="$o_trash_dir/trash-dir.${0##*/}"
253 rm -rf "$trash" || error
"could not remove trash dir"
254 mkdir
-p "$trash" || error
"could not make trash dir"
255 cd "$trash" || error
"could not change to trash dir"
262 test_dir
="$wd/${0%/*}"
263 test_audio_file_dir
="$test_dir/audio_files"
265 [[ -z "$o_results_dir" ]] && o_results_dir
="$test_dir/test-results"
266 [[ -z "$o_executables_dir" ]] && o_executables_dir
="$test_dir/.."
267 [[ -z "$o_trash_dir" ]] && o_trash_dir
="$test_dir/trashes"
269 # we want alsolute paths because relative paths become invalid
270 # after changing to the trash dir
271 [[ -n "${o_results_dir##/*}" ]] && o_results_dir
="$wd/$o_results_dir"
272 [[ -n "${o_executables_dir##/*}" ]] && o_executables_dir
="$wd/$o_results_dir"
273 [[ -n "${o_trash_dir##/*}" ]] && o_trash_dir
="$wd/$o_trash_dir"
275 mkdir
-p "$o_results_dir"
279 if [[ "$o_nocolor" != "true" ]]; then
281 [[ "$result" != "true" ]] && o_nocolor
="true"
284 # Each test must set test_description
285 [[ -z "${test_description}" ]] && error
"${0##*/} did not set test_description"
286 if [[ "$o_help" == "true" ]]; then
288 sed -e '1!d' <<< "$test_description"
289 if (($o_verbose >= 2)); then
291 sed -e '1,2d' -e 's/^/ /g' <<<"$test_description"
298 [[ -z "$o_executables" ]] && o_executables
="para_afh para_audioc para_audiod
299 para_client para_fade para_filter para_gui para_recv para_server
301 for exe
in $o_executables; do
302 export $
(tr 'a-z' 'A-Z' <<< $exe)="$o_executables_dir/$exe"
312 create_trash_dir_and_cd
314 if (($o_verbose >= 2)); then
317 exec 4>$o_results_dir/${0##*/}-$$.out
3>&4
323 say_color run
"# running ${0##*/}"