libtest-core: Add assert_files_equal

[Originally from bubblewrap commits c5c999a7 "tests: test --userns"
and 3e5fe1bf "tests: Better error message if assert_files_equal fails";
separated into this commit by Simon McVittie.]
This commit is contained in:
Alexander Larsson 2019-11-26 09:25:15 +01:00 committed by Simon McVittie
parent 0fcf4a3f30
commit c934fc8f99
1 changed files with 18 additions and 0 deletions

View File

@ -83,6 +83,18 @@ _fatal_print_file() {
fatal "$@"
}
_fatal_print_files() {
file1="$1"
shift
file2="$1"
shift
ls -al "$file1" >&2
sed -e 's/^/# /' < "$file1" >&2
ls -al "$file2" >&2
sed -e 's/^/# /' < "$file2" >&2
fatal "$@"
}
assert_not_has_file () {
if test -f "$1"; then
_fatal_print_file "$1" "File '$1' exists"
@ -156,6 +168,12 @@ assert_file_empty() {
fi
}
assert_files_equal() {
if ! cmp "$1" "$2"; then
_fatal_print_files "$1" "$2" "File '$1' and '$2' is not equal"
fi
}
# Use to skip all of these tests
skip() {
echo "1..0 # SKIP" "$@"