|
1 | 1 | #!/bin/bash
|
2 | 2 | set -e
|
3 | 3 |
|
4 |
| -TEST_DIR="${TEST_DIR:-$(dirname $0)}" |
5 |
| -MPREMOTE="${MPREMOTE:-${TEST_DIR}/../mpremote.py}" |
| 4 | +TESTS_DIR="${TESTS_DIR:-$(dirname $0)}" |
| 5 | +RESULT_DIR="${RESULT_DIR:-${TESTS_DIR}/results}" |
| 6 | +MPREMOTE="${MPREMOTE:-${TESTS_DIR}/../mpremote.py}" |
| 7 | +DIFF="diff --unified --strip-trailing-cr" |
6 | 8 |
|
7 | 9 | if [ -z "$1" ]; then
|
8 | 10 | # Find tests matching test_*.sh
|
9 |
| - TESTS=${TEST_DIR}/test_*.sh |
| 11 | + declare -a TESTS=("${TESTS_DIR}"/test_*.sh) |
10 | 12 | else
|
11 |
| - # Specific test path from the command line. |
12 |
| - TESTS="$1" |
| 13 | + # Specific test paths from the command line. |
| 14 | + declare -a TESTS=("$@") |
13 | 15 | fi
|
14 | 16 |
|
15 |
| -for t in $TESTS; do |
| 17 | +mkdir --parents "${RESULT_DIR}" |
| 18 | + |
| 19 | +for test in "${TESTS[@]}"; do |
16 | 20 | TMP=$(mktemp -d)
|
17 |
| - echo -n "${t}: " |
18 |
| - # Strip CR and replace the random temp dir with a token. |
19 |
| - if env MPREMOTE="${MPREMOTE}" TMP="${TMP}" "${t}" 2>&1 | tr -d '\r' | sed "s,${TMP},"'${TMP},g' > "${t}.out"; then |
20 |
| - if diff "${t}.out" "${t}.exp" > /dev/null; then |
| 21 | + result="${RESULT_DIR}/$(basename "${test}")" |
| 22 | + |
| 23 | + echo -n "${test}: " |
| 24 | + |
| 25 | + env TMP="${TMP}" envsubst <"${test}.exp" >"${result}.exp" |
| 26 | + if env MPREMOTE="${MPREMOTE}" TMP="${TMP}" "${test}" >"${result}.out" 2>&1; then |
| 27 | + if $DIFF "${result}.out" "${result}.exp" > /dev/null; then |
21 | 28 | echo "OK"
|
| 29 | + rm "${result}.out" "${result}.exp" |
22 | 30 | else
|
23 | 31 | echo "FAIL"
|
24 |
| - diff "${t}.out" "${t}.exp" || true |
25 | 32 | fi
|
26 | 33 | else
|
27 | 34 | echo "CRASH"
|
28 | 35 | fi
|
29 | 36 | rm -r "${TMP}"
|
30 | 37 | done
|
| 38 | + |
| 39 | +for test in "${TESTS[@]}"; do |
| 40 | + result="${RESULT_DIR}/$(basename "${test}")" |
| 41 | + if [ -e "${result}.out" ]; then |
| 42 | + echo "FAILURE ${test}" |
| 43 | + $DIFF "${result}.out" "${result}.exp" |
| 44 | + fi |
| 45 | +done |
0 commit comments