summaryrefslogtreecommitdiff
path: root/tests/scripts/variables/SHELL
blob: fa3b5fc8874c12ab33fbfb09c1e538afb53426be (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
96
97
98
99
100
101
102
103
#                                                                    -*-perl-*-

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

# If we don't have a POSIX shell available, never mind
$is_posix_sh or return -1;

# On Windows, shell names might not match
if ($port_type eq 'W32') {
    return -1;
}

$mshell = $sh_name;

# According to POSIX, the value of SHELL in the environment has no impact on
# the value in the makefile.

$ENV{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.  A more portable option might be to set SHELL to
# be $^X (perl) in the makefile, and set .SHELLFLAGS to -e.

$ENV{SHELL} = $mshell;

my $altshell = "/./$mshell";
my $altshell2 = "/././$mshell";

if ($mshell =~ m,^([a-zA-Z]:)([\\/])(.*),) {
    $altshell = "$1$2.$2$3";
    $altshell2 = "$1$2.$2.$2$3";
}

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

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

$ENV{SHELL} = $mshell;

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


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

$ENV{SHELL} = $mshell;

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

$ENV{SHELL} = $mshell;

run_make_test("
SHELL := $altshell2
one: two
two: export SHELL := $altshell\n".'
one two:;@echo "$@: $(SHELL) $$SHELL"
', '', "two: $altshell $altshell\none: $altshell2 $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 = `$sh_name $flags '$script' 2>&1`;

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

# Do it again but add spaces to SHELLFLAGS

# Some shells (*shakes fist at Solaris*) cannot handle multiple flags in
# separate arguments.
my $t = `$sh_name -e -c true 2>/dev/null`;
my $multi_ok = $? == 0;

if ($multi_ok) {
    $flags = '-x -c';
    run_make_test(qq!
.SHELLFLAGS = $flags
all: ; \@$script
!,
              '', $out);
}

run_make_test(qq!
.SHELLFLAGS = -xec
all: ; \@true; #HELPER# -q fail 1; true
!,
              '', "+ true\n+ #HELPER# -q fail 1\n#MAKE#: *** [#MAKEFILE#:3: all] Error 1\n", 512);

1;