Skip to content

Commit 2c7cd3c

Browse files
committed
adjusted several Python tests to accommodate for the build dir usage [skip ci]
1 parent d33ccc6 commit 2c7cd3c

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

test/cli/helloworld_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,25 @@ def test_checkers_report(tmpdir):
290290
filename = os.path.join(tmpdir, '1.txt')
291291
args = [
292292
f'--checkers-report={filename}',
293+
'--no-cppcheck-build-dir', # TODO: remove this
293294
'helloworld'
294295
]
295296

296297
cppcheck(args, cwd=__script_dir)
297298

298299
with open(filename, 'rt') as f:
299-
data = f.read()
300-
assert 'No CheckAutoVariables::assignFunctionArg' in data
301-
assert 'Yes CheckAutoVariables::autoVariables' in data
300+
data = f.read().splitlines()
301+
assert 'No CheckAutoVariables::assignFunctionArg require:style,warning' in data, json.dumps(data, indent=4)
302+
assert 'Yes CheckAutoVariables::autoVariables' in data, json.dumps(data, indent=4)
302303

303304
args += [
304305
'--enable=style'
305306
]
306307
cppcheck(args, cwd=__script_dir)
307308
with open(filename, 'rt') as f:
308-
data = f.read()
309+
data = f.read().splitlines()
309310
# checker has been activated by --enable=style
310-
assert 'Yes CheckAutoVariables::assignFunctionArg' in data
311+
assert 'Yes CheckAutoVariables::assignFunctionArg' in data, json.dumps(data, indent=4)
311312

312313

313314
def test_missing_include_system(): # #11283

test/cli/other_test.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,6 @@ def test_unused_function_include(tmpdir):
820820
__test_unused_function_include(tmpdir, [])
821821

822822

823-
# TODO: remove when we inject builddir
824-
def test_unused_function_include_builddir(tmpdir):
825-
builddir = os.path.join(tmpdir, 'injected')
826-
os.makedirs(builddir)
827-
__test_unused_function_include(tmpdir, ['--cppcheck-build-dir={}'.format(builddir)])
828-
829-
830823
# TODO: test with all other types
831824
def test_showtime_top5_file(tmpdir):
832825
test_file = os.path.join(tmpdir, 'test.cpp')

test/cli/qml_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __test_unused_functions(extra_args):
3535

3636

3737
def test_unused_functions():
38-
__test_unused_functions(['-j1'])
38+
__test_unused_functions(['-j1', '--no-cppcheck-build-dir'])
3939

4040

4141
def test_unused_functions_j():
@@ -45,6 +45,7 @@ def test_unused_functions_j():
4545
'--library=qt',
4646
'--enable=unusedFunction',
4747
'-j2',
48+
'--no-cppcheck-build-dir',
4849
__project_dir
4950
]
5051
ret, stdout, stderr = cppcheck(args)

test/cli/whole-program_test.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,11 @@ def test_addon_rerun(tmp_path, builddir):
220220
'--enable=style',
221221
'--template={id}',
222222
'whole-program']
223+
# do not use the injection because the directory needs to survive runs
223224
if builddir:
224225
args.append('--cppcheck-build-dir=' + str(tmp_path))
226+
else:
227+
args.append('--no-cppcheck-build-dir')
225228
_, _, stderr = cppcheck(args, cwd=__script_dir)
226229
assert 'misra-c2012-5.8' in stderr
227230
_, _, stderr = cppcheck(args, cwd=__script_dir)
@@ -293,10 +296,9 @@ def test_checkclass():
293296
__test_checkclass(['-j1'])
294297

295298

296-
# whole program analysis requires a build dir with -j
297-
@pytest.mark.xfail(strict=True)
299+
@pytest.mark.xfail(strict=True) # TODO: check error
298300
def test_checkclass_j():
299-
__test_checkclass(['-j2'])
301+
__test_checkclass(['-j2', '--no-cppcheck-build-dir'])
300302

301303

302304
def test_checkclass_builddir(tmpdir):
@@ -305,6 +307,11 @@ def test_checkclass_builddir(tmpdir):
305307
__test_checkclass(['--cppcheck-build-dir={}'.format(build_dir)])
306308

307309

310+
def test_checkclass_builddir_j(tmpdir):
311+
build_dir = os.path.join(tmpdir, 'b1')
312+
os.mkdir(build_dir)
313+
__test_checkclass(['-j2', '--cppcheck-build-dir={}'.format(build_dir)])
314+
308315
def __test_checkclass_project(tmpdir, extra_args):
309316
odr_file_1 = os.path.join(__script_dir, 'whole-program', 'odr1.cpp')
310317

@@ -336,14 +343,18 @@ def test_checkclass_project(tmpdir):
336343
__test_checkclass_project(tmpdir, ['-j1'])
337344

338345

339-
# whole program analysis requires a build dir with -j
340-
@pytest.mark.xfail(strict=True)
346+
@pytest.mark.xfail(strict=True) # TODO: check error
341347
def test_checkclass_project_j(tmpdir):
342-
__test_checkclass_project(tmpdir, ['-j2'])
348+
__test_checkclass_project(tmpdir, ['-j2', '--no-cppcheck-build-dir'])
343349

344350

345351
def test_checkclass_project_builddir(tmpdir):
346352
build_dir = os.path.join(tmpdir, 'b1')
347353
os.mkdir(build_dir)
348354
__test_checkclass_project(tmpdir, ['-j1', '--cppcheck-build-dir={}'.format(build_dir)])
349355

356+
357+
def test_checkclass_project_builddir_j(tmpdir):
358+
build_dir = os.path.join(tmpdir, 'b1')
359+
os.mkdir(build_dir)
360+
__test_checkclass_project(tmpdir, ['-j2', '--cppcheck-build-dir={}'.format(build_dir)])

0 commit comments

Comments
 (0)