Path: blob/main/contrib/atf/atf-c++/pkg_config_test.sh
39537 views
# Copyright (c) 2008 The NetBSD Foundation, Inc.1# All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions5# are met:6# 1. Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# 2. Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11#12# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425# The following tests assume that the atfc++.pc file is installed in a26# directory that is known by pkg-config. Otherwise they will fail,27# and you will be required to adjust PKG_CONFIG_PATH accordingly.28#29# It would be possible to bypass this requirement by setting the path30# explicitly during the tests, but then this would not do a real check31# to ensure that the installation is working.3233require_pc()34{35pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \36"maybe need to set PKG_CONFIG_PATH?"37}3839check_version()40{41ver1=$($(atf_get_srcdir)/detail/version_helper)42echo "Version reported by builtin PACKAGE_VERSION: ${ver1}"4344atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}"45ver2=$(cat stdout)46echo "Version reported by pkg-config: ${ver2}"4748atf_check_equal ${ver1} ${ver2}49}5051atf_test_case version52version_head()53{54atf_set "descr" "Checks that the version in atf-c++ is correct"55atf_set "require.progs" "pkg-config"56}57version_body()58{59require_pc "atf-c++"6061check_version "atf-c++"62}6364atf_test_case build65build_head()66{67atf_set "descr" "Checks that a test program can be built against" \68"the C++ library based on the pkg-config information"69atf_set "require.progs" "pkg-config"70}71build_body()72{73require_pc "atf-c++"7475atf_check -s eq:0 -o save:stdout -e empty \76pkg-config --variable=cxx atf-c++77cxx=$(cat stdout)78echo "Compiler is: ${cxx}"79atf_require_prog ${cxx}8081cat >tp.cpp <<EOF82#include <iostream>8384#include <atf-c++.hpp>8586ATF_TEST_CASE(tc);87ATF_TEST_CASE_HEAD(tc) {88set_md_var("descr", "A test case");89}90ATF_TEST_CASE_BODY(tc) {91std::cout << "Running\n";92}9394ATF_INIT_TEST_CASES(tcs) {95ATF_ADD_TEST_CASE(tcs, tc);96}97EOF9899atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c++100cxxflags=$(cat stdout)101echo "CXXFLAGS are: ${cxxflags}"102103atf_check -s eq:0 -o save:stdout -e empty \104pkg-config --libs-only-L --libs-only-other atf-c++105ldflags=$(cat stdout)106atf_check -s eq:0 -o save:stdout -e empty \107pkg-config --libs-only-l atf-c++108libs=$(cat stdout)109echo "LDFLAGS are: ${ldflags}"110echo "LIBS are: ${libs}"111112atf_check -s eq:0 -o empty -e empty ${cxx} ${cxxflags} -o tp.o -c tp.cpp113atf_check -s eq:0 -o empty -e empty ${cxx} ${ldflags} -o tp tp.o ${libs}114115libpath=116for f in ${ldflags}; do117case ${f} in118-L*)119dir=$(echo ${f} | sed -e 's,^-L,,')120if [ -z "${libpath}" ]; then121libpath="${dir}"122else123libpath="${libpath}:${dir}"124fi125;;126*)127;;128esac129done130131atf_check -s eq:0 -o empty -e empty test -x tp132atf_check -s eq:0 -o match:'Running' -e empty -x \133"LD_LIBRARY_PATH=${libpath} ./tp tc"134}135136atf_init_test_cases()137{138atf_add_test_case version139atf_add_test_case build140}141142# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4143144145