Merge branch 'testsuite-saner-shell' into maint
[platform/upstream/automake.git] / t / self-check-sanity.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Sanity check for the automake testsuite.
18 # Test the sanity checks performed by the 'defs' script.  Also check
19 # that we can use 'defs' elsewhere, when we duplicate some of the
20 # infrastructure from the automake/tests subdirectory.
21
22 am_create_testdir=empty
23 . ./defs || Exit 1
24
25 # Avoid to confuse traces from child processed with our own traces.
26 show_stderr ()
27 {
28   sed 's/^/ | /' stderr >&2
29 }
30
31 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
32
33 source_defs=". '$am_top_builddir/defs'"
34
35 if $AM_TEST_RUNNER_SHELL -c "$source_defs" dummy.sh 2>stderr; then
36   show_stderr
37   Exit 1
38 else
39   show_stderr
40   grep 'defs-static: not found in current directory' stderr
41 fi
42
43 sed 's|^am_top_srcdir=.*|am_top_srcdir=foo|' \
44   "$am_top_builddir"/defs-static > defs-static
45 if $AM_TEST_RUNNER_SHELL -c "$source_defs" t/dummy.sh 2>stderr; then
46   show_stderr
47   Exit 1
48 else
49   show_stderr
50   grep 'foo/defs-static\.in not found.*check \$am_top_srcdir' stderr
51 fi
52
53 sed 's|^am_top_builddir=.*|am_top_builddir=foo|' \
54   "$am_top_builddir"/defs-static > defs-static
55 if $AM_TEST_RUNNER_SHELL -c "$source_defs" t/dummy.sh 2>stderr; then
56   show_stderr
57   Exit 1
58 else
59   show_stderr
60   grep 'foo/defs-static not found.*check \$am_top_builddir' stderr
61 fi
62
63 # We still need a little hack to make ./defs work outside automake's
64 # tree 'tests' subdirectory.  Not a big deal.
65 sed "s|^am_top_builddir=.*|am_top_builddir='`pwd`'|" \
66   "$am_top_builddir"/defs-static > defs-static
67 # Redefining *srcdir and *builddir variables in the environment shouldn't
68 # cause problems
69 env \
70   builddir=bad-dir srcdir=bad-dir \
71   top_builddir=bad-dir top_srcdir=bad-dir \
72   abs_builddir=bad-dir abs_srcdir=bad-dir \
73   abs_top_builddir=bad-dir abs_top_srcdir=bad-dir \
74   $AM_TEST_RUNNER_SHELL -c "$source_defs && echo '!OK!' > ../foo" t/dummy.sh
75 $FGREP '!OK!' t/foo
76
77 :