@@ -2028,81 +2028,98 @@ def test_checkers_report_misra_json(tmpdir):
2028
2028
assert '<checker id="Misra C 2012: 8.1"/>' in stderr
2029
2029
2030
2030
2031
- def test_ignore (tmpdir ):
2031
+ def __test_ignore_file (tmpdir , ign , append = False , inject_path = False ):
2032
2032
os .mkdir (os .path .join (tmpdir , 'src' ))
2033
2033
test_file = os .path .join (tmpdir , 'src' , 'test.cpp' )
2034
2034
with open (test_file , 'wt' ):
2035
2035
pass
2036
2036
2037
2037
# TODO: this should say that all paths are ignored
2038
2038
lines_exp = [
2039
+ 'ignored path: {}' .format (test_file ),
2039
2040
'cppcheck: error: could not find or open any of the paths given.' ,
2040
2041
'cppcheck: Maybe all paths were ignored?'
2041
2042
]
2042
2043
2043
2044
args = [
2044
- '-itest.cpp ' ,
2045
+ '--debug-ignore ' ,
2045
2046
test_file
2046
2047
]
2047
2048
2048
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2049
- assert exitcode == 1 , stdout
2050
- assert stdout .splitlines () == lines_exp
2049
+ if inject_path :
2050
+ ign = ign .replace ('$path' , str (test_file ))
2051
2051
2052
- # make sure it also matches when specified after the file
2053
- args = [
2054
- test_file ,
2055
- '-itest.cpp'
2056
- ]
2052
+ if append :
2053
+ args += ['-i{}' .format (ign )]
2054
+ else :
2055
+ args = ['-i{}' .format (ign )] + args
2057
2056
2058
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2059
- assert exitcode == 1 , stdout
2057
+ exitcode , stdout , stderr = cppcheck (args , cwd = tmpdir )
2058
+ assert exitcode == 1 , stdout if stdout else stderr
2060
2059
assert stdout .splitlines () == lines_exp
2061
2060
2062
- args = [
2063
- '-isrc/test.cpp' ,
2064
- test_file
2065
- ]
2066
2061
2067
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2068
- assert exitcode == 1 , stdout
2069
- assert stdout .splitlines () == lines_exp
2062
+ def test_ignore_file (tmpdir ):
2063
+ __test_ignore_file (tmpdir , 'test.cpp' )
2070
2064
2071
- args = [
2072
- '-isrc\\ test.cpp' ,
2073
- test_file
2074
- ]
2075
2065
2076
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2077
- assert exitcode == 1 , stdout
2078
- assert stdout .splitlines () == lines_exp
2066
+ def test_ignore_file_append (tmpdir ):
2067
+ __test_ignore_file (tmpdir , 'test.cpp' , append = True )
2079
2068
2080
- args = [
2081
- '-isrc/' ,
2082
- test_file
2083
- ]
2084
2069
2085
- exitcode , stdout , _ = cppcheck ( args , cwd = tmpdir )
2086
- assert exitcode == 1 , stdout
2087
- assert stdout . splitlines () == lines_exp
2070
+ @ pytest . mark . xfail ( strict = True ) # TODO: glob syntax is not supported?
2071
+ def test_ignore_file_wildcard_back ( tmpdir ):
2072
+ __test_ignore_file ( tmpdir , 'test.c*' )
2088
2073
2089
- args = [
2090
- '-isrc\\ ' ,
2091
- test_file
2092
- ]
2093
2074
2094
- exitcode , stdout , _ = cppcheck ( args , cwd = tmpdir )
2095
- assert exitcode == 1 , stdout
2096
- assert stdout . splitlines () == lines_exp
2075
+ @ pytest . mark . xfail ( strict = True ) # TODO: glob syntax is not supported?
2076
+ def test_ignore_file_wildcard_front ( tmpdir ):
2077
+ __test_ignore_file ( tmpdir , '*test.cpp' )
2097
2078
2098
- args = [
2099
- '-i{}' .format (test_file ),
2100
- test_file
2101
- ]
2102
2079
2103
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2104
- assert exitcode == 1 , stdout
2105
- assert stdout .splitlines () == lines_exp
2080
+ @pytest .mark .xfail (strict = True ) # TODO: glob syntax is not supported?
2081
+ def test_ignore_file_placeholder (tmpdir ):
2082
+ __test_ignore_file (tmpdir , 't?st.cpp' )
2083
+
2084
+
2085
+ def test_ignore_file_relative (tmpdir ):
2086
+ __test_ignore_file (tmpdir , 'src/test.cpp' )
2087
+
2088
+
2089
+ def test_ignore_file_relative_backslash (tmpdir ):
2090
+ __test_ignore_file (tmpdir , 'src\\ test.cpp' )
2091
+
2092
+
2093
+ @pytest .mark .xfail (strict = True ) # TODO: glob syntax is not supported?
2094
+ def test_ignore_file_relative_wildcard (tmpdir ):
2095
+ __test_ignore_file (tmpdir , 'src/test.c*' )
2096
+
2097
+
2098
+ @pytest .mark .xfail (strict = True ) # TODO: glob syntax is not supported?
2099
+ def test_ignore_file_relative_wildcard_backslash (tmpdir ):
2100
+ __test_ignore_file (tmpdir , 'src\\ test.c*' )
2101
+
2102
+
2103
+ def test_ignore_path_relative (tmpdir ):
2104
+ __test_ignore_file (tmpdir , 'src/' )
2105
+
2106
+
2107
+ def test_ignore_path_relative_backslash (tmpdir ):
2108
+ __test_ignore_file (tmpdir , 'src\\ ' )
2109
+
2110
+
2111
+ @pytest .mark .xfail (strict = True ) # TODO: glob syntax is not supported?
2112
+ def test_ignore_path_relative_wildcard (tmpdir ):
2113
+ __test_ignore_file (tmpdir , 'src*/' )
2114
+
2115
+
2116
+ @pytest .mark .xfail (strict = True ) # TODO: glob syntax is not supported?
2117
+ def test_ignore_path_relative_wildcard_backslash (tmpdir ):
2118
+ __test_ignore_file (tmpdir , 'src*\\ ' )
2119
+
2120
+
2121
+ def test_ignore_abspath (tmpdir ):
2122
+ __test_ignore_file (tmpdir , '$path' , inject_path = True )
2106
2123
2107
2124
2108
2125
def __write_gui_project (tmpdir , test_file , ignore ):
@@ -2122,92 +2139,83 @@ def __write_gui_project(tmpdir, test_file, ignore):
2122
2139
return project_file
2123
2140
2124
2141
2125
- def test_ignore_project (tmpdir ):
2142
+ def __test_ignore_project (tmpdir , ign_proj , ign_cli = None , append_cli = False , inject_path_proj = False ):
2126
2143
os .mkdir (os .path .join (tmpdir , 'src' ))
2127
2144
test_file = os .path .join (tmpdir , 'src' , 'test.cpp' )
2128
2145
with open (test_file , 'wt' ):
2129
2146
pass
2130
2147
2148
+ # TODO: this should say that all paths were ignored
2131
2149
lines_exp = [
2150
+ 'ignored path: {}' .format (test_file ),
2132
2151
'cppcheck: error: could not find or open any of the paths given.' ,
2133
2152
'cppcheck: Maybe all paths were ignored?'
2134
2153
]
2135
2154
2136
- project_file = __write_gui_project (tmpdir , test_file , 'test.cpp' )
2155
+ if inject_path_proj :
2156
+ ign_proj = ign_proj .replace ('$path' , str (test_file ))
2157
+
2158
+ project_file = __write_gui_project (tmpdir , test_file , ign_proj )
2137
2159
args = [
2160
+ '--debug-ignore' ,
2138
2161
'--project={}' .format (project_file )
2139
2162
]
2140
2163
2164
+ if append_cli :
2165
+ args += ['-i{}' .format (ign_cli )]
2166
+ else :
2167
+ args = ['-i{}' .format (ign_cli )] + args
2168
+
2141
2169
exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2142
2170
assert exitcode == 1 , stdout
2143
2171
assert stdout .splitlines () == lines_exp
2144
2172
2145
- # make sure -i works when specified before project
2146
- project_file = __write_gui_project (tmpdir , test_file , 'test2.cpp' )
2147
- args = [
2148
- '-itest.cpp' ,
2149
- '--project={}' .format (project_file )
2150
- ]
2151
2173
2152
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2153
- assert exitcode == 1 , stdout
2154
- assert stdout .splitlines () == lines_exp
2174
+ def test_ignore_project_file (tmpdir ):
2175
+ __test_ignore_project (tmpdir , 'test.cpp' )
2155
2176
2156
- # make sure -i works when specified after project
2157
- project_file = __write_gui_project (tmpdir , test_file , 'test2.cpp' )
2158
- args = [
2159
- '--project={}' .format (project_file ),
2160
- '-itest.cpp'
2161
- ]
2162
2177
2163
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2164
- assert exitcode == 1 , stdout
2165
- assert stdout .splitlines () == lines_exp
2178
+ def test_ignore_project_file_cli_prepend (tmpdir ):
2179
+ __test_ignore_project (tmpdir , ign_proj = 'test2.cpp' , ign_cli = 'test.cpp' )
2166
2180
2167
- project_file = __write_gui_project (tmpdir , test_file , 'src/test.cpp' )
2168
- args = [
2169
- '--project={}' .format (project_file )
2170
- ]
2171
2181
2172
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2173
- assert exitcode == 1 , stdout
2174
- assert stdout .splitlines () == lines_exp
2182
+ def test_ignore_project_file_cli_append (tmpdir ):
2183
+ __test_ignore_project (tmpdir , ign_proj = 'test2.cpp' , ign_cli = 'test.cpp' , append_cli = True )
2175
2184
2176
- project_file = __write_gui_project (tmpdir , test_file , 'src\\ test.cpp' )
2177
- args = [
2178
- '--project={}' .format (project_file )
2179
- ]
2180
2185
2181
- exitcode , stdout , _ = cppcheck ( args , cwd = tmpdir )
2182
- assert exitcode == 1 , stdout
2183
- assert stdout . splitlines () == lines_exp
2186
+ @ pytest . mark . xfail ( strict = True ) # TODO: ?
2187
+ def test_ignore_project_file_wildcard_back ( tmpdir ):
2188
+ __test_ignore_project ( tmpdir , 'test.c*' )
2184
2189
2185
- project_file = __write_gui_project (tmpdir , test_file , 'src/' )
2186
- args = [
2187
- '--project={}' .format (project_file )
2188
- ]
2189
2190
2190
- exitcode , stdout , _ = cppcheck ( args , cwd = tmpdir )
2191
- assert exitcode == 1 , stdout
2192
- assert stdout . splitlines () == lines_exp
2191
+ @ pytest . mark . xfail ( strict = True ) # TODO: ?
2192
+ def test_ignore_project_file_wildcard_front ( tmpdir ):
2193
+ __test_ignore_project ( tmpdir , '*test.cpp' )
2193
2194
2194
- project_file = __write_gui_project (tmpdir , test_file , 'src\\ ' )
2195
- args = [
2196
- '--project={}' .format (project_file )
2197
- ]
2198
2195
2199
- exitcode , stdout , _ = cppcheck ( args , cwd = tmpdir )
2200
- assert exitcode == 1 , stdout
2201
- assert stdout . splitlines () == lines_exp
2196
+ @ pytest . mark . xfail ( strict = True ) # TODO: ?
2197
+ def test_ignore_project_file_placeholder ( tmpdir ):
2198
+ __test_ignore_project ( tmpdir , 't?st.cpp' )
2202
2199
2203
- project_file = __write_gui_project (tmpdir , test_file , test_file )
2204
- args = [
2205
- '--project={}' .format (project_file )
2206
- ]
2207
2200
2208
- exitcode , stdout , _ = cppcheck (args , cwd = tmpdir )
2209
- assert exitcode == 1 , stdout
2210
- assert stdout .splitlines () == lines_exp
2201
+ def test_ignore_project_file_relative (tmpdir ):
2202
+ __test_ignore_project (tmpdir , 'src/test.cpp' )
2203
+
2204
+
2205
+ def test_ignore_project_file_relative_backslash (tmpdir ):
2206
+ __test_ignore_project (tmpdir , 'src\\ test.cpp' )
2207
+
2208
+
2209
+ def test_ignore_project_path_relative (tmpdir ):
2210
+ __test_ignore_project (tmpdir , 'src/' )
2211
+
2212
+
2213
+ def test_ignore_project_path_relative_backslash (tmpdir ):
2214
+ __test_ignore_project (tmpdir , 'src\\ ' )
2215
+
2216
+
2217
+ def test_ignore_project_abspath (tmpdir ):
2218
+ __test_ignore_project (tmpdir , '$path' , inject_path_proj = True )
2211
2219
2212
2220
2213
2221
def __write_compdb (tmpdir , test_file ):
@@ -2231,12 +2239,13 @@ def __test_ignore_project_2(tmpdir, extra_args, append=False, inject_path=False)
2231
2239
pass
2232
2240
2233
2241
lines_exp = [
2242
+ 'ignored path: {}' .format (str (test_file ).replace ('\\ ' , '/' )),
2234
2243
'cppcheck: error: no C or C++ source files found.' ,
2235
2244
'cppcheck: all paths were ignored'
2236
2245
]
2237
2246
project_file = __write_compdb (tmpdir , test_file )
2238
2247
args = [
2239
- '-q ' ,
2248
+ '--debug-ignore ' ,
2240
2249
'--project={}' .format (project_file )
2241
2250
]
2242
2251
@@ -2264,6 +2273,20 @@ def test_ignore_project_2_file_append(tmpdir):
2264
2273
__test_ignore_project_2 (tmpdir , ['-itest.cpp' ], append = True )
2265
2274
2266
2275
2276
+ @pytest .mark .xfail (strict = True ) # TODO: PathMatch lacks wildcard support / -i appears to be ignored
2277
+ def test_ignore_project_2_file_wildcard_back (tmpdir ):
2278
+ __test_ignore_project_2 (tmpdir , ['-itest.c*' ])
2279
+
2280
+
2281
+ def test_ignore_project_2_file_wildcard_front (tmpdir ):
2282
+ __test_ignore_project_2 (tmpdir , ['-i*test.cpp' ])
2283
+
2284
+
2285
+ @pytest .mark .xfail (strict = True ) # TODO: PathMatch lacks wildcard support / -i appears to be ignored
2286
+ def test_ignore_project_2_file_placeholder (tmpdir ):
2287
+ __test_ignore_project_2 (tmpdir , ['-it?st.cpp' ])
2288
+
2289
+
2267
2290
@pytest .mark .xfail (strict = True ) # TODO: -i appears to be ignored
2268
2291
def test_ignore_project_2_file_relative (tmpdir ):
2269
2292
__test_ignore_project_2 (tmpdir , ['-isrc/test.cpp' ])
@@ -2274,6 +2297,16 @@ def test_ignore_project_2_file_relative_backslash(tmpdir):
2274
2297
__test_ignore_project_2 (tmpdir , ['-isrc\\ test.cpp' ])
2275
2298
2276
2299
2300
+ @pytest .mark .xfail (strict = True ) # TODO: PathMatch lacks wildcard support / -i appears to be ignored
2301
+ def test_ignore_project_2_file_relative_wildcard (tmpdir ):
2302
+ __test_ignore_project_2 (tmpdir , ['-isrc/test.c*' ])
2303
+
2304
+
2305
+ @pytest .mark .xfail (strict = True ) # TODO: PathMatch lacks wildcard support / -i appears to be ignored
2306
+ def test_ignore_project_2_file_relative_wildcard_backslash (tmpdir ):
2307
+ __test_ignore_project_2 (tmpdir , ['-isrc\\ test.c*' ])
2308
+
2309
+
2277
2310
def test_ignore_project_2_path_relative (tmpdir ):
2278
2311
__test_ignore_project_2 (tmpdir , ['-isrc/' ])
2279
2312
@@ -2282,6 +2315,16 @@ def test_ignore_project_2_path_relative_backslash(tmpdir):
2282
2315
__test_ignore_project_2 (tmpdir , ['-isrc\\ ' ])
2283
2316
2284
2317
2318
+ @pytest .mark .xfail (strict = True ) # TODO: PathMatch lacks wildcard support
2319
+ def test_ignore_project_2_path_relative_wildcard (tmpdir ):
2320
+ __test_ignore_project_2 (tmpdir , ['-isrc*/' ])
2321
+
2322
+
2323
+ @pytest .mark .xfail (strict = True ) # TODO: PathMatch lacks wildcard support
2324
+ def test_ignore_project_2_path_relative_wildcard_backslash (tmpdir ):
2325
+ __test_ignore_project_2 (tmpdir , ['-isrc*\\ ' ])
2326
+
2327
+
2285
2328
def test_ignore_project_2_abspath (tmpdir ):
2286
2329
__test_ignore_project_2 (tmpdir , ['-i$path' ], inject_path = True )
2287
2330
0 commit comments