summaryrefslogtreecommitdiff
path: root/tests/scripts/functions/wildcard
blob: f01f574a97ab626d0b1a2123a8f931f535144cdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#                                                                    -*-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");

# TEST #7: verify that when the input pattern has a trailing slash wildcard
# returns only directories.
#
# Currently this doesn't work with our embedded GLOB so disable it.
# -------

if (get_config('USE_SYSTEM_GLOB') eq 'yes') {
  touch("hellof");
  mkdir("hellod", 0770);
  mkdir("hellod/worldd", 0770);
  touch("hellod/worldf");
  mkdir("hellod/worldd/kend1", 0770);
  mkdir("hellod/worldd/kend2", 0770);
  touch("hellod/worldd/kenf1");
  touch("hellod/worldd/kenf2");

  run_make_test(qq!
print3:
\t\@echo \$(wildcard hello*)
\t\@echo \$(wildcard hello*/)
\t\@echo \$(wildcard hellod/world*)
\t\@echo \$(wildcard hellod/world*/)
\t\@echo \$(wildcard hello* hellod/world*)
\t\@echo \$(wildcard hello*/ hellod/world*/)
\t\@echo \$(wildcard hellod/*)
\t\@echo \$(wildcard hellod/*/)
\t\@echo \$(wildcard */world*)
\t\@echo \$(wildcard */worldd/)
\t\@echo \$(wildcard hellod/*/ken*/)
\t\@echo \$(wildcard hellod/*/ken?[12])
\t\@echo \$(wildcard hellod/*/ken?[12]/)
!, '',
                "hellod hellof\n"
                ."hellod/\n"
                ."hellod/worldd hellod/worldf\n"
                ."hellod/worldd/\n"
                ."hellod hellof hellod/worldd hellod/worldf\n"
                ."hellod/ hellod/worldd/\n"
                ."hellod/worldd hellod/worldf\n"
                ."hellod/worldd/\n"
                ."hellod/worldd hellod/worldf\n"
                ."hellod/worldd/\n"
                ."hellod/worldd/kend1/ hellod/worldd/kend2/\n"
                ."hellod/worldd/kend1 hellod/worldd/kend2 "
                ."hellod/worldd/kenf1 hellod/worldd/kenf2\n"
                ."hellod/worldd/kend1/ hellod/worldd/kend2/\n");

  unlink('hellof', 'hellod/worldf', 'hellod/worldd/kenf1',
         'hellod/worldd/kenf2');
  foreach $d ('hellod/worldd/kend1', 'hellod/worldd/kend2', 'hellod/worldd',
              'hellod') {
    rmdir($d);
  }
}

if ($port_type ne 'W32') {
  # Check wildcard on the root directory
  run_make_test('print4: ; @echo $(wildcard /)', '', "/\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
  # This doesn't work with the built-in glob... needs to be updated!

  if (get_config('USE_SYSTEM_GLOB') eq 'yes') {
    symlink($dir, $lnk);

    run_make_test(qq!all: ; \@echo \$(wildcard $lnk)!, '', "$lnk");

    unlink($lnk);
  }
}

1;