I'd like to check if a vector is not empty in gtest but I'd like to understand more in general how to check the negation of a matcher.
I usually ckeck size is greater than zero
EXPECT_THAT( vector.size(), Gt( 0 ) );
and I know I could write my own matcher
MATCHER( IsNotEmpty, !negation ? "isn't empty" : "is empty" ) {
if ( !arg.empty() ) {
return true;
}
*result_listener << "whose size is " << arg.size();
return false;
}
but I'm wondering if it's just simply possible to negate any matcher
I find out that you can composite some matchers and do something like
EXPECT_THAT( vector, Not( IsEmpty() ) );
also other interesting composite matchers
AllOf(m1, m2, ..., mn)
AnyOf(m1, m2, ..., mn)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With