-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashtest.sh
65 lines (58 loc) · 1.46 KB
/
bashtest.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
#!/bin/bash
CLEAR='\033[0m' # resets color and format
GREEN='\033[38;5;2m'
RED='\033[38;5;1m'
MAGENTA='\033[38;5;5m'
CHECK='\xE2\x9C\x94'
CROSS='\xe2\x9c\x98'
GREEN_CHECK="${GREEN}${CHECK}${CLEAR}"
RED_CROSS="${RED}${CROSS}${CLEAR}"
readonly PROGNAME="$(basename "$0" | sed 's/.sh//g')"
function run_test(){
local test_name
local rc
test_name="$1"
shift
output="$(eval "$test_name" "$@")"
rc="$?"
if [[ "$rc" -eq "0" ]]; then
echo -e "$test_name ${GREEN_CHECK}"
return 0
else
echo -e "$test_name ${RED_CROSS}"
echo -e "${RED}========================"
echo -e "$output"
echo -e "========================${CLEAR}"
return 1
fi
}
function main() {
if [[ $1 != "" ]]; then
search_path="$1/test"
else
search_path="$PWD/test"
fi
local test_files
test_files=$(find "$search_path" -mindepth 1)
for test_file in $test_files; do
if ! [[ "$(basename "$test_file")" == test* ]]; then
continue
fi
echo -e "${MAGENTA}$(basename "$test_file")${CLEAR}"
source "$test_file"
local decls
decls=$(declare -F)
for decl in $decls; do
case "$decl" in
"test_"*)
run_test "$decl"
unset -f "$decl"
;;
*)
continue
;;
esac
done
done
}
main "$@"