libtest: Fix bugs in assert_file_has_content()

First, we need to preserve whitespace in the regexps.  Second,
in the error path, all of our variables were wrong.

Commit 376a2cc3f5 is an excellent
poster child for how many bugs one can introduce in a single commit
for a ~5 line function.

Closes: #777
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-05-17 17:03:54 -04:00 committed by Atomic Bot
parent 69d8bfa042
commit 2ada15aff3

View File

@ -143,10 +143,10 @@ assert_not_has_dir () {
assert_file_has_content () {
fpath=$1
shift
for re in $@; do
for re in "$@"; do
if ! grep -q -e "$re" "$fpath"; then
sed -e 's/^/# /' < "$1" >&2
echo 1>&2 "File '$1' doesn't match regexp '$2'"
sed -e 's/^/# /' < "$fpath" >&2
echo 1>&2 "File '$fpath' doesn't match regexp '$re'"
exit 1
fi
done