forked from saulpw/visidata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests-individually.sh
executable file
·76 lines (62 loc) · 1.83 KB
/
run-tests-individually.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
#!/usr/bin/env bash
# usage: ./dev/run-tests-individually.sh [<tests/name.vd> […]]
#
# Runs tests/*.vd or the given test files individually and summarize failures
# at the end.
#
# The stdout and stderr of each test is saved in tests/log/<name>.log. Files
# in tests/golden/ which are rewritten by tests are not saved.
#
# Your repository must be clean: no uncommitted changes or untracked files are
# allowed. The working dir is restored after each test, and this policy
# prevents you from losing your changes. It also prevents such changes from
# accidentally perturbing test results.
#
set -euo pipefail
shopt -s nullglob
if [[ -n $(git status --porcelain --untracked-files=all) ]]; then
echo "repo is dirty; aborting" >&2
exit 1
fi
main() {
local test_file test_name
local -a test_files failures
test_files=("$@")
failures=()
if [[ ${#test_files[@]} -eq 0 ]]; then
test_files=(tests/*.vd)
fi
# Clean logs
mkdir -p tests/log/
rm -f tests/log/*.log
# Run each test file separately
trap 'exit 130' SIGINT
for test_file in "${test_files[@]}"; do
test_name="$(basename "$test_file" .vd)"
if ./dev/test.sh "$test_name" >tests/log/"$test_name".log 2>&1; then
pass "$test_name"
else
fail "$test_name"
failures+=("$test_file")
fi
# Restore working dir to a pristine state.
git restore .
done
if [[ ${#failures[@]} -ne 0 ]]; then
printf "\n" >&2
printf "%d failed tests:\n" "${#failures[@]}" >&2
printf " %s\n" "${failures[@]}" >&2
fi
}
pass() {
echo "$(colorize "green bold" " ok")" "$@"
}
fail() {
echo "$(colorize "red bold" "not ok")" "$@"
}
colorize() {
git config --get-color "" "$1"
echo -n "$2"
git config --get-color "" reset
}
main "$@"