root / t / test-exception-wrapper @ 375d3643
Historique | Voir | Annoter | Télécharger (1,89 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# |
| 3 |
# Run a check for a given file. A failure is tolerated (and expected), if the filename is listed |
| 4 |
# in a file containing expected failures. |
| 5 |
# |
| 6 |
# Parameters: SCRIPT_FILENAME TEST_COMMAND [TEST_COMMAND_ARGUMENTS] |
| 7 |
# |
| 8 |
# See EXPECTED_FAILURES_LIST_FILENAME for the filename pattern of a file, containing the relative |
| 9 |
# names of all scripts, that are expected to fail. This wrapper script will fail, if the exit |
| 10 |
# status of the test does not match the expectated result (i.e. it fails but should pass or it |
| 11 |
# passes while being listed in the EXPECTED_FAILURES_LIST_FILENAME file). |
| 12 |
# |
| 13 |
|
| 14 |
set -eu |
| 15 |
|
| 16 |
[ $# -lt 2 ] && echo >&2 "Insufficient number of arguments: expecting SCRIPT_FILENAME and one or more COMMAND tokens" && exit 1 |
| 17 |
|
| 18 |
|
| 19 |
SCRIPT_FILENAME="$1" |
| 20 |
shift |
| 21 |
EXPECTED_FAILURES_LIST_FILENAME="$0.expected-failures" |
| 22 |
|
| 23 |
REPOSITORY_DIR=$(cd "$(dirname "$0")/.." && pwd) |
| 24 |
|
| 25 |
|
| 26 |
[ ! -e "$SCRIPT_FILENAME" ] && echo >&2 "Failed to find script: $SCRIPT_FILENAME" && exit 3 |
| 27 |
|
| 28 |
|
| 29 |
# determine, whether the script is mentioned in the exclusion file |
| 30 |
relative_script_filename=$(realpath --relative-to "$REPOSITORY_DIR" "$SCRIPT_FILENAME") |
| 31 |
if grep --quiet --line-regexp --fixed-strings --no-messages "$relative_script_filename" "$EXPECTED_FAILURES_LIST_FILENAME"; then |
| 32 |
is_expected_to_fail=1 |
| 33 |
else |
| 34 |
is_expected_to_fail=0 |
| 35 |
fi |
| 36 |
|
| 37 |
# check the returncode of the test |
| 38 |
if "$@" "$SCRIPT_FILENAME"; then |
| 39 |
has_failed=0 |
| 40 |
else |
| 41 |
has_failed=1 |
| 42 |
fi |
| 43 |
|
| 44 |
|
| 45 |
# complain, if the result did not meet our expectation |
| 46 |
if [ "$is_expected_to_fail" = "$has_failed" ]; then |
| 47 |
# the check returned the expected result |
| 48 |
exit 0 |
| 49 |
elif [ "$has_failed" = "1" ]; then |
| 50 |
echo >&2 "ERROR: the script '$SCRIPT_FILENAME' should pass the test, but it failed" |
| 51 |
exit 4 |
| 52 |
else |
| 53 |
echo >&2 "ERROR: the script '$SCRIPT_FILENAME' was expected to fail the test, but it succeeded. Please remove this filename from the list of exepected failures ($EXPECTED_FAILURES_LIST_FILENAME)." |
| 54 |
exit 5 |
| 55 |
fi |
