- Enhance .POSIX to set -e when invoking shells, as demanded by a
[make.git] / tests / scripts / variables / SHELL
blob69871d2d2f6850f77031121273bcaafbe7b4c076
1 #                                                                    -*-perl-*-
3 $description = "Test proper handling of SHELL.";
5 # Find the default value when SHELL is not set.  On UNIX it will be /bin/sh,
6 # but on other platforms who knows?
7 resetENV();
8 delete $ENV{SHELL};
9 $mshell = `echo 'all:;\@echo \$(SHELL)' | $make_path -f-`;
10 chop $mshell;
12 # According to POSIX, the value of SHELL in the environment has no impact on
13 # the value in the makefile.
14 # Note %extraENV takes precedence over the default value for the shell.
16 $extraENV{SHELL} = '/dev/null';
17 run_make_test('all:;@echo "$(SHELL)"', '', $mshell);
19 # According to POSIX, any value of SHELL set in the makefile should _NOT_ be
20 # exported to the subshell!  I wanted to set SHELL to be $^X (perl) in the
21 # makefile, but make runs $(SHELL) -c 'commandline' and that doesn't work at
22 # all when $(SHELL) is perl :-/.  So, we just add an extra initial /./ which
23 # works well on UNIX and seems to work OK on at least some non-UNIX systems.
25 $extraENV{SHELL} = $mshell;
27 run_make_test("SHELL := /./$mshell\n".'
28 all:;@echo "$(SHELL) $$SHELL"
29 ', '', "/./$mshell $mshell");
31 # As a GNU make extension, if make's SHELL variable is explicitly exported,
32 # then we really _DO_ export it.
34 $extraENV{SHELL} = $mshell;
36 run_make_test("export SHELL := /./$mshell\n".'
37 all:;@echo "$(SHELL) $$SHELL"
38 ', '', "/./$mshell /./$mshell");
41 # Test out setting of SHELL, both exported and not, as a target-specific
42 # variable.
44 $extraENV{SHELL} = $mshell;
46 run_make_test("all: SHELL := /./$mshell\n".'
47 all:;@echo "$(SHELL) $$SHELL"
48 ', '', "/./$mshell $mshell");
50 $extraENV{SHELL} = $mshell;
52 run_make_test("
53 SHELL := /././$mshell
54 one: two
55 two: export SHELL := /./$mshell\n".'
56 one two:;@echo "$@: $(SHELL) $$SHELL"
57 ', '', "two: /./$mshell /./$mshell\none: /././$mshell $mshell\n");
59 # Test .SHELLFLAGS
61 run_make_test(q!
62 .SHELLFLAGS = -xc
63 all: ; @true
65               '', "+ true\n");
67 run_make_test(q!
68 .SHELLFLAGS = -xec
69 all: ; @true; false; true
71               '', "+ true\n+ false\n#MAKE#: *** [all] Error 1\n", 512);