From: Alex Rousskov Date: Mon, 16 Jan 2023 23:24:41 +0000 (+0000) Subject: Maintenance: Check for expected squid-conf-tests notifications (#1231) X-Git-Tag: SQUID_6_0_1~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2bbaef0eb25170687fc191b20bd8e149e5d24729;p=thirdparty%2Fsquid.git Maintenance: Check for expected squid-conf-tests notifications (#1231) Sometimes, Squid must accept a configuration file while also logging a WARNING or even an ERROR message. The new "expect-message" test case instruction tells test-suite/test-squid-conf.sh to check for a given expected message while still expecting configuration acceptance. Two test cases (mgr_passwd.conf and time_units.conf) were enhanced. We plan to use this feature in future tests already under development. --- diff --git a/test-suite/squidconf/mgr_passwd.conf.instructions b/test-suite/squidconf/mgr_passwd.conf.instructions new file mode 100644 index 0000000000..9635620f9e --- /dev/null +++ b/test-suite/squidconf/mgr_passwd.conf.instructions @@ -0,0 +1,2 @@ +expect-message ERROR:.*menu.*already.has.a.password + diff --git a/test-suite/squidconf/time_units.conf.instructions b/test-suite/squidconf/time_units.conf.instructions new file mode 100644 index 0000000000..9557f6de39 --- /dev/null +++ b/test-suite/squidconf/time_units.conf.instructions @@ -0,0 +1,2 @@ +expect-message url_rewrite_timeout.*WARNING:.missing.time.unit.*using.*second + diff --git a/test-suite/test-squid-conf.sh b/test-suite/test-squid-conf.sh index d1425d8b9a..33fd1941ba 100755 --- a/test-suite/test-squid-conf.sh +++ b/test-suite/test-squid-conf.sh @@ -15,8 +15,33 @@ top_builddir=$1 sbindir=$2 configFile=$3 -# If set, expect non-zero Squid exit code, with a matching stderr message -failureRegex="" +# If set to yes, expect non-zero Squid exit code, +# with stderr output matching $messageRegex. +expectFailure=no + +# If set, expect a matching stderr message +messageRegex="" + +expectMessage() +{ + local p1="$1" + local p2="$2" + local where="$3" + + if test -n "$messageRegex" + then + echo "$where: ERROR: Repeated message-setting instruction"; + exit 1 + fi + + messageRegex="$p1" + + if test -n "$p2" + then + echo "$where: ERROR: Bad message-setting instruction: Unexpected second parameter: $p2" + exit 1 + fi +} instructionsFile="$configFile.instructions" if test -e $instructionsFile @@ -39,20 +64,14 @@ then if test "$instructionName" = "expect-failure" then - if test -n "$failureRegex" - then - echo "$here: ERROR: Repeated $instructionName instruction"; - exit 1; - fi - - failureRegex="$p1" - - if test -n "$p2" - then - echo "$here: ERROR: Bad $instructionName instruction: Unexpected second parameter: $p2"; - exit 1; - fi + expectFailure=yes + expectMessage "$p1" "$p2" "$here" + continue; + fi + if test "$instructionName" = "expect-message" + then + expectMessage "$p1" "$p2" "$here" continue; fi @@ -97,27 +116,60 @@ errorLog="squid-stderr.log" $sbindir/squid -k parse -f $configFile 2> $errorLog result=$? -if test -z "$failureRegex" +# this is the value we return to our caller; +# must be set by the code below using updateOutcome +exitCode="" +updateOutcome() +{ + local newOutcome="$1" + # never overwrite non-zero values (i.e. only overwrite null and zero) + if test -z "$exitCode" -o "$exitCode" = 0 + then + exitCode="$newOutcome" + fi +} + +if test -n "$messageRegex" && ! grep -q -E "$messageRegex" $errorLog +then + echo "ERROR: Squid did not emit an expected message to stderr" + echo " expected message regex: $messageRegex" + updateOutcome 1 +fi + +if test $expectFailure = no then - # a positive test does not require special $result interpretation - exit $? + if test "$result" -ne 0 + then + echo "ERROR: Squid rejected valid $configFile; Squid exit code: $result" + updateOutcome $result + else + # stay silent about ordinary success + updateOutcome 0 + fi +else + if test "$result" -eq 0 + then + echo "ERROR: Squid successfully parsed malformed $configFile instead of rejecting it" + updateOutcome 1 + else + # stay silent about this expected failure (invisible in our output) + #echo "Squid rejected malformed $configFile as expected; Squid exit code: $result" + updateOutcome 0 + fi fi -if test "$result" -eq 0 +if test -z "$exitCode" then - echo "ERROR: Squid successfully parsed malformed $configFile instead of rejecting it" - exit 1; + echo "ERROR: BUG: Forgot to set \$exitCode: $0" + updateOutcome 1 fi -if ! grep -q -E "$failureRegex" $errorLog +# after a bad outcome, share Squid output +if test $exitCode -ne 0 then - echo "ERROR: Squid rejected malformed $configFile but did not emit an expected message to stderr" - echo " expected error message regex: $failureRegex" echo "Squid stderr output:" cat $errorLog - exit 1; fi -echo "Squid rejected malformed $configFile as expected; Squid exit code: $result" -exit 0 +exit $exitCode