From c934fc8f9904d66c443d784ec3f93209b7b9f1b0 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 26 Nov 2019 09:25:15 +0100 Subject: [PATCH 1/4] 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" "$@" From d7cdde5d3445e004c783f86a985d58725f3e6646 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 18 Apr 2021 12:45:24 +0100 Subject: [PATCH 2/4] libtest-core: On failure, make it clearer what has happened If we fail as a result of `set -x`, It's often not completely obvious which command failed or how. Use a trap on ERR to show the command that failed, and its exit status. Signed-off-by: Simon McVittie --- tests/kolainst/libtest-core.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/kolainst/libtest-core.sh b/tests/kolainst/libtest-core.sh index 471a63f0..7179a408 100644 --- a/tests/kolainst/libtest-core.sh +++ b/tests/kolainst/libtest-core.sh @@ -179,3 +179,11 @@ skip() { echo "1..0 # SKIP" "$@" exit 0 } + +report_err () { + local exit_status="$?" + { { local BASH_XTRACEFD=3; } 2> /dev/null + echo "Unexpected nonzero exit status $exit_status while running: $BASH_COMMAND" >&2 + } 3> /dev/null +} +trap report_err ERR From c0157f96b2c797c35391f1c50fab5659259be925 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 18 Jun 2021 10:13:36 +0100 Subject: [PATCH 3/4] libtest-core: Update URL of rpm-ostree Signed-off-by: Simon McVittie --- tests/kolainst/libtest-core.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/kolainst/libtest-core.sh b/tests/kolainst/libtest-core.sh index 7179a408..8d1f36c6 100644 --- a/tests/kolainst/libtest-core.sh +++ b/tests/kolainst/libtest-core.sh @@ -5,7 +5,7 @@ # # Known copies are in the following repos: # -# - https://github.com/projectatomic/rpm-ostree +# - https://github.com/coreos/rpm-ostree # # Copyright (C) 2017 Colin Walters # From 14d6e757520c853cd14ada5a4d0a084ddf400f51 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 18 Jun 2021 10:14:01 +0100 Subject: [PATCH 4/4] libtest-core: Mention bubblewrap as a user of this file Signed-off-by: Simon McVittie --- tests/kolainst/libtest-core.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/kolainst/libtest-core.sh b/tests/kolainst/libtest-core.sh index 8d1f36c6..9632e905 100644 --- a/tests/kolainst/libtest-core.sh +++ b/tests/kolainst/libtest-core.sh @@ -5,6 +5,7 @@ # # Known copies are in the following repos: # +# - https://github.com/containers/bubblewrap # - https://github.com/coreos/rpm-ostree # # Copyright (C) 2017 Colin Walters