1 | # @configure_input@ |
---|
2 | # $Id: common_defs.sh.in 2520 2011-07-11 15:55:27Z peter $ |
---|
3 | |
---|
4 | # Copyright (C) 2009, 2010, 2011 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 | @MKDIR_P@ m4 |
---|
27 | autoreconf -siv && true |
---|
28 | res=$? |
---|
29 | case $res in |
---|
30 | 0) |
---|
31 | :;; |
---|
32 | 63) |
---|
33 | exit 77;; |
---|
34 | *) |
---|
35 | exit $res;; |
---|
36 | esac |
---|
37 | } |
---|
38 | |
---|
39 | # Usage: run PROG EXPECTED_EXITCODE [OPTION]... |
---|
40 | run () |
---|
41 | { |
---|
42 | test $# -ge 2 || exit_fatal |
---|
43 | foo_prog=$1 |
---|
44 | shift |
---|
45 | expected_exitcode=$1 |
---|
46 | shift |
---|
47 | exitcode=0 |
---|
48 | $foo_prog ${1+"$@"} > stdout 2>stderr || exitcode=$? |
---|
49 | cat stderr >&2 |
---|
50 | cat stdout |
---|
51 | test $exitcode = $expected_exitcode || Exit 1 |
---|
52 | } |
---|
53 | |
---|
54 | Exit () { set +x; exit $1; } |
---|
55 | warn_ () { echo $@ >&2; } |
---|
56 | exit_fail () { warn_ "$me: failed test: $@"; Exit 1; } |
---|
57 | exit_fatal () { warn_ "$me: hard error: $@"; Exit 99; } |
---|
58 | exit_skip () { warn_ "$me: skipped test: $@"; Exit 77; } |
---|
59 | exit_success () { echo "$me: successsful test: $@"; Exit 0; } |
---|
60 | |
---|
61 | me=$0 |
---|
62 | |
---|
63 | echo "=== Running $me ===" |
---|
64 | |
---|
65 | # if required tool is not available, exit 77 to skip test |
---|
66 | if test -n "$required"; then |
---|
67 | for tool in $required; do |
---|
68 | case $tool in |
---|
69 | automake) |
---|
70 | echo "$me: running $tool --version" |
---|
71 | ($tool --version) || exit 77; |
---|
72 | # skip test if automake older than v1.10 |
---|
73 | version_am=`$tool --version | head -n 1 | cut -f 2 -d ')'` |
---|
74 | ver_major=`echo ${version_am} | cut -f 1 -d '.'` |
---|
75 | test ${ver_major} -ge 1 || exit 77 |
---|
76 | ver_minor=`echo ${version_am} | cut -f 2 -d '.'` |
---|
77 | test ${ver_major} -gt 1 || test ${ver_minor} -ge 10 || exit 77 |
---|
78 | ;; |
---|
79 | doxygen) |
---|
80 | test @have_doxygen@ = "yes" || exit_skip no doxygen |
---|
81 | ;; |
---|
82 | libtool) |
---|
83 | # GNU libtool comes as glibtool on Mac OS |
---|
84 | (echo "$me: running libtool --version" && libtool --version) || \ |
---|
85 | (echo "$me: running glibtool --version" && glibtool --version) || exit 77 |
---|
86 | ;; |
---|
87 | static) |
---|
88 | if (test "x@enable_static@" = "xno"); then |
---|
89 | echo static libyat disabled; |
---|
90 | exit 77; |
---|
91 | fi |
---|
92 | ;; |
---|
93 | *) |
---|
94 | echo "$me: running $tool --version" |
---|
95 | ($tool --version) || exit 77 |
---|
96 | esac |
---|
97 | done |
---|
98 | fi |
---|
99 | |
---|
100 | # some defs we need in tests |
---|
101 | test_dir=`echo $me.dir | sed -e 's,.*[\\/],,'` |
---|
102 | test_dir="testSubDir/$test_dir" |
---|
103 | abs_top_builddir=@abs_top_builddir@ |
---|
104 | abs_top_srcdir=@abs_top_srcdir@ |
---|
105 | move_if_change=@abs_top_srcdir@/build_support/move-if-change |
---|
106 | have_doxygen="@have_doxygen@" |
---|
107 | |
---|
108 | # user is always right |
---|
109 | test -z "$DOXYGEN" && DOXYGEN="@DOXYGEN@" |
---|
110 | |
---|
111 | rm -rf $test_dir |
---|
112 | @MKDIR_P@ --verbose $test_dir |
---|
113 | |
---|
114 | cd $test_dir |
---|
115 | |
---|
116 | if (echo "$required" | grep autoconf > /dev/null); then |
---|
117 | echo "creating configure.ac" |
---|
118 | cat > configure.ac <<EOF |
---|
119 | AC_INIT([hello],[1.0]) |
---|
120 | AC_CONFIG_SRCDIR([hello.cc]) |
---|
121 | AM_INIT_AUTOMAKE([foreign]) |
---|
122 | AC_CONFIG_MACRO_DIR([m4]) |
---|
123 | AC_LANG(C++) |
---|
124 | AC_PROG_CXXCPP |
---|
125 | AC_PROG_CXX |
---|
126 | EOF |
---|
127 | if (echo "$required" | grep libtool > /dev/null); then |
---|
128 | echo AC_PROG_LIBTOOL >> configure.ac |
---|
129 | fi |
---|
130 | |
---|
131 | |
---|
132 | echo "creating Makefile.am" |
---|
133 | cat > Makefile.am <<EOF |
---|
134 | ACLOCAL_AMFLAGS = -I m4 -I ${abs_top_srcdir}/m4 --install |
---|
135 | AM_CPPFLAGS = \$(YAT_CPPFLAGS) |
---|
136 | AM_CXXFLAGS = \$(YAT_CXXFLAGS) |
---|
137 | LDADD = \$(YAT_LDADD) |
---|
138 | bin_PROGRAMS = hello |
---|
139 | TESTS = hello |
---|
140 | hello_SOURCES = hello.cc |
---|
141 | EOF |
---|
142 | |
---|
143 | echo "creating hello.cc" |
---|
144 | cat > hello.cc <<EOF |
---|
145 | #include <yat/utility/Vector.h> |
---|
146 | #include <yat/utility/version.h> |
---|
147 | #include <algorithm> |
---|
148 | #include <iostream> |
---|
149 | #include <string> |
---|
150 | int main(void) |
---|
151 | { |
---|
152 | using namespace theplu::yat; |
---|
153 | if (utility::version()!="@VERSION@") { |
---|
154 | std::cerr << "Incorrect version of linked libyat\n"; |
---|
155 | return 1; |
---|
156 | } |
---|
157 | // testing something with gsl |
---|
158 | utility::Vector v(10); |
---|
159 | v.resize(120); |
---|
160 | // testing something with boost |
---|
161 | std::copy(v.begin(), v.begin()+10, v.begin()+10); |
---|
162 | return 0; |
---|
163 | } |
---|
164 | EOF |
---|
165 | fi #end of creation of autotool files |
---|
166 | |
---|
167 | # turn on shell traces |
---|
168 | set -x |
---|