From c934fc8f9904d66c443d784ec3f93209b7b9f1b0 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 26 Nov 2019 09:25:15 +0100 Subject: [PATCH] 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.] --- tests/kolainst/libtest-core.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/kolainst/libtest-core.sh b/tests/kolainst/libtest-core.sh index 64b3e0a3..471a63f0 100644 --- a/tests/kolainst/libtest-core.sh +++ b/tests/kolainst/libtest-core.sh @@ -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" "$@"