make/tests/scripts/functions/wildcard

103 lines
2.4 KiB
Perl

# -*-perl-*-
$description = "The following test creates a makefile to test wildcard
expansions and the ability to put a command on the same
line as the target name separated by a semi-colon.";
$details = "\
This test creates 4 files by the names of 1.example,
two.example and 3.example. We execute three tests. The first
executes the print1 target which tests the '*' wildcard by
echoing all filenames by the name of '*.example'. The second
test echo's all files which match '?.example' and
[a-z0-9].example. Lastly we clean up all of the files using
the '*' wildcard as in the first test";
touch("example.1");
touch("example.two");
touch("example.3");
touch("example.for");
touch("example._");
# TEST #1
# -------
run_make_test(qq/
.PHONY: print1 print2 clean
print1: ;\@echo \$(wildcard example.*)
print2:
\t\@echo \$(wildcard example.?)
\t\@echo \$(wildcard example.[a-z0-9])
\t\@echo \$(wildcard example.[!A-Za-z_\\!])
clean:
\t$CMD_rmfile \$(wildcard example.*)
/,
'print1', "example.1 example.3 example._ example.for example.two\n");
# TEST #2
# -------
run_make_test(undef, 'print2', "example.1 example.3 example._\n"
."example.1 example.3\n"
."example.1 example.3\n");
# TEST #3
# -------
$answer = "$CMD_rmfile example.1 example.3 example._ example.for example.two";
if ($vos)
{
$answer .= " \n";
}
else
{
$answer .= "\n";
}
run_make_test(undef, 'clean', $answer);
# TEST #4: Verify that failed wildcards don't return the pattern
run_make_test(q!
all: ; @echo $(wildcard xz--y*.7)
!,
'', "\n");
# TEST #5: wildcard used to verify file existence
touch('xxx.yyy');
run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
'', "file=xxx.yyy\n");
unlink('xxx.yyy');
run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
'', "file=\n");
if ($port_type ne 'W32' && eval { symlink("",""); 1 }) {
# TEST #6: check for wildcards matching directories
# See SV 53465
my $dir = '__rdir';
my $lnk = '__ldir';
mkdir($dir, 0777);
symlink($dir, $lnk);
run_make_test(qq!all: ; \@echo \$(wildcard $lnk*/.)!, '', "$lnk/.");
unlink($lnk);
rmdir($dir);
# Test for dangling symlinks
symlink($dir, $lnk);
run_make_test(qq!all: ; \@echo \$(wildcard $lnk)!, '', "$lnk");
unlink($lnk);
}
1;