Skip to content
Snippets Groups Projects
version 2.29 KiB
#!/bin/bash

# Copyright © 2017 Collabora Ltd
#
# This file is part of libcapsule.
#
# libcapsule 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.1 of the
# License, or (at your option) any later version.
#
# libcapsule 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 libcapsule.  If not, see <http://www.gnu.org/licenses/>.

set -eu -o pipefail

. "$(dirname "$0")"/../../tests/libtest.sh

if ! bwrap --ro-bind / / true; then
    skip_all "1..0 # SKIP - cannot run bwrap"
fi

echo_tap "# Working directory: $test_tempdir"
cd "$test_tempdir"
host="${test_tempdir}/host"

CAPSULE_VERSION="$(pkg-config --variable=libexecdir capsule)/capsule-version"

output="$(bwrap --ro-bind / / --ro-bind / "${host}" --dev-bind /dev /dev \
    ${CAPSULE_VERSION} libz.so.1 "${host}")"
set -- $output
is "$1" "${host}"
is "$2" libz.so.1
like "$3" "1.*.*"
like "$4" "${host}/@(usr/lib|lib)/*-linux-gnu*/libz.so.$3"
test -e "${4#${host}}"
pass "successfully found libz"

# Try the same thing without a prefix
output="$(${CAPSULE_VERSION} libz.so.1 "/")"
set -- $output
is "$1" "/"
is "$2" libz.so.1
# TODO: This just returns 1?
#like "$3" "1.*.*"
# TODO: Would be nice if this didn't start with //
like "$4" "+(/)@(usr/lib|lib)/*-linux-gnu*/libz.so.$3"
test -e "$4"
pass "successfully found libz"

# A different way
output="$(${CAPSULE_VERSION} libz.so.1 "")"
set -- $output
is "$1" libz.so.1
# TODO: This just returns 1?
#like "$2" "1.*.*"
like "$3" "/@(usr/lib|lib)/*-linux-gnu*/libz.so.$2"
test -e "$3"
pass "successfully found libz"

# Another different way
output="$(${CAPSULE_VERSION} libz.so.1 "/")"
set -- $output
# TODO: This should probably not try to print NULL
#is "$1" "(null)"
is "$2" libz.so.1
# TODO: This just returns 1?
#like "$3" "1.*.*"
# TODO: Would be nice if this didn't start with //
like "$4" "+(/)@(usr/lib|lib)/*-linux-gnu*/libz.so.$3"
test -e "$4"
pass "successfully found libz"

done_testing

# vim:set sw=4 sts=4 et: