summaryrefslogtreecommitdiff
path: root/tests/scripts/variables/SHELL
blob: 3d49349bb7dad7908aa3e4d350603d679cf69c5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#                                                                    -*-perl-*-

$description = "Test proper handling of SHELL.";

# Find the default value when SHELL is not set.  On UNIX it will be /bin/sh,
# but on other platforms who knows?
resetENV();
delete $ENV{SHELL};
$mshell = `echo 'all:;\@echo \$(SHELL)' | $make_path -f-`;
chop $mshell;

# According to POSIX, the value of SHELL in the environment has no impact on
# the value in the makefile.
# Note %extraENV takes precedence over the default value for the shell.

$extraENV{SHELL} = '/dev/null';
run_make_test('all:;@echo "$(SHELL)"', '', $mshell);

# According to POSIX, any value of SHELL set in the makefile should _NOT_ be
# exported to the subshell!  I wanted to set SHELL to be $^X (perl) in the
# makefile, but make runs $(SHELL) -c 'commandline' and that doesn't work at
# all when $(SHELL) is perl :-/.  So, we just add an extra initial /./ which
# works well on UNIX and seems to work OK on at least some non-UNIX systems.

$extraENV{SHELL} = $mshell;

run_make_test("SHELL := /./$mshell\n".'
all:;@echo "$(SHELL) $$SHELL"
', '', "/./$mshell $mshell");

# As a GNU make extension, if make's SHELL variable is explicitly exported,
# then we really _DO_ export it.

$extraENV{SHELL} = $mshell;

run_make_test("export SHELL := /./$mshell\n".'
all:;@echo "$(SHELL) $$SHELL"
', '', "/./$mshell /./$mshell");


# Test out setting of SHELL, both exported and not, as a target-specific
# variable.

$extraENV{SHELL} = $mshell;

run_make_test("all: SHELL := /./$mshell\n".'
all:;@echo "$(SHELL) $$SHELL"
', '', "/./$mshell $mshell");

$extraENV{SHELL} = $mshell;

run_make_test("
SHELL := /././$mshell
one: two
two: export SHELL := /./$mshell\n".'
one two:;@echo "$@: $(SHELL) $$SHELL"
', '', "two: /./$mshell /./$mshell\none: /././$mshell $mshell\n");

# Test .SHELLFLAGS

# We don't know the output here: on Solaris for example, every line printed
# by the shell in -x mode has a trailing space (!!)
my $script = 'true; true';
my $flags = '-xc';
my $out = `/bin/sh $flags '$script' 2>&1`;

run_make_test(qq!
.SHELLFLAGS = $flags
all: ; \@$script
!,
              '', $out);

# Do it again but add spaces to SHELLFLAGS
$flags = '-x -c';
run_make_test(qq!
.SHELLFLAGS = $flags
all: ; \@$script
!,
              '', $out);

# We can't just use "false" because on different systems it provides a
# different exit code--once again Solaris: false exits with 255 not 1
$script = 'true; false; true';
$flags = '-xec';
$out = `/bin/sh $flags '$script' 2>&1`;
my $err = $? >> 8;

run_make_test(qq!
.SHELLFLAGS = $flags
all: ; \@$script
!,
              '', "$out#MAKEFILE#:3: recipe for target `all' failed
#MAKE#: *** [all] Error $err\n", 512);

1;