make/tests/scripts/options/dash-I
Paul Smith a581146562 tests [WINDOWS32]: Support Strawberry Perl on Windows
Strawberry Perl has some different behaviors from ActiveState Perl
which impact the test suite:

- Avoid Perl's chomp() as it may not remove CRs; chomp() may remove
  only the final NL but not the CR in a CRNL line ending.
- Strawberry Perl doesn't support ActiveState's system(1, ...) form.
- Strawberry Perl (or msys?) does something weird with "/tmp" when
  provided to exec(), replacing it with the user's %TEMP%.
- Strawberry Perl uses msys paths like /c/foo instead of C:\foo.

* tests/test_driver.pl (get_osname): Strawberry Perl uses 'msys' as
its $^O so if we see that use a port of 'W32'.
(_run_with_timeout): Strawberry Perl doesn't support the special
system(1, ...) form of system() so use POSIX standard fork/exec.
(compare_answer): Paths generated by Strawberry Perl use msys path
format (e.g., /c/foo instead of C:\foo); check for those differences
and compare RE against both the unmodified and modified log.
* tests/run_make_tests.pl (set_defaults): Switch from chomp to s///
to remove CRNL and NL line endings.
* tests/scripts/features/errors: Executing directories on Strawberry
will give an error; translate it to Windows error output format.
* tests/scripts/features/output-sync: Ditto.
* tests/scripts/features/temp_stdin: Ditto.
* tests/scripts/functions/realpath: Ditto.
* tests/scripts/options/dash-I: Ditto.
* tests/scripts/variables/INCLUDE_DIRS: Ditto.
* tests/scripts/misc/close_stdout: /dev/full is reported as existing
on Strawberry Perl, but it doesn't do anything.  Skip the test.
* tests/scripts/variables/MAKEFLAGS: When an argument containing
/tmp is passed to a program via exec(), something replaces it with
the expansion of the %TEMP% variable.  Instead of using /tmp create
a local directory to use.
2022-12-20 02:14:18 -05:00

116 lines
3.5 KiB
Perl

# -*-perl-*-
$description = "The following test creates a makefile to test the -I option.";
$details = "\
This test tests the -I option by including a filename in
another directory and giving make that directory name
under -I in the command line. Without this option, the make
would fail to find the included file. It also checks to make
sure that the -I option gets passed to recursive makes.";
use File::Spec;
# Create a directory and put a makefile in it.
# We can't put it in the current directory since that's automatically searched
# anyway.
my $subdir = 'idir';
mkdir($subdir, 0777);
my $included = 'ifile.mk';
my $ipath = File::Spec->catfile($subdir, $included);
create_file($ipath, "
ANOTHER:
\t\@echo This is another included makefile
recurse:
\t\@\$(MAKE) ANOTHER -f \$(main_makefile)\n");
my $nosuch = "#MAKEFILE#:5: $included: $ERR_no_such_file
#MAKE#: *** No rule to make target '$included'. Stop.\n";
# Verify that we get an error if we don't have -I
run_make_test(qq!
main_makefile := \$(firstword \$(MAKEFILE_LIST))
all:
\t\@echo There should be no errors for this makefile
include $included
!,
'', $nosuch, 512);
# Check basic -I works
run_make_test(undef, "-I $subdir all",
"There should be no errors for this makefile\n");
# Check that the included target works
run_make_test(undef, "-I $subdir ANOTHER",
"This is another included makefile\n");
# Check that -I is passed down through MAKEFLAGS
run_make_test(undef, "-I $subdir recurse",
"#MAKE#[1]: Entering directory '#PWD#'
This is another included makefile
#MAKE#[1]: Leaving directory '#PWD#'\n");
# Verify that we get an error if we add -I- to delete previous includes
run_make_test(undef, "-I $subdir -I- all", $nosuch, 512);
# Make another directory with the same name and make sure the right one is
# chosen if -I- stops the path.
mkdir('idir2', 0777);
my $ipath2 = File::Spec->catfile('idir2', $included);
create_file($ipath2, "This is a bad makefile!!\n");
run_make_test(undef, "-I idir2 -I $subdir ANOTHER",
"$included:1: *** missing separator. Stop.\n", 512);
run_make_test(undef, "-I idir2 -I - -I $subdir ANOTHER",
"This is another included makefile\n");
# Check that -I- is passed down through MAKEFLAGS
run_make_test(undef, "-I idir2 -I - -I $subdir recurse",
"#MAKE#[1]: Entering directory '#PWD#'
This is another included makefile
#MAKE#[1]: Leaving directory '#PWD#'\n");
unlink($ipath2);
rmdir('idir2');
# The only way to check if -I- voids included directories is to see if a file
# exists in one and try to include it. We very likely can't add our own files
# to the default directories since they're probably write-protected. This
# won't work if none of the default directories contain any files :-/
create_file('defaultdirs.mk', "\$(info \$(.INCLUDE_DIRS))\nall:;\@:\n");
my $cmd = subst_make_string("#MAKEPATH# -f defaultdirs.mk");
my @dirs = `$cmd`;
my $dirs = $dirs[0];
$dirs =~ s/\r?\n//g;
unlink('defaultdirs.mk');
my $fn = undef;
foreach my $dn (split ' ', $dirs) {
# On Windows the default is "." which is bogus!
if ($dn ne '.') {
my @files = glob(File::Spec->catfile($dn, "*"));
if (@files) {
(undef, undef, $fn) = File::Spec->splitpath($files[0]);
last;
}
}
}
if ($fn) {
run_make_test("
all:;
include $fn
",
'-I-', "#MAKEFILE#:3: $fn: $ERR_no_such_file
#MAKE#: *** No rule to make target '$fn'. Stop.\n", 512);
}
unlink($ipath);
rmdir($subdir);
1;