QGIS/tests/code_layout/test_banned_keywords.sh

53 lines
1.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# This test checks for use of deprecated/outdated methods and suggests their replacement
declare -a KEYWORDS=()
declare -a HINTS=()
2018-06-16 12:51:33 +10:00
KEYWORDS[0]="\-DBL_MAX"
HINTS[0]="Use the type-safe method std::numeric_limits<double>::lowest() instead"
2018-06-16 12:51:33 +10:00
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"
2018-06-16 12:56:00 +10:00
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