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

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

prefer function exit_fail over exit 77

  • 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 2528 2011-07-26 02:34:35Z 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_skip;;
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_skip
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_skip;
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_skip
76      ver_minor=`echo ${version_am} | cut -f 2 -d '.'`
77      test ${ver_major} -gt 1 || test ${ver_minor} -ge 10 || exit_skip
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) || \
86       exit_skip
87      ;;
88      static)
89      if (test "x@enable_static@" = "xno"); then
90        echo static libyat disabled;
91        exit_skip;
92      fi
93      ;;
94      *)
95      echo "$me: running $tool --version"
96      ($tool --version) || exit_skip
97    esac
98  done
99fi
100 
101# some defs we need in tests
102test_dir=`echo $me.dir | sed -e 's,.*[\\/],,'`
103test_dir="testSubDir/$test_dir"
104abs_top_builddir=@abs_top_builddir@
105abs_top_srcdir=@abs_top_srcdir@
106move_if_change=@abs_top_srcdir@/build_support/move-if-change
107have_doxygen="@have_doxygen@"
108
109# user is always right
110test -z "$DOXYGEN" && DOXYGEN="@DOXYGEN@"
111
112rm -rf $test_dir
113@MKDIR_P@ --verbose $test_dir
114
115cd $test_dir
116
117if (echo "$required" | grep autoconf > /dev/null); then
118echo "creating configure.ac"
119cat > configure.ac <<EOF
120AC_INIT([hello],[1.0])
121AC_CONFIG_SRCDIR([hello.cc])
122AC_CONFIG_MACRO_DIR([m4])
123EOF
124if (echo "$required" | grep automake > /dev/null); then
125echo "AM_INIT_AUTOMAKE([foreign])" >> configure.ac
126fi
127if (echo "$required" | grep libtool > /dev/null); then
128echo AC_PROG_LIBTOOL >> configure.ac
129fi
130
131
132echo "creating Makefile.am"
133cat > Makefile.am <<EOF
134ACLOCAL_AMFLAGS = -I m4 -I ${abs_top_srcdir}/m4 --install
135AM_CPPFLAGS = \$(YAT_CPPFLAGS)
136AM_CXXFLAGS = \$(YAT_CXXFLAGS)
137LDADD = \$(YAT_LDADD)
138bin_PROGRAMS = hello
139TESTS = hello
140hello_SOURCES = hello.cc
141EOF
142
143echo "creating hello.cc"
144cat > hello.cc <<EOF
145#include <yat/utility/Vector.h>
146#include <yat/utility/version.h>
147#include <algorithm>
148#include <iostream>
149#include <string>
150int 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}
164EOF
165fi #end of creation of autotool files
166
167# turn on shell traces
168set -x
Note: See TracBrowser for help on using the repository browser.