Skip to content

Commit

Permalink
test/cli/unused_function_test.py: added testing with --project=
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jan 16, 2024
1 parent a2efcb7 commit 620b52a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
8 changes: 8 additions & 0 deletions test/cli/unusedFunction/unusedFunction.cppcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<paths>
<dir name="1.c"/>
<dir name="2.c"/>
<dir name="3.c"/>
</paths>
</project>
64 changes: 63 additions & 1 deletion test/cli/unused_function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ def test_unused_functions_j():
assert ret == 0, stdout


def test_unused_functions_project():
ret, stdout, stderr = cppcheck(['-q',
'--template=simple',
'--enable=unusedFunction',
'--inline-suppr',
'--project={}'.format(os.path.join(PROJECT_DIR, 'unusedFunction.cppcheck'))])
assert stdout.splitlines() == []
assert [
"{}/3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(PROJECT_DIR)
] == stderr.splitlines()
assert ret == 0, stdout


def test_unused_functions_project_j():
ret, stdout, stderr = cppcheck(['-q',
'--template=simple',
'--enable=unusedFunction',
'--inline-suppr',
'--project={}'.format(os.path.join(PROJECT_DIR, 'unusedFunction.cppcheck')),
'-j2'])
assert stdout.splitlines() == [
"cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check."
]
assert [] == stderr.splitlines()
assert ret == 0, stdout


def test_unused_functions_builddir(tmpdir):
build_dir = os.path.join(tmpdir, 'b1')
os.mkdir(build_dir)
Expand All @@ -51,5 +78,40 @@ def test_unused_functions_builddir_j(tmpdir):
]
assert ret == 0, stdout

# TODO: test with project file

def test_unused_functions_builddir_project(tmpdir):
build_dir = os.path.join(tmpdir, 'b1')
os.mkdir(build_dir)
ret, stdout, stderr = cppcheck(['-q',
'--template=simple',
'--enable=unusedFunction',
'--inline-suppr',
'--project={}'.format(os.path.join(PROJECT_DIR, 'unusedFunction.cppcheck')),
'--cppcheck-build-dir={}'.format(build_dir)])
assert stdout.splitlines() == []
assert stderr.splitlines() == [
"{}/3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(PROJECT_DIR)
]
assert ret == 0, stdout


# TODO: only f3_3 is unused
def test_unused_functions_builddir_project_j(tmpdir):
build_dir = os.path.join(tmpdir, 'b1')
os.mkdir(build_dir)
ret, stdout, stderr = cppcheck(['-q',
'--template=simple',
'--enable=unusedFunction',
'--inline-suppr',
'--project={}'.format(os.path.join(PROJECT_DIR, 'unusedFunction.cppcheck')),
'--cppcheck-build-dir={}'.format(build_dir),
'-j2'])
assert stdout.splitlines() == []
assert stderr.splitlines() == [
"{}/1.c:4:0: style: The function 'f1' is never used. [unusedFunction]".format(PROJECT_DIR),
"{}/2.c:4:0: style: The function 'f2' is never used. [unusedFunction]".format(PROJECT_DIR),
"{}/3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(PROJECT_DIR)
]
assert ret == 0, stdout

# TODO: test with FileSettings

0 comments on commit 620b52a

Please sign in to comment.