-
Notifications
You must be signed in to change notification settings - Fork 24
/
lint.bats
executable file
·68 lines (60 loc) · 2.05 KB
/
lint.bats
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
. "${BASH_LIB_DIR}/init"
setup() {
bl_spushd ${BASH_LIB_DIR}
}
# Find and check shell scripts
@test "Syntax and Shellcheck" {
FAILED=""
echo "Starting Bash Lint checks"
for script in $(bl_find_scripts); do
bl_shellcheck_script "${script}"\
|| FAILED="${FAILED} ${script}"
done
[[ "${FAILED}" == "" ]]
}
@test "Bash scripts do not have .sh suffix" {
rc=0
for file in $(bl_find_scripts); do
if [[ "${file}" =~ .sh$ ]]; then
# script has .sh suffix
echo "Script found with .sh suffix: ${file}, please rename"
rc=1
fi
done
return ${rc}
}
@test "All functions referenced in readme" {
rc=0
for file in $(bl_find_scripts | grep "/lib$"); do
for func_name in $(grep 'function.*()\s*{\s*$' ${file} | awk '{print $2}'| tr -dc '[a-zA-Z0-9_-\n]'); do
if ! grep -q "${func_name}" "${BASH_LIB_DIR}/README.md"; then
echo "Function ${func_name} from libriary ${file} is not mentioned in the README.md, please add a description"
rc=1
fi
done
if ! grep -q "${file}" "${BASH_LIB_DIR}/README.md"; then
echo "Library ${file} is not mentioned in the README.md, please add a description"
rc=1
fi
done
return ${rc}
}
@test "All functions tested" {
local rc=0
for file in $(bl_find_scripts | grep "/lib$"); do
local lib_name="$(dirname ${file})"
local bats_file="tests-for-this-repo/${lib_name}.bats"
if [[ ! -e "${bats_file}" ]]; then
echo "BATS test file ${bats_file} is missing for library ${file}"
rc=1
else
for func_name in $(grep 'function.*()\s*{' "${file}" | awk '{print $2}'| tr -dc '[a-zA-Z0-9_\n]'); do
if ! grep -q "${func_name}" "${bats_file}"; then
echo "Function ${func_name} from libriary ${file} is not tested in ${bats_file}, please add a test."
rc=1
fi
done
fi
done
return ${rc}
}