forked from josephwecker/autohighlight
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·105 lines (86 loc) · 1.33 KB
/
test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
declare -a results=()
run_tests() {
local total_rv=0
local run_as_module=0
if [[ "$1" = -m ]]
then
shift
run_as_module=1
fi
local test_dir="tests"
if ((run_as_module))
then
local test_mod_init="${test_dir}/__init__.py"
touch "${test_mod_init}"
fi
local rv
for name in "$@"
do
local file="${test_dir}/test_$name.py"
echo "Running test ${file}"
if ((run_as_module))
then
local modname="${file%.py}"
local modname="${modname//\//.}"
python -m "${modname}"
else
python "${file}"
fi
rv=$?
if ((rv))
then
total_rv="${rv}"
fi
results+=(
"$name":::"$rv"
)
done
if ((run_as_module))
then
rm -f "${test_mod_init}"{,c} || :
fi
return "${total_rv}"
}
run_tests_m() {
run_tests -m "$@"
}
print_summary() {
for name__rv in "${results[@]}"
do
local name="${name__rv%:::*}"
local rv="${name__rv#*:::}"
local result_string
if [[ "$rv" = 0 ]]
then
result_string="\e[32mPASS\e[m"
else
result_string="\e[31mFAIL\e[m"
fi
printf "%10s - %10b\n" "${name}" "${result_string}"
done
}
greppy() {
grep '[^a-z]set(' -- *.py | grep -v utils.py
}
main() {
local -a tests=(
token
tokenizer
ah3
ah4
type
# ah
# ah2
)
if [[ $# -ne 0 ]]
then
tests=("$@")
fi
run_tests_m "${tests[@]}"
local rv=$?
print_summary
# greppy
return "${rv}"
}
main "$@"