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