From 4cf3a4411bbb87f43320662c413eebdf53aa8311 Mon Sep 17 00:00:00 2001 From: Chris J <86578804+cjcodeproj@users.noreply.github.com> Date: Sat, 10 Jun 2023 06:22:39 -0500 Subject: [PATCH 1/3] Updates to testing code. --- bin/movietest.sh | 11 ++++++----- bin/test_include.sh | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/bin/movietest.sh b/bin/movietest.sh index da3b61e..f5cfd8e 100755 --- a/bin/movietest.sh +++ b/bin/movietest.sh @@ -5,7 +5,7 @@ CPATH=`dirname $0` . $CPATH/test_include.sh FILELIST=`find . -type f -name "*-bluray*.xml" -o -name "*-dvd.xml" -o -name "*-ultrahd.xml" -o -name "*-vhs.xml"` -# XPATH +# XSDPATH COUNT=0 ERRORS=0 @@ -17,8 +17,8 @@ CLEAN=() # Main Block # -if [ -z $XPATH ]; then - echo "Need schema location in order for XML validation tests" +if [ -z $XSDPATH ]; then + echo "Define XSDPATH if you want to do schema validation" fi for FI in $FILELIST @@ -28,10 +28,11 @@ do if [ $DEBUG ]; then echo $FI fi - if [ ! -z $XPATH ]; then + if [ ! -z $XSDPATH ]; then testxml $FI fi testquotes $FI + # testtrailingws $FI if [ -z $SKIPIT ]; then testinstances $FI fi @@ -59,4 +60,4 @@ fi echo "Clean count: $CC" -# echo ${CLEAN[*]} +exit diff --git a/bin/test_include.sh b/bin/test_include.sh index 24a6dc2..82bf825 100755 --- a/bin/test_include.sh +++ b/bin/test_include.sh @@ -1,34 +1,63 @@ #!/bin/sh + +# +# Test XML for validity testxml() { - xmllint --xinclude --path $XPATH --noout --schema media-schema.xsd $1 --noout >/dev/null 2>&1 + xmllint --xinclude --path $XSDPATH --noout --schema media-schema.xsd $1 --noout >/dev/null 2>&1 if [ $? -ne 0 ]; then echo " ERROR -- Validation error found in $1" ((ERRORS = $ERRORS +1)) + xmllint --xinclude --path $XPATH --noout --schema media-schema.xsd $1 fi } + +# +# Tests for presence of double quotes vs. single quotes +# (They're not bad, it's more of just a style issue) testquotes() { grep -q '"' $1 if [ $? -eq 0 ]; then - echo " ERROR -- Double quote found in $1" - ((ERRORS = $ERRORS +1)) + echo " WARNING -- Double quote found in $1" + ((WARNINGS = $WARNINGS +1)) ((IC = $IC + 1)) fi } + +# +# Test for trailing whitespace +# (not bad, but technically increases the size of the file needlessly) +testtrailingws() +{ + egrep -q " +$" $1 + if [ $? -eq 0 ]; then + echo " WARNING -- Trailing whitespace found in $1" + ((WARNINGS = $WARNINGS +1)) + fi +} + + +# +# Test for instance element in the XML +# (prevents user from accidentally saving possible personal data) testinstances() { xmllint --xpath "//*[local-name()='instances']" --noout $1 >/dev/null 2>&1 if [ $? -eq 0 ]; then echo " ERROR -- Instances element found in $1" - ((ERRORS = $ERRORS +1)) + ((WARNINGS = $WARNINGS +1)) fi } + +# +# Test for comments +# (Comments aren't bad, but you may not want to commit them) testcomments() { grep -q '