Skip to content

Commit b58eac4

Browse files
committed
s
1 parent 35d4403 commit b58eac4

1 file changed

Lines changed: 39 additions & 21 deletions

File tree

test/cli/testutils.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
190190

191191
builddir_tmp = None
192192

193-
# TODO: add verify mode and run it twice and compre the results
194193
if 'TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ:
195194
found_builddir = False
196195
for arg in args:
@@ -215,6 +214,22 @@ def run_cppcheck():
215214

216215
return_code, stdout, stderr = run_cppcheck()
217216

217+
def remove_checkers_msg(msgs):
218+
if msgs.find('[checkersReport]\n') > 0:
219+
start_id = msgs.find('[checkersReport]\n')
220+
start_line = msgs.rfind('\n', 0, start_id)
221+
if start_line <= 0:
222+
msgs = ''
223+
else:
224+
msgs = msgs[:start_line + 1]
225+
elif msgs.find(': (information) Active checkers: ') >= 0:
226+
pos = msgs.find(': (information) Active checkers: ')
227+
if pos == 0:
228+
msgs = ''
229+
elif msgs[pos - 1] == '\n':
230+
msgs = msgs[:pos]
231+
return msgs
232+
218233
if builddir_tmp:
219234
# run it again with the generated cache and make sure the output is identical
220235

@@ -230,19 +245,33 @@ def get_cache_contents():
230245
cache_content = get_cache_contents()
231246

232247
return_code_1, stdout_1, stderr_1 = run_cppcheck()
248+
249+
# TODO: the following asserts do not show a diff when the test fails
250+
# this can apparently by fixed by using register_assert_rewrite() but I have no idea how
233251

234252
assert return_code == return_code_1
235-
print(stdout)
236-
print(stdout_1)
253+
237254
stdout_lines = stdout.splitlines()
255+
stdout_1_lines = stdout_1.splitlines()
256+
print('stdout - expected')
257+
print(stdout_lines)
258+
print('stdout - actual')
259+
print(stdout_1_lines)
238260
# strip some common output only seen during analysis
239261
stdout_lines = [entry for entry in stdout_lines if not entry.startswith('Processing rule: ')]
240262
stdout_lines = [entry for entry in stdout_lines if not entry.startswith('progress: ')]
241-
assert stdout_lines == stdout_1.splitlines()
242-
print(stderr)
243-
print(stderr_1)
244-
assert stderr == stderr_1
245-
#register_assert_rewrite
263+
# TODO: no messages for checked configurations when using cached data
264+
assert stdout_lines == stdout_1_lines
265+
266+
stderr_lines = stderr.splitlines()
267+
stderr_1_lines = stderr_1.splitlines()
268+
print('stderr - expected')
269+
print(stderr_lines)
270+
print('stderr - actual')
271+
print(stderr_1_lines)
272+
stderr_lines = remove_checkers_msg(stderr).splitlines()
273+
stderr_1_lines = remove_checkers_msg(stderr_1).splitlines()
274+
assert stderr_lines == stderr_1_lines
246275

247276
cache_content_1 = get_cache_contents()
248277

@@ -252,19 +281,8 @@ def get_cache_contents():
252281
builddir_tmp.cleanup()
253282

254283
if remove_checkers_report:
255-
if stderr.find('[checkersReport]\n') > 0:
256-
start_id = stderr.find('[checkersReport]\n')
257-
start_line = stderr.rfind('\n', 0, start_id)
258-
if start_line <= 0:
259-
stderr = ''
260-
else:
261-
stderr = stderr[:start_line + 1]
262-
elif stderr.find(': (information) Active checkers: ') >= 0:
263-
pos = stderr.find(': (information) Active checkers: ')
264-
if pos == 0:
265-
stderr = ''
266-
elif stderr[pos - 1] == '\n':
267-
stderr = stderr[:pos]
284+
stderr = remove_checkers_msg(stderr)
285+
268286
return return_code, stdout, stderr, exe
269287

270288

0 commit comments

Comments
 (0)