|
| 1 | + |
| 2 | +# python3 -m pytest test-unused_function_test.py |
| 3 | + |
| 4 | +import os |
| 5 | +from testutils import cppcheck |
| 6 | + |
| 7 | +__script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 8 | + |
| 9 | +PROJECT_DIR = os.path.join(__script_dir, 'unusedFunction') |
| 10 | + |
| 11 | + |
| 12 | +def test_unused_functions(): |
| 13 | + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', PROJECT_DIR]) |
| 14 | + assert stdout.splitlines() == [] |
| 15 | + assert stderr.splitlines() == [ |
| 16 | + "{}/3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(PROJECT_DIR) |
| 17 | + ] |
| 18 | + assert ret == 0, stdout |
| 19 | + |
| 20 | + |
| 21 | +def test_unused_functions_j(): |
| 22 | + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j2', PROJECT_DIR]) |
| 23 | + assert stdout.splitlines() == [ |
| 24 | + "cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check." |
| 25 | + ] |
| 26 | + assert stderr.splitlines() == [] |
| 27 | + assert ret == 0, stdout |
| 28 | + |
| 29 | + |
| 30 | +def test_unused_functions_builddir(tmpdir): |
| 31 | + build_dir = os.path.join(tmpdir, 'b1') |
| 32 | + os.mkdir(build_dir) |
| 33 | + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '--cppcheck-build-dir={}'.format(build_dir), PROJECT_DIR]) |
| 34 | + assert stdout.splitlines() == [] |
| 35 | + assert stderr.splitlines() == [ |
| 36 | + "{}/3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(PROJECT_DIR) |
| 37 | + ] |
| 38 | + assert ret == 0, stdout |
| 39 | + |
| 40 | + |
| 41 | +# TODO: only f3_3 is unused |
| 42 | +def test_unused_functions_builddir_j(tmpdir): |
| 43 | + build_dir = os.path.join(tmpdir, 'b1') |
| 44 | + os.mkdir(build_dir) |
| 45 | + ret, stdout, stderr = cppcheck(['-q', '--template=simple', '--enable=unusedFunction', '--inline-suppr', '-j2', '--cppcheck-build-dir={}'.format(build_dir), PROJECT_DIR]) |
| 46 | + assert stdout.splitlines() == [] |
| 47 | + assert stderr.splitlines() == [ |
| 48 | + "{}/1.c:4:0: style: The function 'f1' is never used. [unusedFunction]".format(PROJECT_DIR), |
| 49 | + "{}/2.c:4:0: style: The function 'f2' is never used. [unusedFunction]".format(PROJECT_DIR), |
| 50 | + "{}/3.c:3:0: style: The function 'f3_3' is never used. [unusedFunction]".format(PROJECT_DIR) |
| 51 | + ] |
| 52 | + assert ret == 0, stdout |
| 53 | + |
| 54 | +# TODO: test with project file |
| 55 | +# TODO: test with FileSettings |
0 commit comments