-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.sh
48 lines (36 loc) · 1.03 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
#!/bin/bash
# [[ -f eiskaffee.sh ]] && . eiskaffee.sh
source ./templates/.eiskrc
test_replace_characters() {
result=$(replace_characters "Açãí Fruit")
assert_equals "$result" "acai-fruit"
}
test_trim_string() {
result=$(trim_string " example string ")
assert_equals "$result" "example string"
}
assert_equals() {
if [[ "$1" == "$2" ]]; then
((pass+=1))
status=$'\e[32m✔'
else
((fail+=1))
status=$'\e[31m✖'
local err="(\"$1\" != \"$2\")"
fi
printf ' %s\e[m | %s\n' "$status" "${FUNCNAME[1]/test_} $err"
}
# Generate the list of tests to run.
main() {
head="-> Running tests on the ${blueb}Eiskaffee...${end}"
printf '\n%s\n%s\n' "$head" "${head//?/-}"
IFS=$'\n'
for func in $(declare -F); do
[[ "${func:11}" == test_* ]] && "${func:11}";
done
comp="Completed $((fail+pass)) tests. ${greenb}${pass:-0} passed${end}, ${redb}${fail:-0} failed.${end}"
printf '%s\n%s\n\n' "${comp//?/-}" "$comp"
# If a test failed, exit with '1'.
((fail>0)) || exit 0 && exit 1
}
main "$@"