Skip to content

Commit ce6fc8f

Browse files
committedJun 16, 2018
[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.
1 parent a4c8386 commit ce6fc8f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
 

‎tests/code_layout/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ IF(WITH_ASTYLE)
22
ADD_TEST(qgis_indentation ${CMAKE_SOURCE_DIR}/scripts/verify-indentation.sh)
33
ENDIF(WITH_ASTYLE)
44

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# This test checks for use of deprecated/outdated methods and suggests their replacement
4+
5+
declare -a KEYWORDS=()
6+
declare -a HINTS=()
7+
8+
KEYWORDS[0]="DBL_MAX"
9+
HINTS[0]="Use the type-safe method std::numeric_limits<double>::max() instead"
10+
11+
KEYWORDS[1]="DBL_MIN"
12+
HINTS[1]="Use the type-safe method std::numeric_limits<double>::lowest() instead"
13+
14+
KEYWORDS[2]="DBL_EPSILON"
15+
HINTS[2]="Use the type-safe method std::numeric_limits<double>::epsilon() instead"
16+
17+
RES=
18+
DIR=$(git rev-parse --show-toplevel)
19+
20+
pushd "${DIR}" > /dev/null || exit
21+
22+
for i in "${!KEYWORDS[@]}"
23+
do
24+
FOUND=$(git grep "${KEYWORDS[$i]}" -- 'src/*.h' 'src/*.cpp')
25+
26+
if [[ ${FOUND} ]]; then
27+
echo "Found source files with banned keyword: ${KEYWORDS[$i]}!"
28+
echo " -> ${HINTS[$i]}"
29+
echo
30+
echo "${FOUND}"
31+
echo
32+
RES=1
33+
fi
34+
35+
done
36+
37+
popd > /dev/null || exit
38+
39+
if [ $RES ]; then
40+
echo " *** Found banned keywords"
41+
exit 1
42+
fi
43+

0 commit comments

Comments
 (0)
Please sign in to comment.