diff --git a/tests/tools/private/pre-commit b/tests/tools/private/pre-commit index 9c9ab4828..501655c37 100755 --- a/tests/tools/private/pre-commit +++ b/tests/tools/private/pre-commit @@ -1,5 +1,29 @@ #!/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" -exit $? +if [[ $? != 0 ]] ; then + exit 1 +fi + +# Check JS lib. +printf "${BLUE}Testing scripts lib...${NC}\n" + +so_far_so_good=0 +qmltestrunner -input "./tests/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}" + +exit $so_far_so_good diff --git a/tests/ui/scripts/Utils/utils.spec.qml b/tests/ui/scripts/Utils/utils.spec.qml new file mode 100644 index 000000000..f57cfc96c --- /dev/null +++ b/tests/ui/scripts/Utils/utils.spec.qml @@ -0,0 +1,23 @@ +import QtQuick 2.7 +import QtTest 1.1 + +// Explicit import, `utils.js` is not accessible in resources file +// when tests are executed. +import './utils.js' as Utils + +TestCase { + name: 'UtilsTests' + + function test_snakeToCamel_data () { + return [ + { input: 'foo_bar', output: 'fooBar' }, + { input: 'george_abitbol', output: 'georgeAbitbol' }, + { input: 'billTremendousAndHubert', output: 'billTremendousAndHubert' }, + { input: 'foo_bAr_BAZ', output: 'fooBArBAZ' }, + ] + } + + function test_snakeToCamel (data) { + compare(Utils.snakeToCamel(data.input), data.output) + } +}