-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_tests.sh
executable file
·58 lines (51 loc) · 1.27 KB
/
check_tests.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
#!/bin/env bash
# You can supply the path to the findpick program that is then tested against
# the test cases.
if [[ "${#}" -eq 0 ]]
then
path_to_fp="./fp"
else
path_to_fp="${1}"
fi
results () {
local path="${1}"
local name=${path##*/test_}
name=${name%.sh}
local error_code="${2}"
local message="${3}"
printf '\nTest:\t%s\n' "${name}"
if [[ "${error_code}" -eq 0 ]]
then
printf '\tStatus: Pass\n'
return 0
else
printf '\tStatus: Fail\n'
printf '\tPath: %s\n' "${path}"
printf '\tError Code: %s\n' "${error_code}"
printf '\tMessage: %s\n' "${message}"
exit "${error_code}"
fi
}
original_path_to_fp="${path_to_fp}"
path_to_fp="${path_to_fp/#~/${HOME}}"
if [[ "${path_to_fp}" =~ / ]]
then
path_to_fp="$(realpath -e -- "${path_to_fp}")"
else
path_to_fp="$(command -v -- "${path_to_fp}")"
fi
if [[ "${?}" -ne 0 ]]
then
printf 'ERROR! findpick path not found\n"%s"\n' "${original_path_to_fp}"
exit 1
else
printf '"%s"\n' "${path_to_fp}"
fi
tests_dir="$(realpath -e -- "$(dirname "$0")/tests")"
cd -- "${tests_dir}" || exit 1
for file in "${tests_dir}/test_"*".sh"
do
message=$(bash -- "${file}" "${path_to_fp}")
results "${file}" "${?}" "${message}"
done
exit 0