From c4806d9d87cf76d2fa82234ffda443fd1e2f3f06 Mon Sep 17 00:00:00 2001 From: Mustafa Kemal Gilor Date: Tue, 6 May 2025 22:00:10 +0300 Subject: [PATCH 1/2] [tests/mock_logger] Add substr as Description() for distinction Right now, it's hard to tell which expect_log call is failed to be satisfied because the output is ambiguous: error: Actual function call count doesn't match EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr)))... Expected: to be called once Actual: never called - unsatisfied and active The patch fixes that by utilizing the matcher description: error: Actual function "my expected log string" call count doesn't match EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr)))... Expected: to be called once Actual: never called - unsatisfied and active Signed-off-by: Mustafa Kemal Gilor --- tests/mock_logger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mock_logger.cpp b/tests/mock_logger.cpp index 62054ed822..258d057fff 100644 --- a/tests/mock_logger.cpp +++ b/tests/mock_logger.cpp @@ -50,7 +50,7 @@ mpt::MockLogger::Scope::~Scope() void mpt::MockLogger::expect_log(mpl::Level lvl, const std::string& substr, const Cardinality& times) { - EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr))).Times(times); + EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr))).Times(times).Description(substr); } void mpt::MockLogger::screen_logs(mpl::Level lvl) From e8e97563ce7b91e9e0bd302509fb8d25be898fa0 Mon Sep 17 00:00:00 2001 From: Mustafa Kemal Gilor Date: Wed, 7 May 2025 15:43:56 +0300 Subject: [PATCH 2/2] [tests/mock_logger] prettify expect_log description Signed-off-by: Mustafa Kemal Gilor --- tests/mock_logger.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/mock_logger.cpp b/tests/mock_logger.cpp index 258d057fff..d37ed0556b 100644 --- a/tests/mock_logger.cpp +++ b/tests/mock_logger.cpp @@ -17,6 +17,8 @@ #include "mock_logger.h" +#include + #include namespace mp = multipass; @@ -50,7 +52,9 @@ mpt::MockLogger::Scope::~Scope() void mpt::MockLogger::expect_log(mpl::Level lvl, const std::string& substr, const Cardinality& times) { - EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr))).Times(times).Description(substr); + EXPECT_CALL(*this, log(lvl, _, HasSubstr(substr))) + .Times(times) + .Description(fmt::format("log(level: {}, substr: '{}')", logging::as_string(lvl), substr)); } void mpt::MockLogger::screen_logs(mpl::Level lvl)