Debian Codegraph @

tests/scripts/variables/SHELL

raw
1 # -*-perl-*-
2
3 $description = "Test proper handling of SHELL.";
4
5 # If we don't have a POSIX shell available, never mind
6 $is_posix_sh or return -1;
7
8 # On Windows, shell names might not match
9 if ($port_type eq 'W32') {
10 return -1;
11 }
12
13 $mshell = $sh_name;
14
15 # According to POSIX, the value of SHELL in the environment has no impact on
16 # the value in the makefile.
17 # Note %extraENV takes precedence over the default value for the shell.
18
19 $extraENV{SHELL} = '/dev/null';
20 run_make_test('all:;@echo "$(SHELL)"', '', $mshell);
21
22 # According to POSIX, any value of SHELL set in the makefile should _NOT_ be
23 # exported to the subshell! I wanted to set SHELL to be $^X (perl) in the
24 # makefile, but make runs $(SHELL) -c 'commandline' and that doesn't work at
25 # all when $(SHELL) is perl :-/. So, we just add an extra initial /./ which
26 # works well on UNIX and seems to work OK on at least some non-UNIX systems.
27
28 $extraENV{SHELL} = $mshell;
29
30 my $altshell = "/./$mshell";
31 my $altshell2 = "/././$mshell";
32 if ($mshell =~ m,^([a-zA-Z]:)([\\/])(.*),) {
33 $altshell = "$1$2.$2$3";
34 $altshell2 = "$1$2.$2.$2$3";
35 }
36
37 run_make_test("SHELL := $altshell\n".'
38 all:;@echo "$(SHELL) $$SHELL"
39 ', '', "$altshell $mshell");
40
41 # As a GNU make extension, if make's SHELL variable is explicitly exported,
42 # then we really _DO_ export it.
43
44 $extraENV{SHELL} = $mshell;
45
46 run_make_test("export SHELL := $altshell\n".'
47 all:;@echo "$(SHELL) $$SHELL"
48 ', '', "$altshell $altshell");
49
50
51 # Test out setting of SHELL, both exported and not, as a target-specific
52 # variable.
53
54 $extraENV{SHELL} = $mshell;
55
56 run_make_test("all: SHELL := $altshell\n".'
57 all:;@echo "$(SHELL) $$SHELL"
58 ', '', "$altshell $mshell");
59
60 $extraENV{SHELL} = $mshell;
61
62 run_make_test("
63 SHELL := $altshell2
64 one: two
65 two: export SHELL := $altshell\n".'
66 one two:;@echo "$@: $(SHELL) $$SHELL"
67 ', '', "two: $altshell $altshell\none: $altshell2 $mshell\n");
68
69 # Test .SHELLFLAGS
70
71 # We don't know the output here: on Solaris for example, every line printed
72 # by the shell in -x mode has a trailing space (!!)
73 my $script = 'true; true';
74 my $flags = '-xc';
75 my $out = `$sh_name $flags '$script' 2>&1`;
76
77 run_make_test(qq!
78 .SHELLFLAGS = $flags
79 all: ; \@$script
80 !,
81 '', $out);
82
83 # Do it again but add spaces to SHELLFLAGS
84
85 # Some shells (*shakes fist at Solaris*) cannot handle multiple flags in
86 # separate arguments.
87 my $t = `$sh_name -e -c true 2>/dev/null`;
88 my $multi_ok = $? == 0;
89
90 if ($multi_ok) {
91 $flags = '-x -c';
92 run_make_test(qq!
93 .SHELLFLAGS = $flags
94 all: ; \@$script
95 !,
96 '', $out);
97 }
98
99 # We can't just use "false" because on different systems it provides a
100 # different exit code--once again Solaris: false exits with 255 not 1
101 $script = 'true; false; true';
102 $flags = '-xec';
103 $out = `$sh_name $flags '$script' 2>&1`;
104 my $err = $? >> 8;
105
106 run_make_test(qq!
107 .SHELLFLAGS = $flags
108 all: ; \@$script
109 !,
110 '', "+ true
111 + false
112 #MAKEFILE#:3: *** [all] error $err
113
114 #0 all at $fullworkdir/SHELL.mk.7:3", 512);
115
116 1;