Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 ce6fc8f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/code_layout/CMakeLists.txt
Expand Up @@ -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)

Expand Down
43 changes: 43 additions & 0 deletions tests/code_layout/test_banned_keywords.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.