From a8ec153c9b84ef248066a6f8bf48a92584572c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20COUDERC?= Date: Fri, 2 Jun 2017 11:27:48 +0000 Subject: [PATCH] Add autopkgtests to validate XMLs structure and avoid bugs like #862228 --- debian/changelog | 1 + debian/tests/control | 2 ++ debian/tests/validate-svgs-xmllint | 22 ++++++++++++++ debian/tests/validate-xmls-lint | 22 ++++++++++++++ debian/tests/xmllint-functions | 49 ++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 debian/tests/control create mode 100755 debian/tests/validate-svgs-xmllint create mode 100755 debian/tests/validate-xmls-lint create mode 100755 debian/tests/xmllint-functions diff --git a/debian/changelog b/debian/changelog index 68cf582..02aa95c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ desktop-base (10.0.0~exp1) UNRELEASED; urgency=medium * Build with debhelper, bump compatibility level to 10, drop CDBS build dependency. + * Add autopkgtests to validate XMLs structure and avoid bugs like #862228. -- Aurélien COUDERC Mon, 30 Jan 2017 22:21:40 +0100 diff --git a/debian/tests/control b/debian/tests/control new file mode 100644 index 0000000..e5f92c4 --- /dev/null +++ b/debian/tests/control @@ -0,0 +1,2 @@ +Tests: validate-xmls-lint, validate-svgs-xmllint +Depends: libxml2-utils diff --git a/debian/tests/validate-svgs-xmllint b/debian/tests/validate-svgs-xmllint new file mode 100755 index 0000000..f533b1c --- /dev/null +++ b/debian/tests/validate-svgs-xmllint @@ -0,0 +1,22 @@ +#!/bin/bash + +dir_name=$(dirname $0) +. ${dir_name}/xmllint-functions + +XML_FILE_PATTERN="*.svg" +XML_LINT_SUMMARY="svgs-xmllint-summary.csv" +if [[ -n ${AUTOPKGTEST_ARTIFACTS} ]] ; then + XML_LINT_SUMMARY="${AUTOPKGTEST_ARTIFACTS}/${XML_LINT_SUMMARY}" +fi + + +xml_lint_command="lint_xmls ${XML_FILE_PATTERN} ${XML_LINT_SUMMARY}" +echo "$0: running '${xml_lint_command}'..." +${xml_lint_command} +xml_lint_result=$? + +echo "$0: '${xml_lint_command}' returned ${xml_lint_result}" + + +exit ${xml_lint_result} + diff --git a/debian/tests/validate-xmls-lint b/debian/tests/validate-xmls-lint new file mode 100755 index 0000000..a24762d --- /dev/null +++ b/debian/tests/validate-xmls-lint @@ -0,0 +1,22 @@ +#!/bin/bash + +dir_name=$(dirname $0) +. ${dir_name}/xmllint-functions + +XML_FILE_PATTERN="*.xml" +XML_LINT_SUMMARY="xmls-lint-summary.csv" +if [[ -n ${AUTOPKGTEST_ARTIFACTS} ]] ; then + XML_LINT_SUMMARY="${AUTOPKGTEST_ARTIFACTS}/${XML_LINT_SUMMARY}" +fi + + +xml_lint_command="lint_xmls ${XML_FILE_PATTERN} ${XML_LINT_SUMMARY}" +echo "$0: running '${xml_lint_command}'..." +${xml_lint_command} +xml_lint_result=$? + +echo "$0: '${xml_lint_command}' returned ${xml_lint_result}" + + +exit ${xml_lint_result} + diff --git a/debian/tests/xmllint-functions b/debian/tests/xmllint-functions new file mode 100755 index 0000000..9fb98d9 --- /dev/null +++ b/debian/tests/xmllint-functions @@ -0,0 +1,49 @@ +#!/bin/bash + +lint_xmls() { + local xml_file_pattern=$1 + local xml_lint_summary=$2 + + if [ "$#" -ne 2 ] ; then + echo "$0: wrong number of arguments." + echo "Expected:" + echo " $0 xml_file_pattern summary_file_name" + return 255 + fi + + echo "Running xmllint for pattern '${xml_file_pattern}'" + echo "Current directory is '$(pwd)'" + echo "Result will be stored in ${xml_lint_summary}" + echo + + echo "file,xmllint_status" > ${xml_lint_summary} + + local files_list=$(find . -name "${xml_file_pattern}") + local nb_files=$(echo "${files_list}" | wc -l) + local nb_ok=0 + local nb_errors=0 + + echo "${nb_files} files will be checked" + + while IFS= read -d $'\n' -r xml_file ; do + echo "xmllinting file '${xml_file}'" + xmllint --noout ${xml_file} + local xmllint_result=$? + echo "${xml_file},${xmllint_result}" >> ${xml_lint_summary} + if [ ${xmllint_result} -eq 0 ] ; then + echo "'${xml_file}' is OK" + ((nb_ok++)) + else + echo "'${xml_file}' has errors" + ((nb_errors++)) + fi + done <<< "${files_list}" + + echo "Results of xmllint for pattern '${xml_file_pattern}'" + echo " Checked: ${nb_files}" + echo " OK: ${nb_ok}" + echo " Errors: ${nb_errors}" + + return ${nb_errors} + +}