QGIS/tests/code_layout/test_banned_keywords.sh
Nyall Dawson ce6fc8fe96 [ci] Add unit test for banned keywords
Flags use of keywords representing deprecated or other
"to be avoided" methods, e.g. use of DBL_MAX instead of
the type-safe std::numeric_limits<double>::max() method.
2018-06-17 09:24:37 +10:00

44 lines
921 B
Bash
Executable File

#!/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>::max() instead"
KEYWORDS[1]="DBL_MIN"
HINTS[1]="Use the type-safe method std::numeric_limits<double>::lowest() instead"
KEYWORDS[2]="DBL_EPSILON"
HINTS[2]="Use the type-safe method std::numeric_limits<double>::epsilon() 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