1 | # @configure_input@ |
---|
2 | # $Id: common_defs.sh.in 3018 2013-04-04 04:46:38Z peter $ |
---|
3 | |
---|
4 | # Copyright (C) 2009, 2010, 2011, 2012, 2013 Peter Johansson |
---|
5 | # |
---|
6 | # This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
7 | # |
---|
8 | # The yat library is free software; you can redistribute it |
---|
9 | # and/or modify it under the terms of the GNU General Public License as |
---|
10 | # published by the Free Software Foundation; either version 3 of the |
---|
11 | # License, or (at your option) any later version. |
---|
12 | # |
---|
13 | # The yat library is distributed in the hope that it will be useful, |
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | # General Public License for more details. |
---|
17 | # |
---|
18 | # You should have received a copy of the GNU General Public License |
---|
19 | # along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | |
---|
21 | |
---|
22 | # bootstrap a test project |
---|
23 | # |
---|
24 | bootstrap () |
---|
25 | { |
---|
26 | rm -rf m4 |
---|
27 | @MKDIR_P@ m4 |
---|
28 | cp @abs_top_srcdir@/m4/*.m4 m4/. |
---|
29 | rm -f m4/lt*.m4 m4/libtool.m4 |
---|
30 | autoreconf -siv && true |
---|
31 | res=$? |
---|
32 | case $res in |
---|
33 | 0) |
---|
34 | :;; |
---|
35 | 63) |
---|
36 | exit_skip;; |
---|
37 | *) |
---|
38 | exit $res;; |
---|
39 | esac |
---|
40 | } |
---|
41 | |
---|
42 | # Usage: run PROG EXPECTED_EXITCODE [OPTION]... |
---|
43 | run () |
---|
44 | { |
---|
45 | test $# -ge 2 || exit_fatal |
---|
46 | foo_prog=$1 |
---|
47 | shift |
---|
48 | expected_exitcode=$1 |
---|
49 | shift |
---|
50 | exitcode=0 |
---|
51 | $foo_prog ${1+"$@"} > stdout 2>stderr || exitcode=$? |
---|
52 | cat stderr >&2 |
---|
53 | cat stdout |
---|
54 | test $exitcode = $expected_exitcode || Exit 1 |
---|
55 | } |
---|
56 | |
---|
57 | Exit () { set +x; exit $1; } |
---|
58 | warn_ () { echo $@ >&2; } |
---|
59 | exit_fail () { warn_ "$me: failed test: $@"; Exit 1; } |
---|
60 | exit_fatal () { warn_ "$me: hard error: $@"; Exit 99; } |
---|
61 | exit_skip () { warn_ "$me: skipped test: $@"; Exit 77; } |
---|
62 | exit_success () { echo "$me: successsful test: $@"; Exit 0; } |
---|
63 | |
---|
64 | me=$0 |
---|
65 | |
---|
66 | echo "=== Running $me ===" |
---|
67 | |
---|
68 | # if required tool is not available, exit_skip |
---|
69 | if test -n "$required"; then |
---|
70 | for tool in $required; do |
---|
71 | case $tool in |
---|
72 | automake) |
---|
73 | echo "$me: running $tool --version" |
---|
74 | ($tool --version) || exit_skip; |
---|
75 | # skip test if automake older than v1.10 |
---|
76 | version_am=`$tool --version | head -n 1 | cut -f 2 -d ')'` |
---|
77 | ver_major=`echo ${version_am} | cut -f 1 -d '.'` |
---|
78 | test ${ver_major} -ge 1 || exit_skip |
---|
79 | ver_minor=`echo ${version_am} | cut -f 2 -d '.'` |
---|
80 | test ${ver_major} -gt 1 || test ${ver_minor} -ge 10 || exit_skip |
---|
81 | ;; |
---|
82 | doxygen) |
---|
83 | test @have_doxygen@ = "yes" || exit_skip no doxygen |
---|
84 | ;; |
---|
85 | libbam) |
---|
86 | test @have_libbam@ = "yes" || exit_skip no libbam |
---|
87 | ;; |
---|
88 | libtool) |
---|
89 | # GNU libtool comes as glibtool on Mac OS |
---|
90 | (echo "$me: running libtool --version" && libtool --version) || \ |
---|
91 | (echo "$me: running glibtool --version" && glibtool --version) || \ |
---|
92 | exit_skip |
---|
93 | ;; |
---|
94 | static) |
---|
95 | if (test "x@enable_static@" = "xno"); then |
---|
96 | echo static libyat disabled; |
---|
97 | exit_skip; |
---|
98 | fi |
---|
99 | ;; |
---|
100 | *) |
---|
101 | echo "$me: running $tool --version" |
---|
102 | ($tool --version) || exit_skip |
---|
103 | esac |
---|
104 | done |
---|
105 | fi |
---|
106 | |
---|
107 | # some defs we need in tests |
---|
108 | test_dir=`echo $me.dir | sed -e 's,.*[\\/],,'` |
---|
109 | test_dir="test/testSubDir/$test_dir" |
---|
110 | abs_top_builddir=@abs_top_builddir@ |
---|
111 | abs_top_srcdir=@abs_top_srcdir@ |
---|
112 | have_doxygen="@have_doxygen@" |
---|
113 | |
---|
114 | GSL_CONFIG=@GSL_CONFIG@ |
---|
115 | |
---|
116 | # user is always right |
---|
117 | test -z "$DOXYGEN" && DOXYGEN="@DOXYGEN@" |
---|
118 | |
---|
119 | rm -rf $test_dir/* |
---|
120 | @MKDIR_P@ --verbose $test_dir |
---|
121 | |
---|
122 | # Taken from Automake 1.11 tests/defs.sh.in |
---|
123 | |
---|
124 | # Unset some MAKE... variables that may cause 'make' to act like a |
---|
125 | # recursively invoked sub-make. Any 'make' invocation in a test is |
---|
126 | # conceptually an independent invocation, not part of the main |
---|
127 | # 'yat' build. |
---|
128 | unset MFLAGS |
---|
129 | unset MAKEFLAGS |
---|
130 | unset MAKELEVEL |
---|
131 | unset DESTDIR |
---|
132 | unset V |
---|
133 | unset TESTS |
---|
134 | unset TEST_LOGS |
---|
135 | unset RECHECK_LOGS |
---|
136 | unset VERBOSE |
---|
137 | |
---|
138 | cd $test_dir |
---|
139 | |
---|
140 | if (echo "$required" | grep autoconf > /dev/null); then |
---|
141 | echo "creating configure.ac" |
---|
142 | cat > configure.ac <<EOF |
---|
143 | AC_INIT([hello],[1.0]) |
---|
144 | AC_CONFIG_SRCDIR([hello.cc]) |
---|
145 | AC_CONFIG_MACRO_DIR([m4]) |
---|
146 | EOF |
---|
147 | if (echo "$required" | grep automake > /dev/null); then |
---|
148 | echo "AM_INIT_AUTOMAKE([foreign])" >> configure.ac |
---|
149 | fi |
---|
150 | if (echo "$required" | grep libtool > /dev/null); then |
---|
151 | cat >> configure.ac << EOF |
---|
152 | AC_LANG([C++]) |
---|
153 | AC_PROG_CXXCPP |
---|
154 | AC_PROG_CXX |
---|
155 | AC_PROG_LIBTOOL |
---|
156 | EOF |
---|
157 | fi |
---|
158 | |
---|
159 | |
---|
160 | echo "creating Makefile.am" |
---|
161 | cat > Makefile.am <<EOF |
---|
162 | ACLOCAL_AMFLAGS = -I m4 |
---|
163 | AM_CPPFLAGS = \$(YAT_CPPFLAGS) |
---|
164 | AM_CXXFLAGS = \$(YAT_CXXFLAGS) |
---|
165 | AM_LDFLAGS = \$(YAT_LDFLAGS) |
---|
166 | LDADD = \$(YAT_LDADD) |
---|
167 | bin_PROGRAMS = hello |
---|
168 | TESTS = hello |
---|
169 | hello_SOURCES = hello.cc |
---|
170 | EOF |
---|
171 | |
---|
172 | echo "creating hello.cc" |
---|
173 | cat > hello.cc <<EOF |
---|
174 | #include <yat/utility/Vector.h> |
---|
175 | #include <yat/utility/version.h> |
---|
176 | #include <algorithm> |
---|
177 | #include <iostream> |
---|
178 | #include <string> |
---|
179 | int main(void) |
---|
180 | { |
---|
181 | using namespace theplu::yat; |
---|
182 | if (utility::version()!="@VERSION@") { |
---|
183 | std::cerr << "Incorrect version of linked libyat\n"; |
---|
184 | return 1; |
---|
185 | } |
---|
186 | // testing something with gsl |
---|
187 | utility::Vector v(10); |
---|
188 | v.resize(120); |
---|
189 | // testing something with boost |
---|
190 | std::copy(v.begin(), v.begin()+10, v.begin()+10); |
---|
191 | return 0; |
---|
192 | } |
---|
193 | EOF |
---|
194 | fi #end of creation of autotool files |
---|
195 | |
---|
196 | # turn on shell traces |
---|
197 | set -x |
---|
198 | # remove old core dumps |
---|
199 | rm -f core* |
---|