Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 205 lines (171 sloc) 5.877 kb
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
1 /*
2 * Cppcheck - A tool for static C/C++ code analysis
ff11ba9 @danmar Updated copyright year to 2015
authored
3 * Copyright (C) 2007-2015 Daniel Marjamäki and Cppcheck team.
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
3fc0d0f @kimmov Run dmake to update Makefile.
kimmov authored
19 #include <string>
20 #include <vector>
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
21 #include "testsuite.h"
22 #include "pathmatch.h"
23
bc5132e Refactorization: Moved declaration of errout, ... to testsuite.h, uni…
PKEuS authored
24
6f8e42a @danmar changed the astyle formatting flags
authored
25 class TestPathMatch : public TestFixture {
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
26 public:
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
27 TestPathMatch()
28 : TestFixture("TestPathMatch")
29 , emptyMatcher(std::vector<std::string>())
30 , srcMatcher(std::vector<std::string>(1, "src/"))
31 , fooCppMatcher(std::vector<std::string>(1, "foo.cpp"))
051d42a @danmar astyle formatting
authored
32 , srcFooCppMatcher(std::vector<std::string>(1, "src/foo.cpp")) {
a9a5dc0 @PKEuS Updated to AStyle 2.03, require this version
PKEuS authored
33 }
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
34
35 private:
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
36 const PathMatch emptyMatcher;
37 const PathMatch srcMatcher;
38 const PathMatch fooCppMatcher;
39 const PathMatch srcFooCppMatcher;
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
40
051d42a @danmar astyle formatting
authored
41 void run() {
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
42 TEST_CASE(emptymaskemptyfile);
43 TEST_CASE(emptymaskpath1);
44 TEST_CASE(emptymaskpath2);
45 TEST_CASE(emptymaskpath3);
46 TEST_CASE(onemaskemptypath);
47 TEST_CASE(onemasksamepath);
4ef4cb2 @kimmov CLI: Add support for ignoring case in PathMatch.
kimmov authored
48 TEST_CASE(onemasksamepathdifferentcase);
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
49 TEST_CASE(onemasksamepathwithfile);
f65fa33 @kimmov Tighten the directory name mathing with -i.
kimmov authored
50 TEST_CASE(onemaskdifferentdir1);
51 TEST_CASE(onemaskdifferentdir2);
52 TEST_CASE(onemaskdifferentdir3);
53 TEST_CASE(onemaskdifferentdir4);
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
54 TEST_CASE(onemasklongerpath1);
55 TEST_CASE(onemasklongerpath2);
56 TEST_CASE(onemasklongerpath3);
e5427fe @PKEuS Fixed #3048, further improvements to const correctness check.
PKEuS authored
57 TEST_CASE(twomasklongerpath1);
58 TEST_CASE(twomasklongerpath2);
59 TEST_CASE(twomasklongerpath3);
60 TEST_CASE(twomasklongerpath4);
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
61 TEST_CASE(filemask1);
4ef4cb2 @kimmov CLI: Add support for ignoring case in PathMatch.
kimmov authored
62 TEST_CASE(filemaskdifferentcase);
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
63 TEST_CASE(filemask2);
64 TEST_CASE(filemask3);
65 TEST_CASE(filemaskpath1);
66 TEST_CASE(filemaskpath2);
67 TEST_CASE(filemaskpath3);
68 TEST_CASE(filemaskpath4);
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
69 }
70
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
71 // Test empty PathMatch
051d42a @danmar astyle formatting
authored
72 void emptymaskemptyfile() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
73 ASSERT(!emptyMatcher.Match(""));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
74 }
75
051d42a @danmar astyle formatting
authored
76 void emptymaskpath1() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
77 ASSERT(!emptyMatcher.Match("src/"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
78 }
79
051d42a @danmar astyle formatting
authored
80 void emptymaskpath2() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
81 ASSERT(!emptyMatcher.Match("../src/"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
82 }
83
051d42a @danmar astyle formatting
authored
84 void emptymaskpath3() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
85 ASSERT(!emptyMatcher.Match("/home/user/code/src/"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
86 }
87
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
88 // Test PathMatch containing "src/"
051d42a @danmar astyle formatting
authored
89 void onemaskemptypath() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
90 ASSERT(!srcMatcher.Match(""));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
91 }
92
051d42a @danmar astyle formatting
authored
93 void onemasksamepath() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
94 ASSERT(srcMatcher.Match("src/"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
95 }
96
051d42a @danmar astyle formatting
authored
97 void onemasksamepathdifferentcase() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
98 std::vector<std::string> masks(1, "sRc/");
9f42ce9 @PKEuS Refactored STL container usage in CLI.
PKEuS authored
99 PathMatch match(masks, false);
100 ASSERT(match.Match("srC/"));
4ef4cb2 @kimmov CLI: Add support for ignoring case in PathMatch.
kimmov authored
101 }
102
051d42a @danmar astyle formatting
authored
103 void onemasksamepathwithfile() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
104 ASSERT(srcMatcher.Match("src/file.txt"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
105 }
106
051d42a @danmar astyle formatting
authored
107 void onemaskdifferentdir1() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
108 ASSERT(!srcMatcher.Match("srcfiles/file.txt"));
f65fa33 @kimmov Tighten the directory name mathing with -i.
kimmov authored
109 }
110
051d42a @danmar astyle formatting
authored
111 void onemaskdifferentdir2() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
112 ASSERT(!srcMatcher.Match("proj/srcfiles/file.txt"));
f65fa33 @kimmov Tighten the directory name mathing with -i.
kimmov authored
113 }
114
051d42a @danmar astyle formatting
authored
115 void onemaskdifferentdir3() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
116 ASSERT(!srcMatcher.Match("proj/mysrc/file.txt"));
f65fa33 @kimmov Tighten the directory name mathing with -i.
kimmov authored
117 }
118
051d42a @danmar astyle formatting
authored
119 void onemaskdifferentdir4() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
120 ASSERT(!srcMatcher.Match("proj/mysrcfiles/file.txt"));
f65fa33 @kimmov Tighten the directory name mathing with -i.
kimmov authored
121 }
122
051d42a @danmar astyle formatting
authored
123 void onemasklongerpath1() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
124 ASSERT(srcMatcher.Match("/tmp/src/"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
125 }
126
051d42a @danmar astyle formatting
authored
127 void onemasklongerpath2() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
128 ASSERT(srcMatcher.Match("src/module/"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
129 }
130
051d42a @danmar astyle formatting
authored
131 void onemasklongerpath3() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
132 ASSERT(srcMatcher.Match("project/src/module/"));
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
133 }
134
051d42a @danmar astyle formatting
authored
135 void twomasklongerpath1() const {
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
136 std::vector<std::string> masks;
137 masks.push_back("src/");
138 masks.push_back("module/");
139 PathMatch match(masks);
140 ASSERT(!match.Match("project/"));
141 }
142
051d42a @danmar astyle formatting
authored
143 void twomasklongerpath2() const {
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
144 std::vector<std::string> masks;
145 masks.push_back("src/");
146 masks.push_back("module/");
147 PathMatch match(masks);
148 ASSERT(match.Match("project/src/"));
149 }
150
051d42a @danmar astyle formatting
authored
151 void twomasklongerpath3() const {
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
152 std::vector<std::string> masks;
153 masks.push_back("src/");
154 masks.push_back("module/");
155 PathMatch match(masks);
156 ASSERT(match.Match("project/module/"));
157 }
158
051d42a @danmar astyle formatting
authored
159 void twomasklongerpath4() const {
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
160 std::vector<std::string> masks;
161 masks.push_back("src/");
162 masks.push_back("module/");
163 PathMatch match(masks);
164 ASSERT(match.Match("project/src/module/"));
165 }
166
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
167 // Test PathMatch containing "foo.cpp"
051d42a @danmar astyle formatting
authored
168 void filemask1() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
169 ASSERT(fooCppMatcher.Match("foo.cpp"));
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
170 }
171
051d42a @danmar astyle formatting
authored
172 void filemaskdifferentcase() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
173 std::vector<std::string> masks(1, "foo.cPp");
9f42ce9 @PKEuS Refactored STL container usage in CLI.
PKEuS authored
174 PathMatch match(masks, false);
175 ASSERT(match.Match("fOo.cpp"));
4ef4cb2 @kimmov CLI: Add support for ignoring case in PathMatch.
kimmov authored
176 }
177
051d42a @danmar astyle formatting
authored
178 void filemask2() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
179 ASSERT(fooCppMatcher.Match("../foo.cpp"));
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
180 }
181
051d42a @danmar astyle formatting
authored
182 void filemask3() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
183 ASSERT(fooCppMatcher.Match("src/foo.cpp"));
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
184 }
185
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
186 // Test PathMatch containing "src/foo.cpp"
051d42a @danmar astyle formatting
authored
187 void filemaskpath1() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
188 ASSERT(srcFooCppMatcher.Match("src/foo.cpp"));
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
189 }
190
051d42a @danmar astyle formatting
authored
191 void filemaskpath2() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
192 ASSERT(srcFooCppMatcher.Match("proj/src/foo.cpp"));
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
193 }
194
051d42a @danmar astyle formatting
authored
195 void filemaskpath3() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
196 ASSERT(!srcFooCppMatcher.Match("foo.cpp"));
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
197 }
198
051d42a @danmar astyle formatting
authored
199 void filemaskpath4() const {
36dba83 @PKEuS Reuse constant objects in testpathmatch.cpp, small simplification in …
PKEuS authored
200 ASSERT(!srcFooCppMatcher.Match("bar/foo.cpp"));
2d6d858 @kimmov Allow to exclude filenames (with paths).
kimmov authored
201 }
6401271 @kimmov Add CLI support for ignoring paths.
kimmov authored
202 };
203
204 REGISTER_TEST(TestPathMatch)
Something went wrong with that request. Please try again.