summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2021-06-22 11:44:04 -0400
committerGitHub <noreply@github.com>2021-06-22 11:44:04 -0400
commit6714024bedb3326f086c09c3a4608f744970072b (patch)
tree0516a5f6dc9605c1e1673420a5b2a7088ca07206
parent26f7f65343948906baabb05acaf15ee67c55171d (diff)
parent03b8836e6b00625fae62310e88fbc6ef2e834345 (diff)
downloadbubblewrap-6714024bedb3326f086c09c3a4608f744970072b.tar.gz
Merge pull request #433 from smcv/libtest-core
libtest-core: Sync with libostree
-rw-r--r--Makefile.am7
-rw-r--r--tests/libtest-core.sh42
-rw-r--r--tests/libtest.sh37
-rwxr-xr-xtests/test-run.sh2
4 files changed, 74 insertions, 14 deletions
diff --git a/Makefile.am b/Makefile.am
index d3150c9..550a6e7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,10 +45,15 @@ include Makefile-docs.am
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
LOG_COMPILER =
TESTS = tests/test-run.sh
-TESTS_ENVIRONMENT = BWRAP=$(abs_top_builddir)/test-bwrap
+TESTS_ENVIRONMENT = \
+ BWRAP=$(abs_top_builddir)/test-bwrap \
+ G_TEST_BUILDDIR=$(abs_top_builddir) \
+ G_TEST_SRCDIR=$(abs_top_srcdir) \
+ $(NULL)
EXTRA_DIST += $(TESTS)
EXTRA_DIST += tests/libtest-core.sh
+EXTRA_DIST += tests/libtest.sh
if ENABLE_BASH_COMPLETION
bashcompletiondir = $(BASH_COMPLETION_DIR)
diff --git a/tests/libtest-core.sh b/tests/libtest-core.sh
index e08c4c2..9632e90 100644
--- a/tests/libtest-core.sh
+++ b/tests/libtest-core.sh
@@ -5,10 +5,13 @@
#
# Known copies are in the following repos:
#
-# - https://github.com/projectatomic/rpm-ostree
+# - https://github.com/containers/bubblewrap
+# - https://github.com/coreos/rpm-ostree
#
# Copyright (C) 2017 Colin Walters <walters@verbum.org>
#
+# SPDX-License-Identifier: LGPL-2.0+
+#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
@@ -33,13 +36,19 @@ assert_not_reached () {
}
# Some tests look for specific English strings. Use a UTF-8 version
-# of the C (POSIX) locale if we have one, or fall back to POSIX
+# of the C (POSIX) locale if we have one, or fall back to en_US.UTF-8
# (https://sourceware.org/glibc/wiki/Proposals/C.UTF-8)
-if locale -a | grep C.UTF-8 >/dev/null; then
- export LC_ALL=C.UTF-8
+#
+# If we can't find the locale command assume we have support for C.UTF-8
+# (e.g. musl based systems)
+if type -p locale >/dev/null; then
+ export LC_ALL=$(locale -a | grep -iEe '^(C|en_US)\.(UTF-8|utf8)$' | head -n1 || true)
+ if [ -z "${LC_ALL}" ]; then fatal "Can't find suitable UTF-8 locale"; fi
else
- export LC_ALL=C
+ export LC_ALL=C.UTF-8
fi
+# A GNU extension, used whenever LC_ALL is not C
+unset LANGUAGE
# This should really be the default IMO
export G_DEBUG=fatal-warnings
@@ -119,10 +128,23 @@ assert_file_has_content () {
done
}
+assert_file_has_content_once () {
+ fpath=$1
+ shift
+ for re in "$@"; do
+ if ! test $(grep -e "$re" "$fpath" | wc -l) = "1"; then
+ _fatal_print_file "$fpath" "File '$fpath' doesn't match regexp '$re' exactly once"
+ fi
+ done
+}
+
assert_file_has_content_literal () {
- if ! grep -q -F -e "$2" "$1"; then
- _fatal_print_file "$1" "File '$1' doesn't match fixed string list '$2'"
- fi
+ fpath=$1; shift
+ for s in "$@"; do
+ if ! grep -q -F -e "$s" "$fpath"; then
+ _fatal_print_file "$fpath" "File '$fpath' doesn't match fixed string list '$s'"
+ fi
+ done
}
assert_file_has_mode () {
@@ -159,10 +181,6 @@ skip() {
exit 0
}
-extract_child_pid() {
- grep child-pid "$1" | sed "s/^.*: \([0-9]*\).*/\1/"
-}
-
report_err () {
local exit_status="$?"
{ { local BASH_XTRACEFD=3; } 2> /dev/null
diff --git a/tests/libtest.sh b/tests/libtest.sh
new file mode 100644
index 0000000..41b209b
--- /dev/null
+++ b/tests/libtest.sh
@@ -0,0 +1,37 @@
+# Source library for shell script tests.
+# Add non-bubblewrap-specific code to libtest-core.sh instead.
+#
+# Copyright (C) 2017 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+if [ -n "${G_TEST_SRCDIR:-}" ]; then
+ test_srcdir="${G_TEST_SRCDIR}/tests"
+else
+ test_srcdir=$(dirname $0)
+fi
+
+if [ -n "${G_TEST_BUILDDIR:-}" ]; then
+ test_builddir="${G_TEST_BUILDDIR}/tests"
+else
+ test_builddir=$(dirname $0)
+fi
+
+. "${test_srcdir}/libtest-core.sh"
+
+extract_child_pid() {
+ grep child-pid "$1" | sed "s/^.*: \([0-9]*\).*/\1/"
+}
diff --git a/tests/test-run.sh b/tests/test-run.sh
index af690cf..1cc048b 100755
--- a/tests/test-run.sh
+++ b/tests/test-run.sh
@@ -7,7 +7,7 @@ PATH="$PATH:/usr/sbin:/sbin"
srcd=$(cd $(dirname $0) && pwd)
-. ${srcd}/libtest-core.sh
+. ${srcd}/libtest.sh
bn=$(basename $0)
tempdir=$(mktemp -d /var/tmp/tap-test.XXXXXX)