header-vars: recognize more make flags ('-k' in particular)
[platform/upstream/automake.git] / t / make-dryrun.tap
1 #! /bin/sh
2 # Copyright (C) 2012-2013 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 # Check that $(am__make_dryrun) works as expected.
18
19 . test-init.sh
20
21 plan_ 20
22
23 if echo "all: ; +@printf %sbb%s aa cc" | $MAKE -n -f - | grep aabbcc; then
24   make_plus_silence () { return 0; }
25 else
26   make_plus_silence () { return 1; }
27 fi
28
29 mkdir none # Also used later.
30 if echo nil: | $MAKE -I none -f -; then
31   make_supports_option_I () { return 0; }
32 else
33   make_supports_option_I () { return 1; }
34 fi
35
36 echo AC_OUTPUT >> configure.ac
37
38 cat > Makefile.am <<'END'
39 all:
40         : Dummy, nothing to do.
41 run:
42         @echo ":: $$MAKEFLAGS ::"; : For debugging.
43         $(am__make_dryrun) && exit 1; echo ok > from-run
44 dry:
45         +@echo ":: $$MAKEFLAGS ::"; : For debugging.
46         +$(am__make_dryrun) || exit 1; echo ok > from-dry
47 END
48
49 check_make ()
50 {
51   r=ok msg= mode= condition=: directive= reason= skip_reason=
52   case $1 in
53     --dry) mode=dry;;
54     --run) mode=run;;
55     *) fatal_ "check_run: invalid usage";;
56   esac
57   shift
58   while test $# -gt 0; do
59     case $1 in
60       -C) condition=$2 skip_reason=$3; shift; shift;;
61       -M) msg=$2; shift;;
62       --) shift; break;;
63        *) break;;
64     esac
65     shift
66   done
67   msg=${mode}${msg:+" [$msg]"}
68   if $condition; then
69     $MAKE "$mode" ${1+"$@"} || r='not ok'
70     test -f from-$mode      || r='not ok'
71     test ! -e bad           || r='not ok'
72     rm -f bad from-*        || fatal_ "cleaning up"
73   else
74     directive=SKIP reason=$skip_reason
75   fi
76   result_ "$r" -D "$directive" -r "$reason" "$msg"
77   unset r msg mode condition directive reason skip_reason
78 }
79
80 # ----------------------------------------------------------------------
81
82 $ACLOCAL    || fatal_ "aclocal failed"
83 $AUTOCONF   || fatal_ "autoconf failed"
84 $AUTOMAKE   || fatal_ "automake failed"
85 ./configure || fatal_ "configure failed"
86
87 # ----------------------------------------------------------------------
88
89 check_make --run
90
91 # Test against a known regression.  This was especially heinous, since
92 # make running in normal mode was sometimes mistaken for make running
93 # in dry mode.
94 check_make --run TESTS="n1.test n2.test"
95 check_make --run TESTS="n1 n2" AM_MAKEFLAGS="TESTS='n1 n2'"
96 check_make --run TESTS="n1 n2" AM_MAKEFLAGS='TESTS="n1 n2"'
97 check_make --run FOOFLAGS="-n -n -knf2 n --none -n"
98 check_make --run MYFLAGS="-n --dryrun -n --dry-run -n"
99
100 # ----------------------------------------------------------------------
101
102 check_make --dry -C make_plus_silence 'recipe prefix "+" unsupported' -n
103 check_make --dry -C using_gmake "\$MAKE is not GNU make" --dry-run -k
104
105 # ----------------------------------------------------------------------
106
107 # Automake bug#13760: the "n" in "none" used to confound am__make_dryrun
108 # into thinking the '-n' option had been passed.
109
110 pr='bug#13760'
111
112 check_make --run -C make_supports_option_I "-I make option unsupported" \
113                  -M "$pr" -I none
114
115 check_make --run -C using_gmake "\$MAKE is not GNU make" \
116                  -M "$pr" -I none --include dry-run 
117
118 check_make --dry -C make_supports_option_I "-I make option unsupported" \
119                  -M "$pr" -I none -n
120
121 check_make --dry -C using_gmake "\$MAKE is not GNU make" \
122                  -M "$pr" --dry-run -I none --include dry-run
123
124 # ----------------------------------------------------------------------
125
126 # Test for when shell metacharacters or backslashes are in $(MAKEFLAGS).
127
128 check_metachars ()
129 {
130   check_make --run -M "metachars" "$@"
131 }
132
133 check_metachars MYFLAGS="-n \"n\" '-n' --none -n"
134 check_metachars MYFLAGS='-knf2\ n\ \\n'
135 check_metachars MYFLAGS="(&) | ; \" \` '"
136 check_metachars MYFLAGS=" ' # ' "
137 check_metachars MYFLAGS='$(foo)'
138 check_metachars MYFLAGS='$(foo -n)'
139 check_metachars MYFLAGS='`touch bad`'
140 check_metachars MYFLAGS='`touch --dry-run bad`'
141
142 # ----------------------------------------------------------------------
143
144 :