--- /dev/null
+## Copyright (C) 1996-2022 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+
+acl foo browser *
sbindir=$2
configFile=$3
+# If set, expect non-zero Squid exit code, with a matching stderr message
+failureRegex=""
+
instructionsFile="$configFile.instructions"
if test -e $instructionsFile
then
continue; # skip comment lines
fi
+ 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
+
+ continue;
+ fi
+
if test "$instructionName" = "skip-unless-autoconf-defines"
then
# Skip test unless the given macro is #defined in autoconf.h
exit 1;
fi
done < $instructionsFile
+fi
+
+errorLog="squid-stderr.log"
- # TODO: Add support for the "require-failure" instruction.
+$sbindir/squid -k parse -f $configFile 2> $errorLog
+result=$?
+
+if test -z "$failureRegex"
+then
+ # a positive test does not require special $result interpretation
+ exit $?
fi
-exec $sbindir/squid -k parse -f $configFile
+if test "$result" -eq 0
+then
+ echo "ERROR: Squid successfully parsed malformed $configFile instead of rejecting it"
+ exit 1;
+fi
+
+if ! grep -q -E "$failureRegex" $errorLog
+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
+