tests: don't clutter the top-level dir with temporary test directories
[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'.
19
20 am_create_testdir=no
21 . ./defs || exit 1
22
23 plan_ 12
24
25 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
26
27 # This test becomes cumbersome if we keep the 'errexit' shell flag set.
28 # And removing it is no big deal, as this test is a TAP-based one, so
29 # that false positives remain very unlikely.
30 set +e
31
32 do_check ()
33 {
34   $AM_TEST_RUNNER_SHELL -c '
35     am_create_testdir=no # Do not pollute the top-level directory.
36     . ./defs
37     echo me=$me
38   ' "$1" | grep "^me=$2$"
39   command_ok_ "me=$1" test $? -eq 0
40 }
41
42 for e in sh tap; do
43   do_check foo-bar-.$e 'foo-bar-'
44   do_check _foo__bar.$e '_foo__bar'
45   do_check 012.$e '012'
46   do_check a.b.c.$e 'a\.b\.c'
47 done
48
49 do_check foo.bar 'foo\.bar'
50 do_check abc. 'abc\.'
51
52 # A definition of $me in the environment should be ignored.
53
54 s=$(me=bad $AM_TEST_RUNNER_SHELL -c '
55   # Do not pollute the top-level directory.
56   am_create_testdir=no
57   . ./defs
58   echo me=$me
59 ' foo.sh)
60 command_ok_ "override of \$me before ./defs causes no error" \
61             test $? -eq 0
62
63 r='ok'
64 printf '%s\n' "$s" | grep '^me=foo$' || r='not ok'
65 printf '%s\n' "$s" | grep 'me=bad'   && r='not ok'
66 result_ "$r" "\$me from the environment is ignored"
67 unset r
68
69 :