googletest
                                
                                
                                
                                    googletest copied to clipboard
                            
                            
                            
                        total_part_count() won't return success part count.
Just as below test code, the expected total part count is 4, but actual is 0:
class MinimalistPrinter : public ::testing::EmptyTestEventListener {
    // Called before a test starts.
    virtual void OnTestStart(const ::testing::TestInfo& test_info) {
        std::cout << "***TEST START:" << test_info.test_case_name()
            << "." << test_info.name() << std::endl;
    }
    // Called after a failed assertion or a SUCCESS().
    virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) {
        printf("%s in %s:%d\n%s\n",
            test_part_result.failed() ? "*** Failure" : "Success",
            test_part_result.file_name(),
            test_part_result.line_number(),
            test_part_result.summary());
    }
    // Called after a test ends.
    virtual void OnTestEnd(const ::testing::TestInfo& test_info) {
        std::cout << "***TEST END:" << test_info.test_case_name()
            << "." << test_info.name() << std::endl;
        std::cout << "Part Count:" << test_info.result()->total_part_count() << std::endl;
    }
};
int add_one(int a) {
    return a + 1;
}
TEST(TestCase1, check_function) {
    EXPECT_EQ(4, add_one(3));
    EXPECT_EQ(4, add_one(3));
    EXPECT_EQ(4, add_one(3));
    EXPECT_EQ(4, add_one(3));
}
int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    // Gets hold of the event listener list.
    ::testing::TestEventListeners& listeners =
        ::testing::UnitTest::GetInstance()->listeners();
    // Adds a listener to the end.  googletest takes the ownership.
    delete listeners.Release(listeners.default_result_printer());
    listeners.Append(new MinimalistPrinter);
    return RUN_ALL_TESTS();
}
                                    
                                    
                                    
                                
@SuJinpei @sbenzaquen Is this issue still relevant or should be closed?
I'm also affected by this issue. I'm using release 1.12.1.
According to the docstring:
// Gets the number of all test parts.  This is the sum of the number
// of successful test parts and the number of failed test parts.
Here is a minimal reproducer:
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "gtest/gtest-spi.h"
class Fixture : public ::testing::Test
{
    public:
        void TearDown() override
        {
            const ::testing::TestInfo  * ti = ::testing::UnitTest::GetInstance()->current_test_info();
            const ::testing::TestResult* tr = ti->result();
            std::cout << ti->name() << " : " << tr->total_part_count() << std::endl;
            if(std::string_view(ti->name()) == std::string("total_part_count_no_failure"))
            {
                if(tr->total_part_count() != 0)
                    throw std::runtime_error("I cannot observe the bug.");
            }
            else if(std::string_view(ti->name()) == std::string("total_part_count_one_failure"))
            {
                if(tr->total_part_count() != 1)
                    throw std::runtime_error("Ok, it's really broken now!");
            }
            else
                throw std::runtime_error(std::string("Unhandled test name ") + ti->name());
        }
};
TEST_F(Fixture, total_part_count_no_failure)
{
    EXPECT_TRUE(true);
}
TEST_F(Fixture, total_part_count_one_failure)
{
    EXPECT_TRUE(false);
}
int main(int argc, char **argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
Console output:
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from Fixture
[ RUN      ] Fixture.total_part_count_no_failure
total_part_count_no_failure : 0
[       OK ] Fixture.total_part_count_no_failure (0 ms)
[ RUN      ] Fixture.total_part_count_one_failure
/workspaces/FEpLaplace/tests/utils/test_repro.cpp:37: Failure
Value of: false
  Actual: false
Expected: true
total_part_count_one_failure : 1
[  FAILED  ] Fixture.total_part_count_one_failure (0 ms)
[----------] 2 tests from Fixture (0 ms total)
[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (0 ms total)
[  PASSED  ] 1 test.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] Fixture.total_part_count_one_failure
 1 FAILED TEST