added environment variable `TEST_CPPCHECK_INJECT_BUILDDIR` to inject `--cppcheck-build-dir` into the cppcheck invocation of Python tests
Locally it already exposed an issue:
_____________________________________________ test_unused_function_include _____________________________________________
tmpdir = local('/tmp/pytest-of-sshuser/pytest-372/test_unused_function_include0')
def test_unused_function_include(tmpdir):
test_cpp_file = os.path.join(tmpdir, 'test.cpp')
with open(test_cpp_file, 'wt') as f:
f.write("""
#include "test.h"
""")
test_h_file = os.path.join(tmpdir, 'test.h')
with open(test_h_file, 'wt') as f:
f.write("""
class A {
public:
void f() {}
// cppcheck-suppress unusedFunction
void f2() {}
};
""")
args = ['--enable=unusedFunction', '--inline-suppr', '--template=simple', '-j1', test_cpp_file]
_, _, stderr = cppcheck(args)
> assert stderr == "{}:4:0: style: The function 'f' is never used. [unusedFunction]\n".format(test_h_file)
E assert "/tmp/pytest-of-sshuser/pytest-372/test_unused_function_include0/test.cpp:4:0: style: The function 'f' is never used. [unusedFunction]\n/tmp/pytest-of-sshuser/pytest-372/test_unused_function_include0/test.cpp:6:0: style: The function 'f2' is never used. [unusedFunction]\n" == "/tmp/pytest-of-sshuser/pytest-372/test_unused_function_include0/test.h:4:0: style: The function 'f' is never used. [unusedFunction]\n"
E
E - /tmp/pytest-of-sshuser/pytest-372/test_unused_function_include0/test.h:4:0: style: The function 'f' is never used. [unusedFunction]
E ? ^
E + /tmp/pytest-of-sshuser/pytest-372/test_unused_function_include0/test.cpp:4:0: style: The function 'f' is never used. [unusedFunction]
E ? ^^^
E + /tmp/pytest-of-sshuser/pytest-372/test_unused_function_include0/test.cpp:6:0: style: The function 'f2' is never used. [unusedFunction]
test/cli/other_test.py:808: AssertionError
So far I still stand by my previous comment that the build dir should not be used in production ... if all tests pass with the option injected I will most likely change my opinion.
This requires a way to indicate that --cppcheck-build-dir should not be injected into a test.
So far I still stand by my previous comment that the build dir should not be used in production ... if all tests pass with the option injected I will most likely change my opinion.
This looks better than expected and I take back my previous opinion. There are still documented issues but those don't look too bad.
I like the idea to run the tests with and without build dir 👍
Wait til you see the follow-up...