Skip to content
Permalink
Browse files

[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.
  • Loading branch information
nyalldawson committed Jun 16, 2018
1 parent a4c8386 commit ce6fc8fe96afb331c25c6c7ba7dd32e5f2540a7a
Showing with 44 additions and 0 deletions.
  1. +1 −0 tests/code_layout/CMakeLists.txt
  2. +43 −0 tests/code_layout/test_banned_keywords.sh
@@ -2,6 +2,7 @@ IF(WITH_ASTYLE)
ADD_TEST(qgis_indentation ${CMAKE_SOURCE_DIR}/scripts/verify-indentation.sh)
ENDIF(WITH_ASTYLE)

ADD_TEST(qgis_banned_keywords ${CMAKE_SOURCE_DIR}/tests/code_layout/test_banned_keywords.sh)
ADD_TEST(qgis_licenses ${CMAKE_SOURCE_DIR}/tests/code_layout/test_licenses.sh)
ADD_TEST(qgis_spelling ${CMAKE_SOURCE_DIR}/scripts/spell_check/spell_test.sh)

@@ -0,0 +1,43 @@
#!/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

0 comments on commit ce6fc8f

Please sign in to comment.
You can’t perform that action at this time.