cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

added environment variable `TEST_CPPCHECK_INJECT_BUILDDIR` to inject `--cppcheck-build-dir` into the cppcheck invocation of Python tests

Open firewave opened this issue 1 year ago • 4 comments

firewave avatar Oct 07 '24 19:10 firewave

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

firewave avatar Oct 07 '24 19:10 firewave

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.

firewave avatar Oct 07 '24 19:10 firewave

This requires a way to indicate that --cppcheck-build-dir should not be injected into a test.

firewave avatar Oct 20 '24 14:10 firewave

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.

firewave avatar Oct 21 '24 13:10 firewave

I like the idea to run the tests with and without build dir 👍

Wait til you see the follow-up...

firewave avatar Dec 05 '24 16:12 firewave