From 260cebc8de928a3b69a15e77bd96aa44edc87310 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 20 Oct 2016 13:53:10 +0200 Subject: [PATCH] feat(app): add new tool `test_qml` that run unit tests on all `*.spec.qml` files --- tests/CMakeLists.txt | 2 +- tests/resources.qrc | 3 +- tests/tools/{check_qml => check_qml_syntax} | 2 +- tests/tools/private/pre-commit | 24 ++----- tests/tools/test_qml | 62 +++++++++++++++++++ tests/tools/update_resources | 10 +-- .../Common/Dialog/ConfirmDialog.spec.qml | 1 - .../Animations/CaterpillarAnimationStyle.qml | 2 +- 8 files changed, 77 insertions(+), 29 deletions(-) rename tests/tools/{check_qml => check_qml_syntax} (96%) create mode 100644 tests/tools/test_qml diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e1ffcac0c..cdf6e44ad 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -96,7 +96,7 @@ endforeach () add_custom_target( check_qml DEPENDS ${QML_SOURCES} - COMMAND "${CMAKE_SOURCE_DIR}/tools/check_qml" + COMMAND "${CMAKE_SOURCE_DIR}/tools/check_qml_syntax" ) # -------------------------------------------------------------------- diff --git a/tests/resources.qrc b/tests/resources.qrc index 9d6a885a2..06cfad5d9 100644 --- a/tests/resources.qrc +++ b/tests/resources.qrc @@ -1,5 +1,5 @@ - + imgs/add_field.svg imgs/call.svg imgs/cam.svg @@ -32,6 +32,7 @@ ui/modules/Common/Colors.qml ui/modules/Common/Constants.qml ui/modules/Common/Dialog/ConfirmDialog.qml + ui/modules/Common/Dialog/ConfirmDialog.spec.qml ui/modules/Common/Dialog/DialogDescription.qml ui/modules/Common/Dialog/DialogPlus.qml ui/modules/Common/DroppableTextArea.qml diff --git a/tests/tools/check_qml b/tests/tools/check_qml_syntax similarity index 96% rename from tests/tools/check_qml rename to tests/tools/check_qml_syntax index 202d713ba..258be6b4a 100755 --- a/tests/tools/check_qml +++ b/tests/tools/check_qml_syntax @@ -4,7 +4,7 @@ # Tool to check the syntax of `.qml`/`.js` files. # ==================================================================== -RESOURCES_FILE="resources.qrc" +RESOURCES_FILE='resources.qrc' LINTER=qmllint-qt5 RED='\e[1;31m' diff --git a/tests/tools/private/pre-commit b/tests/tools/private/pre-commit index 501655c37..ca87c9d66 100755 --- a/tests/tools/private/pre-commit +++ b/tests/tools/private/pre-commit @@ -1,29 +1,15 @@ #!/usr/bin/sh -RED='\e[1;31m' -GREEN='\e[1;32m' -BLUE='\e[1;34m' -NC='\e[0m' - # Check QML files, quit on failure. -sh "./tests/tools/check_qml" +sh './tests/tools/check_qml_syntax' if [[ $? != 0 ]] ; then exit 1 fi -# Check JS lib. -printf "${BLUE}Testing scripts lib...${NC}\n" +printf '\n' -so_far_so_good=0 -qmltestrunner -input "./tests/ui/scripts/Utils/utils.spec.qml" +# Run unit tests. +sh './tests/tools/test_qml' -if [[ $? == 0 ]]; then - printf "${GREEN}Done. No error found in scripts lib.\n" -else - printf "${RED}One or more errors were found. Please to fix them.\n" - so_far_so_good=1 -fi -printf "${NC}" - -exit $so_far_so_good +exit $? diff --git a/tests/tools/test_qml b/tests/tools/test_qml new file mode 100644 index 000000000..af0afa615 --- /dev/null +++ b/tests/tools/test_qml @@ -0,0 +1,62 @@ +#!/usr/bin/sh + +RESOURCES_FILE='resources.qrc' +TEST_RUNNER='qmltestrunner-qt5' +TEST_FILE_EXTENSION='spec.qml' + +RED='\e[1;31m' +GREEN='\e[1;32m' +BLUE='\e[1;34m' +NC='\e[0m' + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $SCRIPT_DIR/.. + +# Check JS lib. +printf "${BLUE}Testing scripts lib...${NC}\n" + +so_far_so_good=0 +$TEST_RUNNER -input './ui/scripts/Utils/utils.spec.qml' + +if [[ $? == 0 ]]; then + printf "${GREEN}Done. No error found in scripts lib.\n" +else + printf "${RED}One or more errors were found. Please to fix them.\n" + so_far_so_good=1 +fi +printf "${NC}\n" + +# Check all `*.spec.qml` files +while read line +do + qml_file=$( + printf "$line" | + sed -n 's/^\s*<\s*file\s*>\s*\(.*\.qml\)\s*<\s*\/\s*file\s*>\s*$/\1/p' + ) + if [[ ! -z $qml_file ]]; then + spec_qml_file="${qml_file%.*}.${TEST_FILE_EXTENSION}" + + if [ -f $spec_qml_file ]; then + printf "${BLUE}Running unit qml tests of '${qml_file}'...${NC}\n" + $TEST_RUNNER -import './ui/modules/' -input "$spec_qml_file" + + if [[ $? == 0 ]]; then + printf "${GREEN}All unit tests have succeeded for '${spec_qml_file}'.\n" + else + printf "${RED}Unit tests have failed for '${spec_qml_file}'.\n" + so_far_so_good=1 + fi + fi + fi +done < $RESOURCES_FILE + +printf "\n" +if [[ $so_far_so_good == 0 ]]; then + printf "${GREEN}Done. All tests have succeeded.\n" +else + printf "${RED}Fail. One or many tests have failed.\n" + so_far_so_good=1 +fi +printf "${NC}\n" + +exit $so_far_so_good diff --git a/tests/tools/update_resources b/tests/tools/update_resources index 661d9b227..d8d6a1a45 100755 --- a/tests/tools/update_resources +++ b/tests/tools/update_resources @@ -10,13 +10,13 @@ # If you don't want to add a particular file, do not use this script! # ==================================================================== -RESOURCES_FILE="resources.qrc" +RESOURCES_FILE='resources.qrc' SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $SCRIPT_DIR/.. -echo " - " > $RESOURCES_FILE +echo ' + ' > $RESOURCES_FILE for filename in $(find ui/ imgs/ -type f | sort) do @@ -29,5 +29,5 @@ do fi done -echo " -" >> $RESOURCES_FILE +echo ' +' >> $RESOURCES_FILE diff --git a/tests/ui/modules/Common/Dialog/ConfirmDialog.spec.qml b/tests/ui/modules/Common/Dialog/ConfirmDialog.spec.qml index 0e6177a48..368bf346c 100644 --- a/tests/ui/modules/Common/Dialog/ConfirmDialog.spec.qml +++ b/tests/ui/modules/Common/Dialog/ConfirmDialog.spec.qml @@ -26,7 +26,6 @@ TestCase { return dialog } - function test_exitStatusViaButtons_data () { return [ { button: 0, expectedStatus: 0 }, diff --git a/tests/ui/modules/Common/Styles/Animations/CaterpillarAnimationStyle.qml b/tests/ui/modules/Common/Styles/Animations/CaterpillarAnimationStyle.qml index 943274827..25936b736 100644 --- a/tests/ui/modules/Common/Styles/Animations/CaterpillarAnimationStyle.qml +++ b/tests/ui/modules/Common/Styles/Animations/CaterpillarAnimationStyle.qml @@ -1,7 +1,7 @@ pragma Singleton import QtQuick 2.7 -import Common.Styles 1.0 +import Common 1.0 // ===================================================================