test: Add assert mock to avoid death tests (#1947)

Fixes #1750
This commit is contained in:
Sergey Kuznetsov
2025-03-07 18:11:52 +00:00
committed by GitHub
parent 8a08c5e6ce
commit c57fe1e6e4
30 changed files with 411 additions and 295 deletions

View File

@@ -17,6 +17,7 @@
*/
//==============================================================================
#include "util/MockAssert.hpp"
#include "util/prometheus/Counter.hpp"
#include "util/prometheus/OStream.hpp"
@@ -30,7 +31,7 @@
using namespace util::prometheus;
struct AnyCounterTests : ::testing::Test {
struct AnyCounterTests : virtual ::testing::Test {
struct MockCounterImpl {
using ValueType = std::uint64_t;
MOCK_METHOD(void, add, (ValueType));
@@ -89,18 +90,15 @@ TEST_F(AnyCounterTests, value)
EXPECT_EQ(counter.value(), 42);
}
struct AnyCounterDeathTest : AnyCounterTests {};
struct AnyCounterAssertTest : common::util::WithMockAssert, AnyCounterTests {};
TEST_F(AnyCounterDeathTest, setLowerValue)
TEST_F(AnyCounterAssertTest, setLowerValue)
{
testing::Mock::AllowLeak(&mockCounterImpl);
EXPECT_DEATH(
{
EXPECT_CALL(mockCounterImpl, value()).WillOnce(::testing::Return(50));
counter.set(42);
},
".*"
);
EXPECT_CLIO_ASSERT_FAIL({
EXPECT_CALL(mockCounterImpl, value()).WillOnce(::testing::Return(50));
counter.set(42);
});
}
struct CounterIntTests : ::testing::Test {