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

Last change on this file since 2527 was 2527, checked in by Peter, 10 years ago

remove compiler test from configure.ac genewrated in common_defs.sh (to speed up tests not using compiler)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1# @configure_input@
2# $Id: common_defs.sh.in 2527 2011-07-26 02:15:29Z 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#
24bootstrap ()
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]...
40run ()
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
54Exit () { set +x; exit $1; }
55warn_ () { echo $@ >&2; }
56exit_fail () { warn_ "$me: failed test: $@"; Exit 1; }
57exit_fatal () { warn_ "$me: hard error: $@"; Exit 99; }
58exit_skip () { warn_ "$me: skipped test: $@"; Exit 77; }
59exit_success () { echo "$me: successsful test: $@"; Exit 0; }
60
61me=$0
62
63echo "=== Running $me ==="
64
65# if required tool is not available, exit 77 to skip test
66if 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
98fi
99 
100# some defs we need in tests
101test_dir=`echo $me.dir | sed -e 's,.*[\\/],,'`
102test_dir="testSubDir/$test_dir"
103abs_top_builddir=@abs_top_builddir@
104abs_top_srcdir=@abs_top_srcdir@
105move_if_change=@abs_top_srcdir@/build_support/move-if-change
106have_doxygen="@have_doxygen@"
107
108# user is always right
109test -z "$DOXYGEN" && DOXYGEN="@DOXYGEN@"
110
111rm -rf $test_dir
112@MKDIR_P@ --verbose $test_dir
113
114cd $test_dir
115
116if (echo "$required" | grep autoconf > /dev/null); then
117echo "creating configure.ac"
118cat > configure.ac <<EOF
119AC_INIT([hello],[1.0])
120AC_CONFIG_SRCDIR([hello.cc])
121AC_CONFIG_MACRO_DIR([m4])
122EOF
123if (echo "$required" | grep automake > /dev/null); then
124echo "AM_INIT_AUTOMAKE([foreign])" >> configure.ac
125fi
126if (echo "$required" | grep libtool > /dev/null); then
127echo AC_PROG_LIBTOOL >> configure.ac
128fi
129
130
131echo "creating Makefile.am"
132cat > Makefile.am <<EOF
133ACLOCAL_AMFLAGS = -I m4 -I ${abs_top_srcdir}/m4 --install
134AM_CPPFLAGS = \$(YAT_CPPFLAGS)
135AM_CXXFLAGS = \$(YAT_CXXFLAGS)
136LDADD = \$(YAT_LDADD)
137bin_PROGRAMS = hello
138TESTS = hello
139hello_SOURCES = hello.cc
140EOF
141
142echo "creating hello.cc"
143cat > hello.cc <<EOF
144#include <yat/utility/Vector.h>
145#include <yat/utility/version.h>
146#include <algorithm>
147#include <iostream>
148#include <string>
149int main(void)
150{
151  using namespace theplu::yat;
152  if (utility::version()!="@VERSION@") {
153    std::cerr << "Incorrect version of linked libyat\n";
154    return 1;
155  }
156  // testing something with gsl
157  utility::Vector v(10);
158  v.resize(120); 
159  // testing something with boost
160  std::copy(v.begin(), v.begin()+10, v.begin()+10);
161  return 0;
162}
163EOF
164fi #end of creation of autotool files
165
166# turn on shell traces
167set -x
Note: See TracBrowser for help on using the repository browser.