From 986bbddd834bb4d73606e1a019bbb0ded554b176 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 16 Aug 2017 14:52:17 +0200 Subject: [PATCH] feat(tools): check and test qml if it's necessary! --- tools/check_qml_syntax | 30 +++++++++++++--------------- tools/test_qml | 44 +++++++++++++++++++++++------------------- tools/update_resources | 14 +++++++------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/tools/check_qml_syntax b/tools/check_qml_syntax index 74b98d120..df0b0ca35 100755 --- a/tools/check_qml_syntax +++ b/tools/check_qml_syntax @@ -18,34 +18,30 @@ cd $SCRIPT_DIR/.. # ============================================================================== if ! [ -x "$( command -v "$LINTER" )" ]; then - printf "${RED}Unable to found `$LINTER`. No tests can be executed.${NC}\n" - exit 0 + printf "${RED}Unable to found `$LINTER`.${NC}\n" + exit 1 fi -"${LINTER}" -v +"${LINTER}" -v 2> /dev/null 1>&2 if [[ $? != 0 ]] ; then - printf "${RED}Unable to check qml syntax.${NC}\n" - exit 0 + printf "${RED}Unable to check qml syntax.${NC}\n" + exit 1 fi printf "${BLUE}Checking qml files...${NC}\n" so_far_so_good=0 -while read line -do - result=$( - printf "$line" | - sed -n 's/^\s*<\s*file\s*>\s*\(.*\.\(qml\|js\)\)\s*<\s*\/\s*file\s*>\s*$/\1/p' - ) - if [[ ! -z $result ]] && ! $LINTER "$result"; then - so_far_so_good=1 - fi -done < $RESOURCES_FILE +while read file; do + $LINTER "$file" + if [[ $? != 0 ]] ; then + so_far_so_good=1 + fi +done < <(git diff --name-only --cached | grep -E '\.qml|js|js\.spec$') if [[ $so_far_so_good == 0 ]]; then - printf "${GREEN}Done. No qml error found.\n" + printf "${GREEN}Done. No qml error found.\n" else - printf "${RED}One or more errors were found. Please to fix them.\n" + printf "${RED}One or more errors were found. Please to fix them.\n" fi printf "${NC}" diff --git a/tools/test_qml b/tools/test_qml index 69603ac09..347f76f68 100755 --- a/tools/test_qml +++ b/tools/test_qml @@ -28,38 +28,42 @@ if ! [ -x "$( command -v "$TEST_RUNNER" )" ]; then exit 0 fi -so_far_so_good=0 +git diff --name-only --cached | grep -Eq '\.qml|js|js\.spec$' +if [[ $? != 0 ]] ; then + exit 0 +fi # Check all `*.spec.qml` files. +so_far_so_good=0 while read line do - source_file=$( - printf "$line" | - sed -n 's/^\s*<\s*file\s*>\s*\(.*\.\(qml\|js\)\)\s*<\s*\/\s*file\s*>\s*$/\1/p' + source_file=$( + printf "$line" | + sed -n 's/^\s*<\s*file\s*>\s*\(.*\.\(qml\|js\)\)\s*<\s*\/\s*file\s*>\s*$/\1/p' ) - if [[ ! -z $source_file ]]; then - spec_file="${source_file%.*}.${TEST_FILE_EXTENSION}" + if [[ ! -z $source_file ]]; then + spec_file="${source_file%.*}.${TEST_FILE_EXTENSION}" - if [ -f $spec_file ]; then - printf "${BLUE}Running unit qml tests of '${source_file}'...${NC}\n" - $TEST_RUNNER -import $DEV_MODULES_PATH -import $MODULES_PATH -import $SCRIPTS_PATH -input "$spec_file" + if [ -f $spec_file ]; then + printf "${BLUE}Running unit qml tests of '${source_file}'...${NC}\n" + $TEST_RUNNER -import $DEV_MODULES_PATH -import $MODULES_PATH -import $SCRIPTS_PATH -input "$spec_file" - if [[ $? == 0 ]]; then - printf "${GREEN}All unit tests have succeeded for '${spec_file}'.\n" - else - printf "${RED}Unit tests have failed for '${spec_file}'.\n" - so_far_so_good=1 - fi - printf "${NC}\n" - fi + if [[ $? == 0 ]]; then + printf "${GREEN}All unit tests have succeeded for '${spec_file}'.\n" + else + printf "${RED}Unit tests have failed for '${spec_file}'.\n" + so_far_so_good=1 + fi + printf "${NC}\n" fi + fi done < $RESOURCES_FILE if [[ $so_far_so_good == 0 ]]; then - printf "${GREEN}Done. All tests have succeeded.\n" + printf "${GREEN}Done. All tests have succeeded.\n" else - printf "${RED}Fail. One or many tests have failed.\n" - so_far_so_good=1 + printf "${RED}Fail. One or many tests have failed.\n" + so_far_so_good=1 fi printf "${NC}\n" diff --git a/tools/update_resources b/tools/update_resources index e1d77a1dc..d67cf31e2 100755 --- a/tools/update_resources +++ b/tools/update_resources @@ -20,14 +20,14 @@ echo ' for filename in $(find ui/modules/ ui/scripts/ ui/views/ assets/ -type f | sort) do - basename="${filename##*/}" - extension="${filename##*.}" + basename="${filename##*/}" + extension="${filename##*.}" - if [[ $extension == @(svg|png|jpg|js|ttf) || - $basename == qmldir || - ($extension == qml && $basename != *\.spec\.qml) ]]; then - echo " $filename" >> $RESOURCES_FILE - fi + if [[ $extension == @(svg|png|jpg|js|ttf) || + $basename == qmldir || + ($extension == qml && $basename != *\.spec\.qml) ]]; then + echo " $filename" >> $RESOURCES_FILE + fi done echo '