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

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

use new functions (r2519) in tests and simplify code

  • 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 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#
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])
121AM_INIT_AUTOMAKE([foreign])
122AC_CONFIG_MACRO_DIR([m4])
123AC_LANG(C++)
124AC_PROG_CXXCPP
125AC_PROG_CXX
126EOF
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.