Merge branch 'rmch'
[platform/upstream/automake.git] / t / self-check-me.tap
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 # Make sure that $me gets automatically defined by './defs', and that it
19 # can be overridden by the test script.
20
21 am_create_testdir=no
22 . ./defs || Exit 1
23
24 plan_ 14
25
26 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
27
28 # This test becomes cumbersome if we keep the 'errexit' shell flag set.
29 # And removing it is no big deal, as this test is a TAP-based one, so
30 # that false positives remain very unlikely.
31 set +e
32
33 do_check ()
34 {
35   $SHELL -c '. ./defs && echo me=$me' "$1" | grep "^me=$2$"
36   command_ok_ "me=$1" test $? -eq 0
37 }
38
39 for e in sh tap; do
40   do_check foo-bar-.$e 'foo-bar-'
41   do_check _foo__bar.$e '_foo__bar'
42   do_check 012.$e '012'
43   do_check a.b.c.$e 'a\.b\.c'
44 done
45
46 do_check foo.bar 'foo\.bar'
47 do_check abc. 'abc\.'
48
49 # If we override $me, ./defs should not modify it.
50
51 s=`$SHELL -c 'me=foo.sh && . ./defs && echo me=$me' bad.sh`
52 command_ok_ "override of \$me before ./defs causes no error" \
53             test $? -eq 0
54
55 r='ok'
56 printf '%s\n' "$s" | grep '^me=foo\.sh$' || r='not ok'
57 printf '%s\n' "$s" | grep 'me=bad'       && r='not ok'
58 result_ "$r" "override of \$me before ./defs is honored"
59 unset r
60
61 # Overriding $me after sourcing ./defs-static should work.
62 s=`$SHELL -c '. ./defs-static && me=zardoz &&
63               . ./defs && echo me=$me' bad.sh`
64 command_ok_ "override of \$me after ./defs-static causes no error" \
65             test $? -eq 0
66
67 r='ok'
68 printf '%s\n' "$s" | grep '^me=zardoz$' || r='not ok'
69 printf '%s\n' "$s" | grep 'me=bad'      && r='not ok'
70 result_ "$r" "override of \$me after ./defs-static is honored"
71 unset r
72
73 :