diff --git a/api/test/rtc_error_matchers.h b/api/test/rtc_error_matchers.h index cf923b28fa..2abc569f8a 100644 --- a/api/test/rtc_error_matchers.h +++ b/api/test/rtc_error_matchers.h @@ -37,7 +37,41 @@ MATCHER_P(IsRtcOkAndHolds, return testing::ExplainMatchResult(matcher, arg.value(), result_listener); } -MATCHER_P2(IsRtcErrorWithMessage, +MATCHER_P(IsRtcErrorWithType, error_type, ToString(error_type)) { + if (arg.ok()) { + *result_listener << "Expected " << ToString(error_type) << ", got OK."; + return false; + } + if (arg.type() != error_type) { + *result_listener << "Expected " << ToString(error_type) << ", got " + << ToString(arg.type()); + return false; + } + return true; +} + +MATCHER_P2(IsRtcErrorWithTypeAndMessage, + error_type, + message, + ToString(error_type)) { + if (arg.ok()) { + *result_listener << "Expected " << ToString(error_type) << ", got OK."; + return false; + } + if (arg.type() != error_type) { + *result_listener << "Expected " << ToString(error_type) << ", got " + << ToString(arg.type()); + return false; + } + if (std::string(arg.message()) != message) { + *result_listener << "Expected message \"" << message << "\", got \"" + << arg.message() << "\""; + return false; + } + return true; +} + +MATCHER_P2(IsRtcErrorOrWithMessage, error_matcher, message_matcher, "RtcErrorOr that is holding an error that " + diff --git a/test/wait_until_unittest.cc b/test/wait_until_unittest.cc index 5f4ecf1696..fffce708c1 100644 --- a/test/wait_until_unittest.cc +++ b/test/wait_until_unittest.cc @@ -54,7 +54,7 @@ TEST(WaitUntilTest, ReturnsErrorWhenTimeoutIsReached) { // flakiness. EXPECT_THAT( result, - IsRtcErrorWithMessage( + IsRtcErrorOrWithMessage( _, MatchesRegex( "Value of: counter\nExpected: is equal to 1\nActual: -\\d+"))); } @@ -71,7 +71,7 @@ TEST(WaitUntilTest, ErrorContainsMatcherExplanation) { // flakiness. EXPECT_THAT( result, - IsRtcErrorWithMessage( + IsRtcErrorOrWithMessage( _, MatchesRegex("Value of: counter\nExpected: \\(is > 0\\) and " "\\(is < 10\\)\nActual: -\\d+, which doesn't match " "\\(is > 0\\)")));