make/tests/scripts/variables/SHELL
Paul Smith 11444fb001 [SV 62654] Support GNU Make on z/OS
Original patches provided by Igor Todorovski <itodorov@ca.ibm.com>
Reworked by Paul Smith <psmith@gnu.org>.
Thanks to IBM for providing a test system.

* NEWS: Announce support.
* AUTHORS: Ditto.
* README.zOS: Provide details on building GNU Make on z/OS.
* build.sh (get_mk_var): z/OS sh has a strange bug which causes it to
generate extra lines of output: rework the function to print output
as we compute it instead of collecting it into a variable, which
works around this bug.
* src/makeint.h: Declare MK_OS_ZOS if we're building for z/OS.
* src/arscan.c: Don't include <ar.h> on z/OS.
* src/job.c: We can't change environ in ASCII mode on z/OS.
* src/main.c: Ditto.  Also we can't use pselect() on z/OS.
* src/posixos.c: pselect() seems to hang on z/OS: don't use it.
* tests/run_make_tests.pl: Handle different exit codes on z/OS.
* tests/test_driver.pl: Preserve some special z/OS env.vars.
Add special checks to output comparisons when on z/OS.
* tests/scripts/features/archives: Don't validate names.  Don't
try to compile empty files as IBM compilers complain.
* tests/scripts/features/shell_assignment: Fix octal value of #.
* tests/scripts/features/temp_stdin: Don't print "term".
* tests/scripts/functions/shell: Handle shell exit codes.
* tests/scripts/targets/ONESHELL: Ditto.
* tests/scripts/targets/POSIX: sh -x prints differently.
* tests/scripts/variables/SHELL: Ditto.
2023-01-08 10:45:38 -05:00

108 lines
2.5 KiB
Perl

# -*-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 some systems, 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);
}
$script = subst_make_string('true; #HELPER# -q fail 1; true');
$flags = '-xec';
$out = `$sh_name $flags '$script' 2>&1`;
run_make_test(qq!
.SHELLFLAGS = $flags
all: ; \@$script
!,
'', "${out}#MAKE#: *** [#MAKEFILE#:3: all] Error 1", 512);
1;