| 1 |
# -*-perl-*- |
| 2 |
|
| 3 |
$description = "The following test creates a makefile to test wildcard |
| 4 |
expansions and the ability to put a command on the same |
| 5 |
line as the target name separated by a semi-colon."; |
| 6 |
|
| 7 |
$details = "\ |
| 8 |
This test creates 4 files by the names of 1.example, |
| 9 |
two.example and 3.example. We execute three tests. The first |
| 10 |
executes the print1 target which tests the '*' wildcard by |
| 11 |
echoing all filenames by the name of '*.example'. The second |
| 12 |
test echo's all files which match '?.example' and |
| 13 |
[a-z0-9].example. Lastly we clean up all of the files using |
| 14 |
the '*' wildcard as in the first test"; |
| 15 |
|
| 16 |
touch("example.1"); |
| 17 |
touch("example.two"); |
| 18 |
touch("example.3"); |
| 19 |
touch("example.for"); |
| 20 |
touch("example._"); |
| 21 |
|
| 22 |
# TEST #1 |
| 23 |
# ------- |
| 24 |
|
| 25 |
run_make_test(qq/ |
| 26 |
.PHONY: print1 print2 clean |
| 27 |
print1: ;\@echo \$(wildcard example.*) |
| 28 |
print2: |
| 29 |
\t\@echo \$(wildcard example.?) |
| 30 |
\t\@echo \$(wildcard example.[a-z0-9]) |
| 31 |
\t\@echo \$(wildcard example.[!A-Za-z_\\!]) |
| 32 |
clean: |
| 33 |
\t$CMD_rmfile \$(wildcard example.*) |
| 34 |
/, |
| 35 |
'print1', "example.1 example.3 example._ example.for example.two\n"); |
| 36 |
|
| 37 |
# TEST #2 |
| 38 |
# ------- |
| 39 |
|
| 40 |
run_make_test(undef, 'print2', "example.1 example.3 example._\n" |
| 41 |
."example.1 example.3\n" |
| 42 |
."example.1 example.3\n"); |
| 43 |
|
| 44 |
# TEST #3 |
| 45 |
# ------- |
| 46 |
|
| 47 |
$answer = "$CMD_rmfile example.1 example.3 example._ example.for example.two"; |
| 48 |
if ($vos) |
| 49 |
{ |
| 50 |
$answer .= " \n"; |
| 51 |
} |
| 52 |
else |
| 53 |
{ |
| 54 |
$answer .= "\n"; |
| 55 |
} |
| 56 |
|
| 57 |
run_make_test(undef, 'clean', $answer); |
| 58 |
|
| 59 |
# TEST #4: Verify that failed wildcards don't return the pattern |
| 60 |
|
| 61 |
run_make_test(q! |
| 62 |
all: ; @echo $(wildcard xz--y*.7) |
| 63 |
!, |
| 64 |
'', "\n"); |
| 65 |
|
| 66 |
# TEST #5: wildcard used to verify file existence |
| 67 |
|
| 68 |
touch('xxx.yyy'); |
| 69 |
|
| 70 |
run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, '', "file=xxx.yyy\n"); |
| 71 |
|
| 72 |
unlink('xxx.yyy'); |
| 73 |
|
| 74 |
run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, '', "file=\n"); |
| 75 |
|
| 76 |
# TEST #7: verify that when the input pattern has a trailing slash wildcard |
| 77 |
# returns only directories. |
| 78 |
# |
| 79 |
# Currently this doesn't work with our embedded GLOB so disable it. |
| 80 |
# ------- |
| 81 |
|
| 82 |
if (get_config('USE_SYSTEM_GLOB') eq 'yes') { |
| 83 |
touch("hellof"); |
| 84 |
mkdir("hellod", 0770); |
| 85 |
mkdir("hellod/worldd", 0770); |
| 86 |
touch("hellod/worldf"); |
| 87 |
mkdir("hellod/worldd/kend1", 0770); |
| 88 |
mkdir("hellod/worldd/kend2", 0770); |
| 89 |
touch("hellod/worldd/kenf1"); |
| 90 |
touch("hellod/worldd/kenf2"); |
| 91 |
|
| 92 |
run_make_test(qq! |
| 93 |
print3: |
| 94 |
\t\@echo \$(wildcard hello*) |
| 95 |
\t\@echo \$(wildcard hello*/) |
| 96 |
\t\@echo \$(wildcard hellod/world*) |
| 97 |
\t\@echo \$(wildcard hellod/world*/) |
| 98 |
\t\@echo \$(wildcard hello* hellod/world*) |
| 99 |
\t\@echo \$(wildcard hello*/ hellod/world*/) |
| 100 |
\t\@echo \$(wildcard hellod/*) |
| 101 |
\t\@echo \$(wildcard hellod/*/) |
| 102 |
\t\@echo \$(wildcard */world*) |
| 103 |
\t\@echo \$(wildcard */worldd/) |
| 104 |
\t\@echo \$(wildcard hellod/*/ken*/) |
| 105 |
\t\@echo \$(wildcard hellod/*/ken?[12]) |
| 106 |
\t\@echo \$(wildcard hellod/*/ken?[12]/) |
| 107 |
!, '', |
| 108 |
"hellod hellof\n" |
| 109 |
."hellod/\n" |
| 110 |
."hellod/worldd hellod/worldf\n" |
| 111 |
."hellod/worldd/\n" |
| 112 |
."hellod hellof hellod/worldd hellod/worldf\n" |
| 113 |
."hellod/ hellod/worldd/\n" |
| 114 |
."hellod/worldd hellod/worldf\n" |
| 115 |
."hellod/worldd/\n" |
| 116 |
."hellod/worldd hellod/worldf\n" |
| 117 |
."hellod/worldd/\n" |
| 118 |
."hellod/worldd/kend1/ hellod/worldd/kend2/\n" |
| 119 |
."hellod/worldd/kend1 hellod/worldd/kend2 " |
| 120 |
."hellod/worldd/kenf1 hellod/worldd/kenf2\n" |
| 121 |
."hellod/worldd/kend1/ hellod/worldd/kend2/\n"); |
| 122 |
|
| 123 |
unlink('hellof', 'hellod/worldf', 'hellod/worldd/kenf1', |
| 124 |
'hellod/worldd/kenf2'); |
| 125 |
foreach $d ('hellod/worldd/kend1', 'hellod/worldd/kend2', 'hellod/worldd', |
| 126 |
'hellod') { |
| 127 |
rmdir($d); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
if ($port_type ne 'W32') { |
| 132 |
# Check wildcard on the root directory |
| 133 |
run_make_test('print4: ; @echo $(wildcard /)', '', "/\n"); |
| 134 |
} |
| 135 |
|
| 136 |
if ($port_type ne 'W32' && eval { symlink("",""); 1 }) { |
| 137 |
|
| 138 |
# TEST #6: check for wildcards matching directories |
| 139 |
# See SV 53465 |
| 140 |
|
| 141 |
my $dir = '__rdir'; |
| 142 |
my $lnk = '__ldir'; |
| 143 |
mkdir($dir, 0777); |
| 144 |
symlink($dir, $lnk); |
| 145 |
|
| 146 |
run_make_test(qq!all: ; \@echo \$(wildcard $lnk*/.)!, '', "$lnk/."); |
| 147 |
|
| 148 |
unlink($lnk); |
| 149 |
rmdir($dir); |
| 150 |
|
| 151 |
# Test for dangling symlinks |
| 152 |
# This doesn't work with the built-in glob... needs to be updated! |
| 153 |
|
| 154 |
if (get_config('USE_SYSTEM_GLOB') eq 'yes') { |
| 155 |
symlink($dir, $lnk); |
| 156 |
|
| 157 |
run_make_test(qq!all: ; \@echo \$(wildcard $lnk)!, '', "$lnk"); |
| 158 |
|
| 159 |
unlink($lnk); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
1; |