summaryrefslogtreecommitdiff
path: root/trust
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2018-04-10 09:46:56 +0200
committerDaiki Ueno <ueno@gnu.org>2018-04-10 17:57:11 +0200
commite4a5466e5e3cfe22344e79c6e1a0ad9a7945a602 (patch)
treed71e00b6e544d50aa4f470b325c780187514d8bd /trust
parentdcb6ee3fa89e0c9586e2b09e1f60aa076f263123 (diff)
test: Factor out common harness from test-extract.in
Diffstat (limited to 'trust')
-rw-r--r--trust/Makefile.am7
-rw-r--r--trust/test-extract.sh (renamed from trust/test-extract.in)92
-rw-r--r--trust/test-init.sh.in106
3 files changed, 112 insertions, 93 deletions
diff --git a/trust/Makefile.am b/trust/Makefile.am
index 726d249..dfc64eb 100644
--- a/trust/Makefile.am
+++ b/trust/Makefile.am
@@ -303,12 +303,15 @@ frob_token_SOURCES = trust/frob-token.c
frob_token_LDADD = $(trust_LIBS)
frob_token_CFLAGS = $(trust_CFLAGS)
-noinst_SCRIPTS += trust/test-extract
+noinst_SCRIPTS += trust/test-extract.sh
+if !OS_WIN32
installcheck-local:
- sh $(builddir)/trust/test-extract
+ builddir="$(abs_top_builddir)/trust" $(SHELL) $(srcdir)/trust/test-extract.sh
+endif
EXTRA_DIST += \
trust/input \
trust/fixtures \
+ trust/test-extract.sh \
$(NULL)
diff --git a/trust/test-extract.in b/trust/test-extract.sh
index ec4387d..61745a9 100644
--- a/trust/test-extract.in
+++ b/trust/test-extract.sh
@@ -1,48 +1,6 @@
#!/bin/sh
-set -euf
-
-# -----------------------------------------------------------------------------
-# Basic fundamentals
-
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-datarootdir=@datarootdir@
-datadir=@datadir@
-sysconfdir=@sysconfdir@
-libdir=@libdir@
-libexecdir=@libexecdir@
-privatedir=@privatedir@
-with_trust_paths=@with_trust_paths@
-script=$(basename $0)
-
-# -----------------------------------------------------------------------------
-# Testing
-
-warning()
-{
- echo "$script: $@" >&2
-}
-
-assert_fail()
-{
- warning $@
- exit 1
-}
-
-assert_contains()
-{
- if ! grep -qF $2 $1; then
- assert_fail "$1 does not contain $2"
- fi
-}
-
-assert_not_contains()
-{
- if grep -qF $2 $1; then
- assert_fail "$1 contains $2"
- fi
-}
+. "${builddir=.}/test-init.sh"
teardown()
{
@@ -56,12 +14,6 @@ teardown()
TD=""
}
-teardown_dirty()
-{
- echo "not ok $TEST_NUMBER $TEST_NAME"
- teardown
-}
-
openssl_quiet()
(
command='/Generating a|-----|^[.+]+$|writing new private key/d'
@@ -69,12 +21,6 @@ openssl_quiet()
openssl $@ 2>&1 >&3 3>&- | sed -r "$command" 3>&-
)
-skip()
-{
- TEST_SKIP=yes
- echo "ok $TEST_NUMBER # skip $TEST_NAME: $@"
-}
-
setup()
{
# Parse the trust paths
@@ -126,42 +72,6 @@ setup()
TD="$SOURCE_1/anchors/cert_1.pem $SOURCE_2/anchors/cert_2.pem $SOURCE_2/anchors/cert_3.pem $TD"
}
-run()
-{
- TOTAL=0
- for TEST_NAME in $@; do
- TOTAL=$(expr $TOTAL + 1)
- done
-
- echo "1..$TOTAL"
-
- TEST_NUMBER=0
- for TEST_NAME in $@; do
- TEST_NUMBER=$(expr $TEST_NUMBER + 1)
- (
- trap teardown_dirty EXIT
- trap "teardown_dirty; exit 127" INT TERM
- TD=""
-
- TEST_SKIP=no
- setup
-
- if [ $TEST_SKIP != "yes" ]; then
- $TEST_NAME
- fi
- if [ $TEST_SKIP != "yes" ]; then
- echo "ok $TEST_NUMBER $TEST_NAME"
- fi
-
- trap - EXIT
- teardown
- )
- done
-}
-
-# -----------------------------------------------------------------------------
-# Main tests
-
test_extract()
{
trust extract --filter=ca-anchors --format=pem-bundle \
diff --git a/trust/test-init.sh.in b/trust/test-init.sh.in
new file mode 100644
index 0000000..384fb25
--- /dev/null
+++ b/trust/test-init.sh.in
@@ -0,0 +1,106 @@
+#!/bin/sh
+
+set -euf
+
+# -----------------------------------------------------------------------------
+# Basic fundamentals
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+datarootdir=@datarootdir@
+datadir=@datadir@
+sysconfdir=@sysconfdir@
+libdir=@libdir@
+libexecdir=@libexecdir@
+privatedir=@privatedir@
+with_trust_paths=@with_trust_paths@
+script=$(basename $0)
+
+# -----------------------------------------------------------------------------
+# Testing
+
+warning()
+{
+ echo "$script: $@" >&2
+}
+
+assert_fail()
+{
+ warning $@
+ exit 1
+}
+
+assert_contains()
+{
+ if ! grep -qF $2 $1; then
+ assert_fail "$1 does not contain $2"
+ fi
+}
+
+assert_not_contains()
+{
+ if grep -qF $2 $1; then
+ assert_fail "$1 contains $2"
+ fi
+}
+
+teardown()
+{
+ :
+}
+
+teardown_dirty()
+{
+ echo "not ok $TEST_NUMBER $TEST_NAME"
+ teardown
+}
+
+skip()
+{
+ TEST_SKIP=yes
+ echo "ok $TEST_NUMBER # skip $TEST_NAME: $@"
+}
+
+setup()
+{
+ :
+}
+
+run()
+{
+ TOTAL=0
+ for TEST_NAME in $@; do
+ TOTAL=$(expr $TOTAL + 1)
+ done
+
+ echo "1..$TOTAL"
+
+ TEST_NUMBER=0
+ for TEST_NAME in $@; do
+ TEST_NUMBER=$(expr $TEST_NUMBER + 1)
+ (
+ trap teardown_dirty EXIT
+ trap "teardown_dirty; exit 127" INT TERM
+ TD=""
+
+ PATH="$exec_prefix/bin:$PATH"
+ export PATH
+
+ PKG_CONFIG_PATH="$libdir/pkgconfig:$datadir/pkgconfig"
+ export PKG_CONFIG_PATH
+
+ TEST_SKIP=no
+ setup
+
+ if [ $TEST_SKIP != "yes" ]; then
+ $TEST_NAME
+ fi
+ if [ $TEST_SKIP != "yes" ]; then
+ echo "ok $TEST_NUMBER $TEST_NAME"
+ fi
+
+ trap - EXIT
+ teardown
+ )
+ done
+}