test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / built-sources-fork-bomb.sh
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 # Due to how the handling of $(BUILT_SOURCES) is implemented in Automake-NG,
18 # a recursive make call in the recipe of any $(BUILT_SOURCES) (or of any of
19 # its prerequisites) might cause an infinite recursion (complete with fork
20 # bomb, yuck) if not handled correctly.  Verify that this doesn't happen.
21 # For more background, see:
22 # <http://lists.gnu.org/archive/html/help-smalltalk/2012-08/msg00027.html>
23 # <http://lists.gnu.org/archive/html/automake-patches/2012-08/msg00052.html>
24 # Backported to improve coverage of mainline Automake.
25
26 required=GNUmake
27 . test-init.sh
28
29 echo AC_OUTPUT >> configure.ac
30
31 cat > Makefile.am << 'END'
32 BUILT_SOURCES = foo
33 .PHONY: build-foo
34 build-foo:
35         echo OK > foo
36 foo:
37         $(MAKE) build-foo
38
39 # If the bug is still present, we want this test to fail, not to actually
40 # go fork bomb and potentially crash the user machine.  Take care of that.
41
42 is_too_deep := $(shell test $(MAKELEVEL) -lt 10 && echo no)
43
44 ## Extra indentation here required to avoid confusing Automake.
45  ifeq ($(is_too_deep),no)
46    # All is ok.
47  else
48    $(error ::OOPS:: Recursion too deep, $(MAKELEVEL) levels)
49  endif
50 END
51
52 $ACLOCAL
53 $AUTOMAKE -Wno-portability
54 $AUTOCONF
55
56 ./configure
57
58 run_make -M -- -n foo
59 test ! -f foo
60 # Guard against possible infinite recursion.
61 $FGREP '::OOPS::' output && exit 1
62
63 run_make -M -- foo
64 # Guard against possible infinite recursion.
65 $FGREP '::OOPS::' output && exit 1
66
67 :