xref: /freebsd/contrib/atf/atf-c++/pkg_config_test.sh (revision 8f0ea33f2bbf3a6aa80235f0a02fa5f2780c2b17)
1c243e490SMarcel Moolenaar# Copyright (c) 2008 The NetBSD Foundation, Inc.
2c243e490SMarcel Moolenaar# All rights reserved.
3c243e490SMarcel Moolenaar#
4c243e490SMarcel Moolenaar# Redistribution and use in source and binary forms, with or without
5c243e490SMarcel Moolenaar# modification, are permitted provided that the following conditions
6c243e490SMarcel Moolenaar# are met:
7c243e490SMarcel Moolenaar# 1. Redistributions of source code must retain the above copyright
8c243e490SMarcel Moolenaar#    notice, this list of conditions and the following disclaimer.
9c243e490SMarcel Moolenaar# 2. Redistributions in binary form must reproduce the above copyright
10c243e490SMarcel Moolenaar#    notice, this list of conditions and the following disclaimer in the
11c243e490SMarcel Moolenaar#    documentation and/or other materials provided with the distribution.
12c243e490SMarcel Moolenaar#
13c243e490SMarcel Moolenaar# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14c243e490SMarcel Moolenaar# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15c243e490SMarcel Moolenaar# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16c243e490SMarcel Moolenaar# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17c243e490SMarcel Moolenaar# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18c243e490SMarcel Moolenaar# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c243e490SMarcel Moolenaar# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20c243e490SMarcel Moolenaar# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21c243e490SMarcel Moolenaar# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22c243e490SMarcel Moolenaar# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23c243e490SMarcel Moolenaar# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24c243e490SMarcel Moolenaar# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25c243e490SMarcel Moolenaar
26c243e490SMarcel Moolenaar# The following tests assume that the atfc++.pc file is installed in a
27c243e490SMarcel Moolenaar# directory that is known by pkg-config.  Otherwise they will fail,
28c243e490SMarcel Moolenaar# and you will be required to adjust PKG_CONFIG_PATH accordingly.
29c243e490SMarcel Moolenaar#
30c243e490SMarcel Moolenaar# It would be possible to bypass this requirement by setting the path
31c243e490SMarcel Moolenaar# explicitly during the tests, but then this would not do a real check
32c243e490SMarcel Moolenaar# to ensure that the installation is working.
33c243e490SMarcel Moolenaar
34c243e490SMarcel Moolenaarrequire_pc()
35c243e490SMarcel Moolenaar{
36c243e490SMarcel Moolenaar    pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \
37c243e490SMarcel Moolenaar                                "maybe need to set PKG_CONFIG_PATH?"
38c243e490SMarcel Moolenaar}
39c243e490SMarcel Moolenaar
40c243e490SMarcel Moolenaarcheck_version()
41c243e490SMarcel Moolenaar{
42*1a61beb0SJulio Merino    ver1=$($(atf_get_srcdir)/detail/version_helper)
43*1a61beb0SJulio Merino    echo "Version reported by builtin PACKAGE_VERSION: ${ver1}"
44c243e490SMarcel Moolenaar
45c243e490SMarcel Moolenaar    atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}"
46c243e490SMarcel Moolenaar    ver2=$(cat stdout)
47c243e490SMarcel Moolenaar    echo "Version reported by pkg-config: ${ver2}"
48c243e490SMarcel Moolenaar
49c243e490SMarcel Moolenaar    atf_check_equal ${ver1} ${ver2}
50c243e490SMarcel Moolenaar}
51c243e490SMarcel Moolenaar
52c243e490SMarcel Moolenaaratf_test_case version
53c243e490SMarcel Moolenaarversion_head()
54c243e490SMarcel Moolenaar{
55c243e490SMarcel Moolenaar    atf_set "descr" "Checks that the version in atf-c++ is correct"
56*1a61beb0SJulio Merino    atf_set "require.progs" "pkg-config"
57c243e490SMarcel Moolenaar}
58c243e490SMarcel Moolenaarversion_body()
59c243e490SMarcel Moolenaar{
60c243e490SMarcel Moolenaar    require_pc "atf-c++"
61c243e490SMarcel Moolenaar
62c243e490SMarcel Moolenaar    check_version "atf-c++"
63c243e490SMarcel Moolenaar}
64c243e490SMarcel Moolenaar
65c243e490SMarcel Moolenaaratf_test_case build
66c243e490SMarcel Moolenaarbuild_head()
67c243e490SMarcel Moolenaar{
68c243e490SMarcel Moolenaar    atf_set "descr" "Checks that a test program can be built against" \
69c243e490SMarcel Moolenaar                    "the C++ library based on the pkg-config information"
70c243e490SMarcel Moolenaar    atf_set "require.progs" "pkg-config"
71c243e490SMarcel Moolenaar}
72c243e490SMarcel Moolenaarbuild_body()
73c243e490SMarcel Moolenaar{
74c243e490SMarcel Moolenaar    require_pc "atf-c++"
75c243e490SMarcel Moolenaar
76c243e490SMarcel Moolenaar    atf_check -s eq:0 -o save:stdout -e empty \
77c243e490SMarcel Moolenaar              pkg-config --variable=cxx atf-c++
78c243e490SMarcel Moolenaar    cxx=$(cat stdout)
79c243e490SMarcel Moolenaar    echo "Compiler is: ${cxx}"
80c243e490SMarcel Moolenaar    atf_require_prog ${cxx}
81c243e490SMarcel Moolenaar
82c243e490SMarcel Moolenaar    cat >tp.cpp <<EOF
83c243e490SMarcel Moolenaar#include <iostream>
84c243e490SMarcel Moolenaar
85c243e490SMarcel Moolenaar#include <atf-c++.hpp>
86c243e490SMarcel Moolenaar
87c243e490SMarcel MoolenaarATF_TEST_CASE(tc);
88c243e490SMarcel MoolenaarATF_TEST_CASE_HEAD(tc) {
89c243e490SMarcel Moolenaar    set_md_var("descr", "A test case");
90c243e490SMarcel Moolenaar}
91c243e490SMarcel MoolenaarATF_TEST_CASE_BODY(tc) {
92c243e490SMarcel Moolenaar    std::cout << "Running\n";
93c243e490SMarcel Moolenaar}
94c243e490SMarcel Moolenaar
95c243e490SMarcel MoolenaarATF_INIT_TEST_CASES(tcs) {
96c243e490SMarcel Moolenaar    ATF_ADD_TEST_CASE(tcs, tc);
97c243e490SMarcel Moolenaar}
98c243e490SMarcel MoolenaarEOF
99c243e490SMarcel Moolenaar
100c243e490SMarcel Moolenaar    atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c++
101c243e490SMarcel Moolenaar    cxxflags=$(cat stdout)
102c243e490SMarcel Moolenaar    echo "CXXFLAGS are: ${cxxflags}"
103c243e490SMarcel Moolenaar
104c243e490SMarcel Moolenaar    atf_check -s eq:0 -o save:stdout -e empty \
105c243e490SMarcel Moolenaar        pkg-config --libs-only-L --libs-only-other atf-c++
106c243e490SMarcel Moolenaar    ldflags=$(cat stdout)
107c243e490SMarcel Moolenaar    atf_check -s eq:0 -o save:stdout -e empty \
108c243e490SMarcel Moolenaar              pkg-config --libs-only-l atf-c++
109c243e490SMarcel Moolenaar    libs=$(cat stdout)
110c243e490SMarcel Moolenaar    echo "LDFLAGS are: ${ldflags}"
111c243e490SMarcel Moolenaar    echo "LIBS are: ${libs}"
112c243e490SMarcel Moolenaar
113c243e490SMarcel Moolenaar    atf_check -s eq:0 -o empty -e empty ${cxx} ${cxxflags} -o tp.o -c tp.cpp
114c243e490SMarcel Moolenaar    atf_check -s eq:0 -o empty -e empty ${cxx} ${ldflags} -o tp tp.o ${libs}
115c243e490SMarcel Moolenaar
116c243e490SMarcel Moolenaar    libpath=
117c243e490SMarcel Moolenaar    for f in ${ldflags}; do
118c243e490SMarcel Moolenaar        case ${f} in
119c243e490SMarcel Moolenaar            -L*)
120c243e490SMarcel Moolenaar                dir=$(echo ${f} | sed -e 's,^-L,,')
121c243e490SMarcel Moolenaar                if [ -z "${libpath}" ]; then
122c243e490SMarcel Moolenaar                    libpath="${dir}"
123c243e490SMarcel Moolenaar                else
124c243e490SMarcel Moolenaar                    libpath="${libpath}:${dir}"
125c243e490SMarcel Moolenaar                fi
126c243e490SMarcel Moolenaar                ;;
127c243e490SMarcel Moolenaar            *)
128c243e490SMarcel Moolenaar                ;;
129c243e490SMarcel Moolenaar        esac
130c243e490SMarcel Moolenaar    done
131c243e490SMarcel Moolenaar
132c243e490SMarcel Moolenaar    atf_check -s eq:0 -o empty -e empty test -x tp
133c243e490SMarcel Moolenaar    atf_check -s eq:0 -o match:'Running' -e empty -x \
134c243e490SMarcel Moolenaar              "LD_LIBRARY_PATH=${libpath} ./tp tc"
135c243e490SMarcel Moolenaar}
136c243e490SMarcel Moolenaar
137c243e490SMarcel Moolenaaratf_init_test_cases()
138c243e490SMarcel Moolenaar{
139c243e490SMarcel Moolenaar    atf_add_test_case version
140c243e490SMarcel Moolenaar    atf_add_test_case build
141c243e490SMarcel Moolenaar}
142c243e490SMarcel Moolenaar
143c243e490SMarcel Moolenaar# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
144