source: trunk/test/common_defs.sh.in @ 2225

Last change on this file since 2225 was 2225, checked in by Peter, 12 years ago

fixes #613. Restructure tests to have a configure.ac with no included acinclude but include needed code in configure.ac instead. This makes it easier for autotools to give a useful diagnosis when autoconf is too old. The cache in the test were also removed (was never a good idea) so now tests are run from scratch every time, in fact, old testdir is removed before creating input files (such as configure.ac). This makes the tests a bit more time consuming, but they are also more accurate (reported failures have often been problem with the cache).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1# @configure_input@
2# $Id: common_defs.sh.in 2225 2010-03-22 22:29:41Z peter $
3
4# Copyright (C) 2009 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# function copied from GNU Automake 1.10.2
23#
24# is_newest FILE FILES
25# --------------------
26# Return false if any file in FILES is newer than FILE.
27# Resolve ties in favor of FILE.
28is_newest ()
29{
30  test x`find "$@" -newer "$1"` = x
31}
32
33#
34#
35bootstrap ()
36{
37    autoreconf -siv && true
38    res=$?
39    case $res in
40  0)
41      :;;
42  63)
43      exit 77;;
44  *)
45      exit $res;;
46    esac
47}
48
49
50me=$0
51
52while test $# -gt 0; do
53    case "$1" in
54    -v)
55    VERBOSE=1
56    ;;
57    esac
58    shift
59done
60
61if test -n "$YAT_TEST_VERBOSE"; then
62  VERBOSE=YAT_TEST_VERBOSE;
63  echo "WARNING: environment variable \`YAT_TEST_VERBOSE' is deprecated;";
64  echo "  use \`VERBOSE' instead.";
65fi
66
67if test -z "$VERBOSE"; then
68  exec > /dev/null 2>&1
69fi
70
71echo "=== Running $me ==="
72
73# if required tool is not available, exit 77 to skip test
74if test -n "$required"; then
75  for tool in $required; do
76    case $tool in
77      libtool)
78      # GNU libtool comes as glibtool on Mac OS
79      (echo "$me: running libtool --version" && libtool --version) || \
80      (echo "$me: running glibtool --version" && glibtool --version) || exit 77
81      ;;
82      *.m4)
83      : # do nothing see below
84      ;;
85      *)
86      echo "$me: running $tool --version"
87      ($tool --version) || exit 77
88    esac
89  done
90fi
91 
92# some defs we need in tests
93test_dir=`echo $me.dir | sed -e 's,.*[\\/],,'`
94test_dir="testSubDir/$test_dir"
95abs_top_builddir=@abs_top_builddir@
96abs_top_srcdir=@abs_top_srcdir@
97move_if_change=@abs_top_srcdir@/build_support/move-if-change
98
99rm -rf $test_dir
100@MKDIR_P@ --verbose $test_dir
101
102cd $test_dir
103
104if (echo "$required" | grep autoconf > /dev/null); then
105echo "creating configure.ac"
106cat > configure.ac <<EOF
107AC_INIT([hello],[1.0])
108AC_CONFIG_SRCDIR([hello.cc])
109AM_INIT_AUTOMAKE([foreign])
110AC_CONFIG_MACRO_DIR([m4])
111AC_LANG(C++)
112AC_PROG_CXXCPP
113AC_PROG_CXX
114EOF
115if (echo "$required" | grep libtool > /dev/null); then
116echo AC_PROG_LIBTOOL >> configure.ac
117fi
118
119
120echo "creating Makefile.am"
121cat > Makefile.am <<EOF
122ACLOCAL_AMFLAGS = -I m4
123# dependency to rerun configure
124CONFIG_STATUS_DEPENDENCIES = $abs_top_builddir/build_support/yat-config
125AM_CPPFLAGS = \$(YAT_CPPFLAGS)
126AM_CXXFLAGS = \$(YAT_CXXFLAGS)
127LDADD = \$(YAT_LDADD)
128bin_PROGRAMS = hello
129TESTS = hello
130hello_SOURCES = hello.cc
131EOF
132
133echo "creating hello.cc"
134cat > hello.cc <<EOF
135#include <yat/utility/Vector.h>
136#include <yat/utility/version.h>
137#include <algorithm>
138#include <iostream>
139#include <string>
140int main(void)
141{
142  using namespace theplu::yat;
143  if (utility::version()!="@VERSION@") {
144    std::cerr << "Incorrect version of linked libyat\n";
145    return 1;
146  }
147  // testing something with gsl
148  utility::Vector v(10);
149  v.resize(120); 
150  // testing something with boost
151  std::copy(v.begin(), v.begin()+10, v.begin()+10);
152  return 0;
153}
154EOF
155fi #end of creation of autotool files
156
157if test -n "$required"; then
158  for tool in $required; do
159    case $tool in
160      *.m4)
161      @MKDIR_P@ --verbose m4
162      echo "copying $tool"
163      cp @abs_top_srcdir@/m4/$tool m4/$tool
164      ;;
165      *)
166      :
167    esac
168  done
169fi
170 
171# turn on shell traces when in verbose mode
172if test -n "$VERBOSE"; then
173    set -x
174fi
Note: See TracBrowser for help on using the repository browser.