@@ -30,6 +30,8 @@ class TestPathMatch : public TestFixture {
3030private:
3131 static constexpr auto unix = PathMatch::Syntax::unix;
3232 static constexpr auto windows = PathMatch::Syntax::windows;
33+ static constexpr auto ifreg = PathMatch::Filemode::regular;
34+ static constexpr auto ifdir = PathMatch::Filemode::directory;
3335#ifdef _WIN32
3436 const std::string basepath{" C:\\ test" };
3537#else
@@ -73,7 +75,8 @@ class TestPathMatch : public TestFixture {
7375 TEST_CASE (filemaskpath3);
7476 TEST_CASE (filemaskpath4);
7577 TEST_CASE (mixedallmatch);
76- TEST_CASE (glob);
78+ TEST_CASE (glob1);
79+ TEST_CASE (glob2);
7780 TEST_CASE (globstar1);
7881 TEST_CASE (globstar2);
7982 TEST_CASE (pathiterator);
@@ -85,16 +88,16 @@ class TestPathMatch : public TestFixture {
8588 }
8689
8790 void emptymaskpath1 () const {
88- ASSERT (!emptyMatcher.match (" src/" ));
91+ ASSERT (!emptyMatcher.match (" src/" , ifdir ));
8992 }
9093
9194 void emptymaskpath2 () const {
92- ASSERT (!emptyMatcher.match (" ../src/" ));
95+ ASSERT (!emptyMatcher.match (" ../src/" , ifdir ));
9396 }
9497
9598 void emptymaskpath3 () const {
96- ASSERT (!emptyMatcher.match (" /home/user/code/src/" ));
97- ASSERT (!emptyMatcher.match (" d:/home/user/code/src/" ));
99+ ASSERT (!emptyMatcher.match (" /home/user/code/src/" , ifdir ));
100+ ASSERT (!emptyMatcher.match (" d:/home/user/code/src/" , ifdir ));
98101 }
99102
100103 // Test PathMatch containing "src/"
@@ -103,17 +106,20 @@ class TestPathMatch : public TestFixture {
103106 }
104107
105108 void onemasksamepath () const {
106- ASSERT (srcMatcher.match (" src/" ));
109+ ASSERT (srcMatcher.match (" src/" , ifdir));
110+ ASSERT (!srcMatcher.match (" src/" , ifreg));
107111 }
108112
109113 void onemasksamepathdifferentslash () const {
110114 PathMatch srcMatcher2 ({" src\\ " }, basepath, windows);
111- ASSERT (srcMatcher2.match (" src/" ));
115+ ASSERT (srcMatcher2.match (" src/" , ifdir));
116+ ASSERT (!srcMatcher2.match (" src/" , ifreg));
112117 }
113118
114119 void onemasksamepathdifferentcase () const {
115120 PathMatch match ({" sRc/" }, basepath, windows);
116- ASSERT (match.match (" srC/" ));
121+ ASSERT (match.match (" srC/" , ifdir));
122+ ASSERT (!match.match (" srC/" , ifreg));
117123 }
118124
119125 void onemasksamepathwithfile () const {
@@ -125,8 +131,8 @@ class TestPathMatch : public TestFixture {
125131 const std::string shorterToMatch (" src/" );
126132 ASSERT (shorterToMatch.length () < longerExclude.length ());
127133 PathMatch match ({longerExclude});
128- ASSERT (match.match (longerExclude));
129- ASSERT (!match.match (shorterToMatch));
134+ ASSERT (match.match (longerExclude, ifdir ));
135+ ASSERT (!match.match (shorterToMatch, ifdir ));
130136 }
131137
132138 void onemaskdifferentdir1 () const {
@@ -146,40 +152,43 @@ class TestPathMatch : public TestFixture {
146152 }
147153
148154 void onemasklongerpath1 () const {
149- ASSERT (srcMatcher.match (" /tmp/src/" ));
150- ASSERT (srcMatcher.match (" d:/tmp/src/" ));
155+ ASSERT (srcMatcher.match (" /tmp/src/" , ifdir ));
156+ ASSERT (srcMatcher.match (" d:/tmp/src/" , ifdir ));
151157 }
152158
153159 void onemasklongerpath2 () const {
154- ASSERT (srcMatcher.match (" src/module/" ));
160+ ASSERT (srcMatcher.match (" src/module/" , ifdir ));
155161 }
156162
157163 void onemasklongerpath3 () const {
158- ASSERT (srcMatcher.match (" project/src/module/" ));
164+ ASSERT (srcMatcher.match (" project/src/module/" , ifdir ));
159165 }
160166
161167 void onemaskcwd () const {
162- ASSERT (srcMatcher.match (" ./src" ));
168+ ASSERT (srcMatcher.match (" ./src" , ifdir ));
163169 }
164170
165171 void twomasklongerpath1 () const {
166172 PathMatch match ({ " src/" , " module/" });
167- ASSERT (!match.match (" project/" ));
173+ ASSERT (!match.match (" project/" , ifdir ));
168174 }
169175
170176 void twomasklongerpath2 () const {
171177 PathMatch match ({ " src/" , " module/" });
172- ASSERT (match.match (" project/src/" ));
178+ ASSERT (match.match (" project/src/" , ifdir));
179+ ASSERT (!match.match (" project/src/" , ifreg));
173180 }
174181
175182 void twomasklongerpath3 () const {
176183 PathMatch match ({ " src/" , " module/" });
177- ASSERT (match.match (" project/module/" ));
184+ ASSERT (match.match (" project/module/" , ifdir));
185+ ASSERT (!match.match (" project/module/" , ifreg));
178186 }
179187
180188 void twomasklongerpath4 () const {
181189 PathMatch match ({ " src/" , " module/" });
182- ASSERT (match.match (" project/src/module/" ));
190+ ASSERT (match.match (" project/src/module/" , ifdir));
191+ ASSERT (match.match (" project/src/module/" , ifreg));
183192 }
184193
185194 // Test PathMatch containing "foo.cpp"
@@ -224,11 +233,12 @@ class TestPathMatch : public TestFixture {
224233 void mixedallmatch () const { // #13570
225234 // when trying to match a directory against a directory entry it erroneously modified a local variable also used for file matching
226235 PathMatch match ({ " tests/" , " file.c" });
227- ASSERT (match.match (" tests/" ));
236+ ASSERT (match.match (" tests/" , ifdir));
237+ ASSERT (!match.match (" tests/" , ifreg));
228238 ASSERT (match.match (" lib/file.c" ));
229239 }
230240
231- void glob () const {
241+ void glob1 () const {
232242 PathMatch match ({" test?.cpp" });
233243 ASSERT (match.match (" test1.cpp" ));
234244 ASSERT (match.match (" src/test1.cpp" ));
@@ -237,12 +247,22 @@ class TestPathMatch : public TestFixture {
237247 ASSERT (!match.match (" test.cpp" ));
238248 }
239249
250+ void glob2 () const {
251+ PathMatch match ({" test*.cpp" });
252+ ASSERT (match.match (" test1.cpp" ));
253+ ASSERT (match.match (" src/test1.cpp" ));
254+ ASSERT (match.match (" test1.cpp/src" ));
255+ ASSERT (!match.match (" test1.c" ));
256+ ASSERT (match.match (" test.cpp" ));
257+ }
258+
240259 void globstar1 () const {
241260 PathMatch match ({" src/**/foo.c" });
242261 ASSERT (match.match (" src/lib/foo/foo.c" ));
243262 ASSERT (match.match (" src/lib/foo/bar/foo.c" ));
244263 ASSERT (!match.match (" src/lib/foo/foo.cpp" ));
245264 ASSERT (!match.match (" src/lib/foo/bar/foo.cpp" ));
265+ ASSERT (!match.match (" src/foo.c" ));
246266 }
247267
248268 void globstar2 () const {
@@ -251,6 +271,7 @@ class TestPathMatch : public TestFixture {
251271 ASSERT (match.match (" src/lib/foo/bar/foo.c" ));
252272 ASSERT (!match.match (" src/lib/foo/foo.cpp" ));
253273 ASSERT (!match.match (" src/lib/foo/bar/foo.cpp" ));
274+ ASSERT (!match.match (" src/foo.c" ));
254275 }
255276
256277 void pathiterator () const {
0 commit comments