comparison tests/run-tests.sh @ 36:f9501248b6bd

Add tests
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Wed, 07 Aug 2019 11:28:07 +0200
parents
children
comparison
equal deleted inserted replaced
35:2a8298bafec2 36:f9501248b6bd
1 #!/bin/sh
2 #
3 # Copyright (C) 2019 Guido Berhoerster <guido+pwm@berhoerster.name>
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 export PWM="${PWM:-pwm}"
26
27 export LC_ALL=C
28
29 l="$(locale -a | sort | grep -E '^(C|en_US)\.([uU][tT][fF]-?8)$' | head -1)"
30 if [ -z "$l" ]; then
31 printf 'no suitable UTF-8 locale found\n' >&2
32 exit 1
33 fi
34
35 export LC_ALL="$l"
36 export TESTS_PATH="$(dirname "$0")"
37 export TESTS_OUTPUT_PATH="${TESTS_OUTPUT_PATH:-${TESTS_PATH}/output}"
38
39 tests_passed=0
40 tests_failed=0
41
42 mkdir -p "${TESTS_OUTPUT_PATH}" || exit 1
43
44 for t in "${TESTS_PATH}"/test-*.sh; do
45 [ -r "${t}" ] || break
46
47 export LOGFILE="${TESTS_OUTPUT_PATH}/$(basename "${t}" .sh).log"
48 export TEST_NAME="$(basename "${t}" .sh)"
49
50 [ -t 1 ] && printf "Running %s" "${t}"
51 if ${SHELL:-/bin/sh} "$t" >/dev/null 2>"${LOGFILE}"; then
52 tests_passed=$(( tests_passed + 1 ))
53 if [ -t 1 ]; then
54 printf "\rOK "
55 else
56 printf "OK %s" "${t}"
57 fi
58 else
59 tests_failed=$(( tests_failed + 1 ))
60 if [ -t 1 ]; then
61 printf "\rFAILED "
62 else
63 printf "FAILED %s" "${t}"
64 fi
65 fi
66 printf "%s\n" "${t}"
67 done
68
69 printf -- "-----------\npassed: %3d\nfailed: %3d\ntotal: %3d\n" $tests_passed \
70 $tests_failed $(( tests_failed + tests_passed ))
71
72 [ $tests_failed -eq 0 ]