make/tests/scripts/features/exec
Paul Smith cad3ddd165 Enhance tests to work on different systems
The GNU platform testers reported a number of test errors on
different systems; try to address them.

* tests/thelp.pl: A number of tests timed out with a 4-second
timeout.  Increase the default timeout to 10 seconds.
* tests/run_make_tests.pl: Executing directories on cygwin behaves
differently in Perl than make so skip these tests there.
* tests/scripts/options/symlinks: Check for the symlink feature
in make, rather than whether the system supports them.
* tests/scripts/features/implicit_search: On some systems "false"
exits with a different exit code.  Use the helper instead.
* tests/scripts/features/loadapi: Ditto.
* tests/scripts/features/output-sync: Sleep before make -f bar in
the first test as well as the second one.
* tests/scripts/features/exec: Skip on cygwin, which seems to
be "UNIX" but where scripts don't run normally.
* tests/scripts/misc/fopen-fail: Skip on cygwin, where make
eventually exits with exit code 0 and no error messages.
2022-10-22 22:37:49 -04:00

64 lines
1.8 KiB
Perl

# -*-perl-*-
use warnings;
my $description = "Test that make can execute binaries as well as scripts with"
." various shabangs and without a shbang";
my $details = "The various shells that this test uses are the default"
." /bin/sh, \$SHELL and the perl interpreter that is"
." executing this test program. The shells are used for the value"
." of SHELL inside the test makefile and also as a shbang in the"
." executed script. There is also a test which executes a script"
." that has no shbang.";
# Only bother with this on UNIX systems
$port_type eq 'UNIX' or return -1;
$^O =~ /cygwin/ and return -1;
my $usersh = $origENV{SHELL};
my $answer = 'hello, world';
my @shbangs = ('', '#!/bin/sh', "#!$usersh", "#!$perl_name");
my @shells = ('', 'SHELL=/bin/sh', "SHELL=$usersh");
# tests [0-11]
# Have a makefile with various SHELL= exec a shell program with varios
# shbangs or without a shbang at all.
my $stem = './exec.cmd';
my $k = 0;
for my $shbang (@shbangs) {
for my $shell (@shells) {
my $cmd = $k ? "$stem.$k" : $stem;
++$k;
unlink $cmd;
open(CMD,"> $cmd");
print CMD "$shbang\n";
print CMD "printf \"$answer\\n\";\n";
close(CMD);
chmod 0700, $cmd;
run_make_test("# shbang=$shbang\n# shell=$shell" . q!
all:; @$(CMD)
!, "$shell CMD=$cmd", "$answer\n");
rmfiles($cmd);
}
}
# tests [12-14]
# Exec a binary from a makefile that has SHELL=.
for my $shell (@shells) {
run_make_test(q!
all:; @#PERL# -e 'printf "$(ANSWER)\n"';
!, "$shell ANSWER='$answer'", "$answer\n");
}
# test 15
# Use perl as a shell.
run_make_test(q!
SHELL = #PERL#
.SHELLFLAGS = -e
all:; @printf "$(ANSWER)\n";
!, "ANSWER='$answer'", "$answer\n");
1;