-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-all.bash
executable file
·140 lines (106 loc) · 3.36 KB
/
test-all.bash
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
129
130
131
132
133
134
135
136
137
138
139
140
#! /bin/bash
# Runs all the tests in the tests sub-package of the lyc-git-bash-utils package.
# Copyright 2022 Yucheng Liu. GNU GPL3 license.
# GNU GPL3 license copy: https://www.gnu.org/licenses/gpl-3.0.txt
__file=$(realpath ${BASH_SOURCE[0]})
__dir=$(dirname $__file)
# include lyc-git-bash-utils.libs.utils
if [[ -z $_gbu_incl_libs_utils ]]; then
source $__dir/lyc-git-bash-utils/libs/utils.bash
eval "$_gbu_ensure_metainfo_eval"
fi
if [[ -z $_gbu_incl_tests_libs_blackboxes ]]; then
source $__dir/lyc-git-bash-utils/tests/libs/blackboxes.bash
eval "$_gbu_ensure_metainfo_eval"
fi
__repo_path=$(realpath $__dir)
__test_data_path=$__repo_path/.lyc-git-bash-utils-test-data
__failed_stderr_loc=$__test_data_path/-failed-stderr.txt
# Test count.
__test_cnt=0
# Success count.
__succ_cnt=0
# Failure count.
__fail_cnt=0
# Test index.
__test_idx=0
# Blackbox test total.
__blackbox_test_ttl="${#_gbu_blackbox_tests[@]}"
# Test total.
__test_ttl=$(($__blackbox_test_ttl))
__run_blackbox_tests() {
if [[ $# -ne 0 ]]; then
return 1
fi
_gbu_setup_blackbox_tests
for test_fn in "${_gbu_blackbox_tests[@]}"; do
$test_fn 1>>/dev/null 2>>$__failed_stderr_loc
local exit_code=$?
__test_cnt=$(($__test_cnt + 1))
if [[ $exit_code -eq 0 ]]; then
echo -ne "."
__succ_cnt=$(($__succ_cnt + 1))
else
echo -ne "F"
__fail_cnt=$(($__fail_cnt + 1))
fi
if [[
$((($__test_idx + 1) % 60)) -eq 0 ||
$(($__test_idx + 1)) -eq $__test_ttl ]]; then
echo -ne "\n"
fi
__test_idx=$(($__test_idx + 1))
done
_gbu_tear_down_blackbox_tests
}
__run_tests() {
if [[ $# -ne 0 ]]; then
return 1
fi
mkdir $__test_data_path 1>>/dev/null 2>>/dev/null
touch $__failed_stderr_loc
local start_time=$SECONDS
__run_blackbox_tests
local end_time=$SECONDS
local taken_time_secs=$(($end_time - $start_time))
local taken_hrs=$(($taken_time_secs / 3600))
local taken_mins=$((($taken_time_secs / 60) - $taken_hrs * 60))
local taken_mins=$(printf "%02d" "$taken_mins")
local taken_secs=$(($taken_time_secs - $taken_mins * 60 - $taken_hrs * 3600))
local taken_secs=$(printf "%02d" "$taken_secs")
local test_summ="\
-
Ran $__test_cnt tests Time taken: $taken_hrs:$taken_mins:$taken_secs (hours: minutes: seconds)
Successes: $__succ_cnt Failures: $__fail_cnt
"
echo -ne "$test_summ"
if [[ $__fail_cnt -gt 0 ]]; then
local details=$(cat $__failed_stderr_loc)
local fail_details="\
- Failure details
$details
- End of failure details
"
echo -ne "$fail_details"
fi
rm -f $__failed_stderr_loc
}
__main() {
local brief_usage=test-all.bash
local few_args_fmt="\"$brief_usage\" gets too few arguments\nExpects 0 arguments; Gets %s arguments\n"
local usage="Usage: $brief_usage\nHelp: LYC-GitBashUtils/README.md"
local many_args_fmt="\"$brief_usage\" gets too many arguments\nExpects 0 arguments; Gets %s arguments\n"
if [[ $# -lt 0 ]]; then
printf "$few_args_fmt" "$#" >>/dev/stderr
echo -e "$usage" >>/dev/stderr
exit 1
elif [[ $# -eq 0 ]]; then
__run_tests
exit 0
else
printf "$many_args_fmt" "$#" >>/dev/stderr
echo -e "$usage" >>/dev/stderr
exit 1
fi
}
__main "$@"