libtest: show files' contents when assertions about them fail
I've seen an intermittent test failure in an autobuilder (sbuild) environment where logs from failed builds cannot be retrieved, but I can no longer reproduce it. Put the contents of the offending file in the test's failing output so that if the failure comes back, it can be debugged. Signed-off-by: Simon McVittie <smcv@debian.org> Closes: #264 Approved by: cgwalters
This commit is contained in:
parent
e9a1809c4d
commit
24cab773a2
|
|
@ -100,13 +100,17 @@ assert_has_dir () {
|
||||||
|
|
||||||
assert_not_has_file () {
|
assert_not_has_file () {
|
||||||
if test -f "$1"; then
|
if test -f "$1"; then
|
||||||
echo 1>&2 "File '$1' exists"; exit 1
|
sed -e 's/^/# /' < "$1" >&2
|
||||||
|
echo 1>&2 "File '$1' exists"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_not_file_has_content () {
|
assert_not_file_has_content () {
|
||||||
if grep -q -e "$2" "$1"; then
|
if grep -q -e "$2" "$1"; then
|
||||||
echo 1>&2 "File '$1' incorrectly matches regexp '$2'"; exit 1
|
sed -e 's/^/# /' < "$1" >&2
|
||||||
|
echo 1>&2 "File '$1' incorrectly matches regexp '$2'"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,13 +122,17 @@ assert_not_has_dir () {
|
||||||
|
|
||||||
assert_file_has_content () {
|
assert_file_has_content () {
|
||||||
if ! grep -q -e "$2" "$1"; then
|
if ! grep -q -e "$2" "$1"; then
|
||||||
echo 1>&2 "File '$1' doesn't match regexp '$2'"; exit 1
|
sed -e 's/^/# /' < "$1" >&2
|
||||||
|
echo 1>&2 "File '$1' doesn't match regexp '$2'"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_file_empty() {
|
assert_file_empty() {
|
||||||
if test -s "$1"; then
|
if test -s "$1"; then
|
||||||
echo 1>&2 "File '$1' is not empty"; exit 1
|
sed -e 's/^/# /' < "$1" >&2
|
||||||
|
echo 1>&2 "File '$1' is not empty"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue