-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.sh
executable file
·128 lines (95 loc) · 1.78 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
get_module_names() {
local path="$1"
local candidate
while read -r candidate; do
local filename
# No constructor -> no module
if ! grep "^__init\(\)" < "$candidate" &>/dev/null; then
continue
fi
filename="${candidate#$path/}"
echo "${filename%.sh}"
done < <(find "$path" -type f -iname "*.sh")
return 0
}
get_test_names() {
local path="$1"
local candidate
while read -r candidate; do
echo "${candidate#$path/}"
done < <(find "$path" -type f -iname "*_spec.sh")
return 0
}
main() {
local tests
local missing
local modules
local failed
local module
local test
local err
tests=()
missing=()
modules=()
failed=()
readarray -t modules < <(get_module_names "include")
readarray -t tests < <(get_test_names "test")
for module in "${modules[@]}"; do
if ! array_contains "${module}_spec.sh" "${tests[@]}"; then
missing+=("$module")
fi
done
if (( ${#missing[@]} > 0 )); then
echo "There are no tests for these modules:"
for module in "${missing[@]}"; do
echo " $module"
done
return 1
fi
for test in "${tests[@]}"; do
if ! shellspec --shell bash --format d "test/$test"; then
failed+=("$test")
fi
done
if (( ${#failed[@]} > 0 )); then
echo "The following unit tests failed:"
for test in "${failed[@]}"; do
echo " $test"
done
return 1
fi
echo "All unit tests passed"
return 0
}
whereami() {
local scriptpath
if ! scriptpath=$(realpath "${BASH_SOURCE[0]}"); then
return 1
fi
echo "${scriptpath%/*}"
return 0
}
use_this_toolbox() {
local here
if ! here=$(whereami); then
return 1
fi
if ! export PATH="$here:$PATH"; then
return 1
fi
return 0
}
{
if ! use_this_toolbox; then
exit 1
fi
if ! . toolbox.sh; then
exit 1
fi
if ! include "array"; then
exit 1
fi
main "$@"
exit "$?"
}