Menu

Gtest unusedStructMember, unusedFunction false positive

2024-09-18
2024-09-23
  • Samuel Poláček

    #include <gtest/gtest.h>
    
    namespace Namespace
    {
        class TestClass : public testing::Test
        {
        public:
            std::string const ApplicationName = "TestApp";
        };
    
        TEST_F(TestClass, testCase)
        {
            ASSERT_NO_THROW(std::string(ApplicationName));
        }
    }
    
    $ cppcheck --version
    Cppcheck 2.15.0
    
    $ cppcheck --library=googletest --enable=all test.cpp 
    Checking test.cpp ...
    test.cpp:1:0: information: Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    #include <gtest/gtest.h>
    ^
    test.cpp:8:27: style: class member 'TestClass::ApplicationName' is never used. [unusedStructMember]
            std::string const ApplicationName = "TestApp";
                              ^
    test.cpp:11:0: style: The function '__TestClass_testCase' is never used. [unusedFunction]
        TEST_F(TestClass, testCase)
    ^
    nofile:0:0: information: Active checkers: 167/835 (use --checkers-report=<filename> to see details) [checkersReport]
    

    The test case is not unused and the struct member is used.

     
  • CHR

    CHR - 2024-09-18
     
    • Samuel Poláček

      What about the unused function warning? It seems to be happening a lot for Gtest tests, but des not happen always. I cannot see the pattern in yet.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.