forked from earlephilhower/mklittlefs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.sh
executable file
·77 lines (61 loc) · 1.6 KB
/
run_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -o errexit
set -o nounset
shopt -s extglob
if [[ $# != 1 ]]; then
echo "Usage: ${0} <test_dir>"
exit 1
fi
tests_dir=$(cd ${1} && pwd -P)
work_dir=$(mktemp -d)
if [[ ! "$work_dir" || ! -d "$work_dir" ]]; then
echo "Failed to create working dir"
exit 1
fi
function cleanup {
rm -rf "$work_dir"
}
trap cleanup EXIT
export MKLITTLEFS="$(pwd -P)/mklittlefs"
cd $work_dir
tests_executed=0
tests_failed=0
for test_case in ${tests_dir}/!(*@(.out|.err)); do
test_name=$(basename "${test_case}")
expected_out=/dev/null
expected_err=/dev/null
if [[ -f "${test_case}.out" ]]; then
expected_out="${test_case}.out"
fi
if [[ -f "${test_case}.err" ]]; then
expected_err="${test_case}.err"
fi
mkdir "${test_name}"
actual_out="${test_name}/actual.out"
actual_err="${test_name}/actual.err"
failed=0
rc=0
WORKDIR="${work_dir}/${test_name}" $test_case > "${actual_out}" 2> "${actual_err}" || rc=$?
if [[ ${rc} != 0 ]]; then
echo "Test ${test_name} failed with exit code ${rc}"
failed=1
fi
rc=0
diff -q "${expected_out}" "${actual_out}" || rc=$?
if [[ ${rc} != 0 ]]; then
diff "${expected_out}" "${actual_out}" | head
failed=1
fi
rc=0
diff -q "${expected_err}" "${actual_err}" || rc=$?
if [[ ${rc} != 0 ]]; then
diff "${expected_err}" "${actual_err}" | head
failed=1
fi
if [[ $failed != 0 ]]; then
((++tests_failed))
fi
((++tests_executed))
done
echo "Executed ${tests_executed} test cases, ${tests_failed} failures"
exit $tests_failed