/
test_banned_keywords.sh
executable file
·52 lines (36 loc) · 1.25 KB
/
test_banned_keywords.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
#!/usr/bin/env bash
# This test checks for use of deprecated/outdated methods and suggests their replacement
declare -a KEYWORDS=()
declare -a HINTS=()
KEYWORDS[0]="\-DBL_MAX"
HINTS[0]="Use the type-safe method std::numeric_limits<double>::lowest() instead"
KEYWORDS[1]="DBL_MAX"
HINTS[1]="Use the type-safe method std::numeric_limits<double>::max() instead"
KEYWORDS[2]="DBL_MIN"
HINTS[2]="Use the type-safe method std::numeric_limits<double>::min() instead (but be careful - maybe you actually want lowest!!)"
KEYWORDS[3]="DBL_EPSILON"
HINTS[3]="Use the type-safe method std::numeric_limits<double>::epsilon() instead"
KEYWORDS[4]="INT_MIN"
HINTS[4]="Use the type-safe method std::numeric_limits<int>::min() instead"
KEYWORDS[5]="INT_MAX"
HINTS[5]="Use the type-safe method std::numeric_limits<int>::max() instead"
RES=
DIR=$(git rev-parse --show-toplevel)
pushd "${DIR}" > /dev/null || exit
for i in "${!KEYWORDS[@]}"
do
FOUND=$(git grep "${KEYWORDS[$i]}" -- 'src/*.h' 'src/*.cpp')
if [[ ${FOUND} ]]; then
echo "Found source files with banned keyword: ${KEYWORDS[$i]}!"
echo " -> ${HINTS[$i]}"
echo
echo "${FOUND}"
echo
RES=1
fi
done
popd > /dev/null || exit
if [ $RES ]; then
echo " *** Found banned keywords"
exit 1
fi