tests: refactor/enhance tests about make dry-run mode
[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_ 14
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 echo AC_OUTPUT >> configure.ac
30
31 cat > Makefile.am <<'END'
32 all:
33         : Dummy, nothing to do.
34 foo:
35         $(MAKE) all
36 run:
37         @echo ":: $$MAKEFLAGS ::"; : For debugging.
38         $(am__make_dryrun) && exit 1; echo ok > from-run
39 dry:
40         +@echo ":: $$MAKEFLAGS ::"; : For debugging.
41         +$(am__make_dryrun) || exit 1; echo ok > from-dry
42 END
43
44 check_make ()
45 {
46   r=ok msg= mode= condition=: directive= reason= skip_reason=
47   case $1 in
48     --dry) mode=dry;;
49     --run) mode=run;;
50     *) fatal_ "check_run: invalid usage";;
51   esac
52   shift
53   while test $# -gt 0; do
54     case $1 in
55       -C) condition=$2 skip_reason=$3; shift; shift;;
56       -M) msg=$2; shift;;
57       -X) directive=TODO;;
58       --) shift; break;;
59        *) break;;
60     esac
61     shift
62   done
63   msg=${mode}${msg:+" [$msg]"}
64   if $condition; then
65     $MAKE "$mode" ${1+"$@"} || r='not ok'
66     test -f from-$mode      || r='not ok'
67     test ! -e bad           || r='not ok'
68     rm -f bad from-*        || fatal_ "cleaning up"
69   else
70     directive=SKIP reason=$skip_reason
71   fi
72   result_ "$r" -D "$directive" -r "$reason" "$msg"
73   unset r msg mode condition directive reason skip_reason
74 }
75
76 # ----------------------------------------------------------------------
77
78 $ACLOCAL    || fatal_ "aclocal failed"
79 $AUTOCONF   || fatal_ "autoconf failed"
80 $AUTOMAKE   || fatal_ "automake failed"
81 ./configure || fatal_ "configure failed"
82
83 # ----------------------------------------------------------------------
84
85 check_make --run
86
87 # Test against a known regression.  This was especially heinous, since
88 # make running in normal mode was sometimes mistaken for make running
89 # in dry mode.
90 check_make --run TESTS="n1.test n2.test"
91 check_make --run TESTS="n1 n2" AM_MAKEFLAGS="TESTS='n1 n2'"
92 check_make --run TESTS="n1 n2" AM_MAKEFLAGS='TESTS="n1 n2"'
93 check_make --run FOOFLAGS="-n -n -knf2 n --none -n"
94 check_make --run MYFLAGS="-n --dryrun -n --dry-run -n"
95
96 # ----------------------------------------------------------------------
97
98 check_make --dry -C make_plus_silence 'recipe prefix "+" unsupported' -n
99 check_make --dry -C using_gmake "\$MAKE is not GNU make" --dry-run -k
100
101 # ----------------------------------------------------------------------
102
103 # Test for when shell metacharacters or backslashes are in $(MAKEFLAGS).
104
105 check_metachars ()
106 {
107   check_make --run -M "metachars" "$@"
108 }
109
110 check_metachars MYFLAGS="-n \"n\" '-n' --none -n"
111 check_metachars MYFLAGS='-knf2\ n\ \\n'
112 check_metachars MYFLAGS="(&) | ; \" \` '"
113 check_metachars MYFLAGS=" ' # ' "
114 check_metachars MYFLAGS='$(foo)'
115 check_metachars MYFLAGS='`touch bad`'
116
117 # ----------------------------------------------------------------------
118
119 :