From 778f7de4521cd14ed54c33bb45d708af3f67d8e7 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 20 Jul 2023 09:51:20 +1000 Subject: [PATCH] Add a test to ensure consistency of class names --- .github/workflows/code_layout.yml | 10 +++++++- tests/code_layout/CMakeLists.txt | 1 + tests/code_layout/test_class_names.sh | 37 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 tests/code_layout/test_class_names.sh diff --git a/.github/workflows/code_layout.yml b/.github/workflows/code_layout.yml index fc29d0f1ff8..10f3d9be196 100644 --- a/.github/workflows/code_layout.yml +++ b/.github/workflows/code_layout.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.10' - name: Install requirements run: | wget https://www.doxygen.nl/files/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz @@ -72,6 +72,14 @@ jobs: - name: Run Banned Keywords Test run: ./tests/code_layout/test_banned_keywords.sh + class_name_check: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Run class naming conventions check + run: ./tests/code_layout/test_class_names.sh + def_window_title_check: runs-on: ubuntu-latest steps: diff --git a/tests/code_layout/CMakeLists.txt b/tests/code_layout/CMakeLists.txt index 5c8687bb590..35f5fa28c47 100644 --- a/tests/code_layout/CMakeLists.txt +++ b/tests/code_layout/CMakeLists.txt @@ -9,6 +9,7 @@ if(WITH_ASTYLE) endif() add_qgis_test_script(qgis_banned_keywords tests/code_layout/test_banned_keywords.sh) +add_qgis_test_script(qgis_class_names tests/code_layout/test_class_names.sh) add_qgis_test_script(qgis_licenses tests/code_layout/test_licenses.sh) add_qgis_test_script(qgis_spelling scripts/spell_check/spell_test.sh) add_qgis_test_script(qgis_defwindowtitle tests/code_layout/test_defwindowtitle.sh) diff --git a/tests/code_layout/test_class_names.sh b/tests/code_layout/test_class_names.sh new file mode 100755 index 00000000000..b80429a1c24 --- /dev/null +++ b/tests/code_layout/test_class_names.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# This test checks for use of non-compliant class names + +declare -a KEYWORDS=() +declare -a HINTS=() + +KEYWORDS[0]="^\s*class[^:]*Qgs\S*3d" +HINTS[0]="Use '3D' capitalisation in class names instead of '3d'" + +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' | sed -n 's/.*\(Qgs\w*\).*/\1/p' | sort -u) + + if [[ ${FOUND} ]]; then + echo "Found classes with non-standard names!" + echo " -> ${HINTS[$i]}" + echo + echo "${FOUND}" + echo + RES=1 + fi + +done + +popd > /dev/null || exit + +if [ $RES ]; then + echo " *** Found non-compliant class names" + exit 1 +fi +