gtest: check if string is equal to one of two strings
16,010
Try it:
std::string s1 = "ab";
std::string s2 = "cd";
std::string str = "ab";
EXPECT_TRUE(s1 == str || s2 == str);
Related videos on Youtube
Author by
David Hovsepyan
Updated on June 08, 2022Comments
-
David Hovsepyan 5 months
Consider that I have two strings:
std::string s1 = "ab"; std::string s2 = "cd";
and I want to check (e.g. using EXPECT_EQ) if some given
std::string str
is equal either tos1
ors2
.If gtest's
ASSERT_*
andEXPECT_*
would returnbool
I could have writtenEXPECT_TRUE(EXPECT_EQ(str, s1) || EXPECT_EQ(str, s2));
but, unfortunately, they don't.
-
Easton Bornemeier over 4 years
EXPECT_TRUE(str==s1 || str==s2)
?
-
-
hfrmobile over 1 yearI am in the situation that I have used as described and now I don't know why test is failing on server build but locally the tests succeeds. See bellow for a better solution.