Improves matcher messages across the board.
This commit is contained in:
@@ -211,6 +211,43 @@ TEST(ArgsTest, DescribesNegationCorrectly) {
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, ExplainsMatchResultWithoutInnerExplanation) {
|
||||
const Matcher<tuple<bool, int, int> > m = Args<1, 2>(Eq());
|
||||
EXPECT_EQ("whose fields (#1, #2) are (42, 42)",
|
||||
Explain(m, make_tuple(false, 42, 42)));
|
||||
EXPECT_EQ("whose fields (#1, #2) are (42, 43)",
|
||||
Explain(m, make_tuple(false, 42, 43)));
|
||||
}
|
||||
|
||||
// For testing Args<>'s explanation.
|
||||
class LessThanMatcher : public MatcherInterface<tuple<char, int> > {
|
||||
public:
|
||||
virtual void DescribeTo(::std::ostream* os) const {}
|
||||
|
||||
virtual bool MatchAndExplain(tuple<char, int> value,
|
||||
MatchResultListener* listener) const {
|
||||
const int diff = get<0>(value) - get<1>(value);
|
||||
if (diff > 0) {
|
||||
*listener << "where the first value is " << diff
|
||||
<< " more than the second";
|
||||
}
|
||||
return diff < 0;
|
||||
}
|
||||
};
|
||||
|
||||
Matcher<tuple<char, int> > LessThan() {
|
||||
return MakeMatcher(new LessThanMatcher);
|
||||
}
|
||||
|
||||
TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) {
|
||||
const Matcher<tuple<char, int, int> > m = Args<0, 2>(LessThan());
|
||||
EXPECT_EQ("whose fields (#0, #2) are ('a' (97), 42), "
|
||||
"where the first value is 55 more than the second",
|
||||
Explain(m, make_tuple('a', 42, 42)));
|
||||
EXPECT_EQ("whose fields (#0, #2) are ('\\0', 43)",
|
||||
Explain(m, make_tuple('\0', 42, 43)));
|
||||
}
|
||||
|
||||
// For testing ExplainMatchResultTo().
|
||||
class GreaterThanMatcher : public MatcherInterface<int> {
|
||||
public:
|
||||
@@ -224,11 +261,11 @@ class GreaterThanMatcher : public MatcherInterface<int> {
|
||||
MatchResultListener* listener) const {
|
||||
const int diff = lhs - rhs_;
|
||||
if (diff > 0) {
|
||||
*listener << "is " << diff << " more than " << rhs_;
|
||||
*listener << "which is " << diff << " more than " << rhs_;
|
||||
} else if (diff == 0) {
|
||||
*listener << "is the same as " << rhs_;
|
||||
*listener << "which is the same as " << rhs_;
|
||||
} else {
|
||||
*listener << "is " << -diff << " less than " << rhs_;
|
||||
*listener << "which is " << -diff << " less than " << rhs_;
|
||||
}
|
||||
|
||||
return lhs > rhs_;
|
||||
@@ -254,32 +291,32 @@ TEST(ElementsAreTest, CanDescribeExpectingNoElement) {
|
||||
|
||||
TEST(ElementsAreTest, CanDescribeExpectingOneElement) {
|
||||
Matcher<vector<int> > m = ElementsAre(Gt(5));
|
||||
EXPECT_EQ("has 1 element that is greater than 5", Describe(m));
|
||||
EXPECT_EQ("has 1 element that is > 5", Describe(m));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, CanDescribeExpectingManyElements) {
|
||||
Matcher<list<string> > m = ElementsAre(StrEq("one"), "two");
|
||||
EXPECT_EQ("has 2 elements where\n"
|
||||
"element 0 is equal to \"one\",\n"
|
||||
"element 1 is equal to \"two\"", Describe(m));
|
||||
"element #0 is equal to \"one\",\n"
|
||||
"element #1 is equal to \"two\"", Describe(m));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, CanDescribeNegationOfExpectingNoElement) {
|
||||
Matcher<vector<int> > m = ElementsAre();
|
||||
EXPECT_EQ("is not empty", DescribeNegation(m));
|
||||
EXPECT_EQ("isn't empty", DescribeNegation(m));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, CanDescribeNegationOfExpectingOneElment) {
|
||||
Matcher<const list<int>& > m = ElementsAre(Gt(5));
|
||||
EXPECT_EQ("does not have 1 element, or\n"
|
||||
"element 0 is not greater than 5", DescribeNegation(m));
|
||||
EXPECT_EQ("doesn't have 1 element, or\n"
|
||||
"element #0 isn't > 5", DescribeNegation(m));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, CanDescribeNegationOfExpectingManyElements) {
|
||||
Matcher<const list<string>& > m = ElementsAre("one", "two");
|
||||
EXPECT_EQ("does not have 2 elements, or\n"
|
||||
"element 0 is not equal to \"one\", or\n"
|
||||
"element 1 is not equal to \"two\"", DescribeNegation(m));
|
||||
EXPECT_EQ("doesn't have 2 elements, or\n"
|
||||
"element #0 isn't equal to \"one\", or\n"
|
||||
"element #1 isn't equal to \"two\"", DescribeNegation(m));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, DoesNotExplainTrivialMatch) {
|
||||
@@ -297,8 +334,9 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
|
||||
|
||||
const int a[] = { 10, 0, 100 };
|
||||
vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a));
|
||||
EXPECT_EQ("element 0 is 9 more than 1,\n"
|
||||
"element 2 is 98 more than 2", Explain(m, test_vector));
|
||||
EXPECT_EQ("whose element #0 matches, which is 9 more than 1,\n"
|
||||
"and whose element #2 matches, which is 98 more than 2",
|
||||
Explain(m, test_vector));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, CanExplainMismatchWrongSize) {
|
||||
@@ -309,7 +347,7 @@ TEST(ElementsAreTest, CanExplainMismatchWrongSize) {
|
||||
EXPECT_EQ("", Explain(m, test_list));
|
||||
|
||||
test_list.push_back(1);
|
||||
EXPECT_EQ("has 1 element", Explain(m, test_list));
|
||||
EXPECT_EQ("which has 1 element", Explain(m, test_list));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, CanExplainMismatchRightSize) {
|
||||
@@ -318,10 +356,11 @@ TEST(ElementsAreTest, CanExplainMismatchRightSize) {
|
||||
vector<int> v;
|
||||
v.push_back(2);
|
||||
v.push_back(1);
|
||||
EXPECT_EQ("element 0 doesn't match", Explain(m, v));
|
||||
EXPECT_EQ("whose element #0 doesn't match", Explain(m, v));
|
||||
|
||||
v[0] = 1;
|
||||
EXPECT_EQ("element 1 doesn't match (is 4 less than 5)", Explain(m, v));
|
||||
EXPECT_EQ("whose element #1 doesn't match, which is 4 less than 5",
|
||||
Explain(m, v));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, MatchesOneElementVector) {
|
||||
@@ -1030,16 +1069,22 @@ TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
|
||||
EXPECT_THAT(c_string_set, Not(Contains(string("hello").c_str())));
|
||||
}
|
||||
|
||||
TEST(ContainsTest, DescribesItselfCorrectly) {
|
||||
TEST(ContainsTest, ExplainsMatchResultCorrectly) {
|
||||
const int a[2] = { 1, 2 };
|
||||
Matcher<const int(&)[2]> m = Contains(2);
|
||||
EXPECT_EQ("element 1 matches", Explain(m, a));
|
||||
EXPECT_EQ("whose element #1 matches", Explain(m, a));
|
||||
|
||||
m = Contains(3);
|
||||
EXPECT_EQ("", Explain(m, a));
|
||||
|
||||
m = Contains(GreaterThan(0));
|
||||
EXPECT_EQ("whose element #0 matches, which is 1 more than 0", Explain(m, a));
|
||||
|
||||
m = Contains(GreaterThan(10));
|
||||
EXPECT_EQ("", Explain(m, a));
|
||||
}
|
||||
|
||||
TEST(ContainsTest, ExplainsMatchResultCorrectly) {
|
||||
TEST(ContainsTest, DescribesItselfCorrectly) {
|
||||
Matcher<vector<int> > m = Contains(1);
|
||||
EXPECT_EQ("contains at least one element that is equal to 1", Describe(m));
|
||||
|
||||
|
||||
@@ -61,8 +61,10 @@ bool SkipPrefix(const char* prefix, const char** pstr);
|
||||
|
||||
namespace gmock_matchers_test {
|
||||
|
||||
using std::make_pair;
|
||||
using std::map;
|
||||
using std::multimap;
|
||||
using std::pair;
|
||||
using std::stringstream;
|
||||
using std::tr1::make_tuple;
|
||||
using testing::A;
|
||||
@@ -71,9 +73,11 @@ using testing::AllOf;
|
||||
using testing::An;
|
||||
using testing::AnyOf;
|
||||
using testing::ByRef;
|
||||
using testing::ContainsRegex;
|
||||
using testing::DoubleEq;
|
||||
using testing::EndsWith;
|
||||
using testing::Eq;
|
||||
using testing::ExplainMatchResult;
|
||||
using testing::Field;
|
||||
using testing::FloatEq;
|
||||
using testing::Ge;
|
||||
@@ -85,12 +89,12 @@ using testing::Le;
|
||||
using testing::Lt;
|
||||
using testing::MakeMatcher;
|
||||
using testing::MakePolymorphicMatcher;
|
||||
using testing::MatchResultListener;
|
||||
using testing::Matcher;
|
||||
using testing::MatcherCast;
|
||||
using testing::MatcherInterface;
|
||||
using testing::Matches;
|
||||
using testing::ExplainMatchResult;
|
||||
using testing::MatchResultListener;
|
||||
using testing::MatchesRegex;
|
||||
using testing::NanSensitiveDoubleEq;
|
||||
using testing::NanSensitiveFloatEq;
|
||||
using testing::Ne;
|
||||
@@ -112,17 +116,19 @@ using testing::TypedEq;
|
||||
using testing::Value;
|
||||
using testing::_;
|
||||
using testing::internal::DummyMatchResultListener;
|
||||
using testing::internal::ExplainMatchFailureTupleTo;
|
||||
using testing::internal::FloatingEqMatcher;
|
||||
using testing::internal::FormatMatcherDescriptionSyntaxError;
|
||||
using testing::internal::GetParamIndex;
|
||||
using testing::internal::Interpolation;
|
||||
using testing::internal::Interpolations;
|
||||
using testing::internal::JoinAsTuple;
|
||||
using testing::internal::RE;
|
||||
using testing::internal::SkipPrefix;
|
||||
using testing::internal::StreamMatchResultListener;
|
||||
using testing::internal::String;
|
||||
using testing::internal::Strings;
|
||||
using testing::internal::StringMatchResultListener;
|
||||
using testing::internal::Strings;
|
||||
using testing::internal::ValidateMatcherDescription;
|
||||
using testing::internal::kInvalidInterpolation;
|
||||
using testing::internal::kPercentInterpolation;
|
||||
@@ -131,17 +137,13 @@ using testing::internal::linked_ptr;
|
||||
using testing::internal::scoped_ptr;
|
||||
using testing::internal::string;
|
||||
|
||||
using testing::ContainsRegex;
|
||||
using testing::MatchesRegex;
|
||||
using testing::internal::RE;
|
||||
|
||||
// For testing ExplainMatchResultTo().
|
||||
class GreaterThanMatcher : public MatcherInterface<int> {
|
||||
public:
|
||||
explicit GreaterThanMatcher(int rhs) : rhs_(rhs) {}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const {
|
||||
*os << "is greater than " << rhs_;
|
||||
*os << "is > " << rhs_;
|
||||
}
|
||||
|
||||
virtual bool MatchAndExplain(int lhs,
|
||||
@@ -757,7 +759,7 @@ TEST(GeTest, ImplementsGreaterThanOrEqual) {
|
||||
// Tests that Ge(v) describes itself properly.
|
||||
TEST(GeTest, CanDescribeSelf) {
|
||||
Matcher<int> m = Ge(5);
|
||||
EXPECT_EQ("is greater than or equal to 5", Describe(m));
|
||||
EXPECT_EQ("is >= 5", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that Gt(v) matches anything > v.
|
||||
@@ -771,7 +773,7 @@ TEST(GtTest, ImplementsGreaterThan) {
|
||||
// Tests that Gt(v) describes itself properly.
|
||||
TEST(GtTest, CanDescribeSelf) {
|
||||
Matcher<int> m = Gt(5);
|
||||
EXPECT_EQ("is greater than 5", Describe(m));
|
||||
EXPECT_EQ("is > 5", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that Le(v) matches anything <= v.
|
||||
@@ -785,7 +787,7 @@ TEST(LeTest, ImplementsLessThanOrEqual) {
|
||||
// Tests that Le(v) describes itself properly.
|
||||
TEST(LeTest, CanDescribeSelf) {
|
||||
Matcher<int> m = Le(5);
|
||||
EXPECT_EQ("is less than or equal to 5", Describe(m));
|
||||
EXPECT_EQ("is <= 5", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that Lt(v) matches anything < v.
|
||||
@@ -799,7 +801,7 @@ TEST(LtTest, ImplementsLessThan) {
|
||||
// Tests that Lt(v) describes itself properly.
|
||||
TEST(LtTest, CanDescribeSelf) {
|
||||
Matcher<int> m = Lt(5);
|
||||
EXPECT_EQ("is less than 5", Describe(m));
|
||||
EXPECT_EQ("is < 5", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that Ne(v) matches anything != v.
|
||||
@@ -813,7 +815,7 @@ TEST(NeTest, ImplementsNotEqual) {
|
||||
// Tests that Ne(v) describes itself properly.
|
||||
TEST(NeTest, CanDescribeSelf) {
|
||||
Matcher<int> m = Ne(5);
|
||||
EXPECT_EQ("is not equal to 5", Describe(m));
|
||||
EXPECT_EQ("isn't equal to 5", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that IsNull() matches any NULL pointer of any type.
|
||||
@@ -876,7 +878,7 @@ TEST(IsNullTest, ReferenceToConstScopedPtr) {
|
||||
TEST(IsNullTest, CanDescribeSelf) {
|
||||
Matcher<int*> m = IsNull();
|
||||
EXPECT_EQ("is NULL", Describe(m));
|
||||
EXPECT_EQ("is not NULL", DescribeNegation(m));
|
||||
EXPECT_EQ("isn't NULL", DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that NotNull() matches any non-NULL pointer of any type.
|
||||
@@ -923,7 +925,7 @@ TEST(NotNullTest, ReferenceToConstScopedPtr) {
|
||||
// Tests that NotNull() describes itself properly.
|
||||
TEST(NotNullTest, CanDescribeSelf) {
|
||||
Matcher<int*> m = NotNull();
|
||||
EXPECT_EQ("is not NULL", Describe(m));
|
||||
EXPECT_EQ("isn't NULL", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that Ref(variable) matches an argument that references
|
||||
@@ -973,6 +975,16 @@ TEST(RefTest, IsCovariant) {
|
||||
EXPECT_FALSE(m1.Matches(base2));
|
||||
}
|
||||
|
||||
TEST(RefTest, ExplainsResult) {
|
||||
int n = 0;
|
||||
EXPECT_THAT(Explain(Matcher<const int&>(Ref(n)), n),
|
||||
StartsWith("which is located @"));
|
||||
|
||||
int m = 0;
|
||||
EXPECT_THAT(Explain(Matcher<const int&>(Ref(n)), m),
|
||||
StartsWith("which is located @"));
|
||||
}
|
||||
|
||||
// Tests string comparison matchers.
|
||||
|
||||
TEST(StrEqTest, MatchesEqualString) {
|
||||
@@ -1013,7 +1025,7 @@ TEST(StrNeTest, MatchesUnequalString) {
|
||||
|
||||
TEST(StrNeTest, CanDescribeSelf) {
|
||||
Matcher<const char*> m = StrNe("Hi");
|
||||
EXPECT_EQ("is not equal to \"Hi\"", Describe(m));
|
||||
EXPECT_EQ("isn't equal to \"Hi\"", Describe(m));
|
||||
}
|
||||
|
||||
TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
|
||||
@@ -1072,7 +1084,7 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
|
||||
|
||||
TEST(StrCaseNeTest, CanDescribeSelf) {
|
||||
Matcher<const char*> m = StrCaseNe("Hi");
|
||||
EXPECT_EQ("is not equal to (ignoring case) \"Hi\"", Describe(m));
|
||||
EXPECT_EQ("isn't equal to (ignoring case) \"Hi\"", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that HasSubstr() works for matching string-typed values.
|
||||
@@ -1106,12 +1118,21 @@ TEST(HasSubstrTest, CanDescribeSelf) {
|
||||
}
|
||||
|
||||
TEST(KeyTest, CanDescribeSelf) {
|
||||
Matcher<const std::pair<std::string, int>&> m = Key("foo");
|
||||
Matcher<const pair<std::string, int>&> m = Key("foo");
|
||||
EXPECT_EQ("has a key that is equal to \"foo\"", Describe(m));
|
||||
EXPECT_EQ("doesn't have a key that is equal to \"foo\"", DescribeNegation(m));
|
||||
}
|
||||
|
||||
TEST(KeyTest, ExplainsResult) {
|
||||
Matcher<pair<int, bool> > m = Key(GreaterThan(10));
|
||||
EXPECT_EQ("whose first field is a value which is 5 less than 10",
|
||||
Explain(m, make_pair(5, true)));
|
||||
EXPECT_EQ("whose first field is a value which is 5 more than 10",
|
||||
Explain(m, make_pair(15, true)));
|
||||
}
|
||||
|
||||
TEST(KeyTest, MatchesCorrectly) {
|
||||
std::pair<int, std::string> p(25, "foo");
|
||||
pair<int, std::string> p(25, "foo");
|
||||
EXPECT_THAT(p, Key(25));
|
||||
EXPECT_THAT(p, Not(Key(42)));
|
||||
EXPECT_THAT(p, Key(Ge(20)));
|
||||
@@ -1121,30 +1142,30 @@ TEST(KeyTest, MatchesCorrectly) {
|
||||
TEST(KeyTest, SafelyCastsInnerMatcher) {
|
||||
Matcher<int> is_positive = Gt(0);
|
||||
Matcher<int> is_negative = Lt(0);
|
||||
std::pair<char, bool> p('a', true);
|
||||
pair<char, bool> p('a', true);
|
||||
EXPECT_THAT(p, Key(is_positive));
|
||||
EXPECT_THAT(p, Not(Key(is_negative)));
|
||||
}
|
||||
|
||||
TEST(KeyTest, InsideContainsUsingMap) {
|
||||
std::map<int, char> container;
|
||||
container.insert(std::make_pair(1, 'a'));
|
||||
container.insert(std::make_pair(2, 'b'));
|
||||
container.insert(std::make_pair(4, 'c'));
|
||||
container.insert(make_pair(1, 'a'));
|
||||
container.insert(make_pair(2, 'b'));
|
||||
container.insert(make_pair(4, 'c'));
|
||||
EXPECT_THAT(container, Contains(Key(1)));
|
||||
EXPECT_THAT(container, Not(Contains(Key(3))));
|
||||
}
|
||||
|
||||
TEST(KeyTest, InsideContainsUsingMultimap) {
|
||||
std::multimap<int, char> container;
|
||||
container.insert(std::make_pair(1, 'a'));
|
||||
container.insert(std::make_pair(2, 'b'));
|
||||
container.insert(std::make_pair(4, 'c'));
|
||||
container.insert(make_pair(1, 'a'));
|
||||
container.insert(make_pair(2, 'b'));
|
||||
container.insert(make_pair(4, 'c'));
|
||||
|
||||
EXPECT_THAT(container, Not(Contains(Key(25))));
|
||||
container.insert(std::make_pair(25, 'd'));
|
||||
container.insert(make_pair(25, 'd'));
|
||||
EXPECT_THAT(container, Contains(Key(25)));
|
||||
container.insert(std::make_pair(25, 'e'));
|
||||
container.insert(make_pair(25, 'e'));
|
||||
EXPECT_THAT(container, Contains(Key(25)));
|
||||
|
||||
EXPECT_THAT(container, Contains(Key(1)));
|
||||
@@ -1153,25 +1174,25 @@ TEST(KeyTest, InsideContainsUsingMultimap) {
|
||||
|
||||
TEST(PairTest, Typing) {
|
||||
// Test verifies the following type conversions can be compiled.
|
||||
Matcher<const std::pair<const char*, int>&> m1 = Pair("foo", 42);
|
||||
Matcher<const std::pair<const char*, int> > m2 = Pair("foo", 42);
|
||||
Matcher<std::pair<const char*, int> > m3 = Pair("foo", 42);
|
||||
Matcher<const pair<const char*, int>&> m1 = Pair("foo", 42);
|
||||
Matcher<const pair<const char*, int> > m2 = Pair("foo", 42);
|
||||
Matcher<pair<const char*, int> > m3 = Pair("foo", 42);
|
||||
|
||||
Matcher<std::pair<int, const std::string> > m4 = Pair(25, "42");
|
||||
Matcher<std::pair<const std::string, int> > m5 = Pair("25", 42);
|
||||
Matcher<pair<int, const std::string> > m4 = Pair(25, "42");
|
||||
Matcher<pair<const std::string, int> > m5 = Pair("25", 42);
|
||||
}
|
||||
|
||||
TEST(PairTest, CanDescribeSelf) {
|
||||
Matcher<const std::pair<std::string, int>&> m1 = Pair("foo", 42);
|
||||
Matcher<const pair<std::string, int>&> m1 = Pair("foo", 42);
|
||||
EXPECT_EQ("has a first field that is equal to \"foo\""
|
||||
", and has a second field that is equal to 42",
|
||||
Describe(m1));
|
||||
EXPECT_EQ("has a first field that is not equal to \"foo\""
|
||||
", or has a second field that is not equal to 42",
|
||||
EXPECT_EQ("has a first field that isn't equal to \"foo\""
|
||||
", or has a second field that isn't equal to 42",
|
||||
DescribeNegation(m1));
|
||||
// Double and triple negation (1 or 2 times not and description of negation).
|
||||
Matcher<const std::pair<int, int>&> m2 = Not(Pair(Not(13), 42));
|
||||
EXPECT_EQ("has a first field that is not equal to 13"
|
||||
Matcher<const pair<int, int>&> m2 = Not(Pair(Not(13), 42));
|
||||
EXPECT_EQ("has a first field that isn't equal to 13"
|
||||
", and has a second field that is equal to 42",
|
||||
DescribeNegation(m2));
|
||||
}
|
||||
@@ -1179,43 +1200,43 @@ TEST(PairTest, CanDescribeSelf) {
|
||||
TEST(PairTest, CanExplainMatchResultTo) {
|
||||
// If neither field matches, Pair() should explain about the first
|
||||
// field.
|
||||
const Matcher<std::pair<int, int> > m = Pair(GreaterThan(0), GreaterThan(0));
|
||||
const Matcher<pair<int, int> > m = Pair(GreaterThan(0), GreaterThan(0));
|
||||
EXPECT_EQ("whose first field does not match, which is 1 less than 0",
|
||||
Explain(m, std::make_pair(-1, -2)));
|
||||
Explain(m, make_pair(-1, -2)));
|
||||
|
||||
// If the first field matches but the second doesn't, Pair() should
|
||||
// explain about the second field.
|
||||
EXPECT_EQ("whose second field does not match, which is 2 less than 0",
|
||||
Explain(m, std::make_pair(1, -2)));
|
||||
Explain(m, make_pair(1, -2)));
|
||||
|
||||
// If the first field doesn't match but the second does, Pair()
|
||||
// should explain about the first field.
|
||||
EXPECT_EQ("whose first field does not match, which is 1 less than 0",
|
||||
Explain(m, std::make_pair(-1, 2)));
|
||||
Explain(m, make_pair(-1, 2)));
|
||||
|
||||
// If both fields match, Pair() should explain about them both.
|
||||
EXPECT_EQ("whose both fields match, where the first field is a value "
|
||||
"which is 1 more than 0, and the second field is a value "
|
||||
"which is 2 more than 0",
|
||||
Explain(m, std::make_pair(1, 2)));
|
||||
Explain(m, make_pair(1, 2)));
|
||||
|
||||
// If only the first match has an explanation, only this explanation should
|
||||
// be printed.
|
||||
const Matcher<std::pair<int, int> > explain_first = Pair(GreaterThan(0), 0);
|
||||
const Matcher<pair<int, int> > explain_first = Pair(GreaterThan(0), 0);
|
||||
EXPECT_EQ("whose both fields match, where the first field is a value "
|
||||
"which is 1 more than 0",
|
||||
Explain(explain_first, std::make_pair(1, 0)));
|
||||
Explain(explain_first, make_pair(1, 0)));
|
||||
|
||||
// If only the second match has an explanation, only this explanation should
|
||||
// be printed.
|
||||
const Matcher<std::pair<int, int> > explain_second = Pair(0, GreaterThan(0));
|
||||
const Matcher<pair<int, int> > explain_second = Pair(0, GreaterThan(0));
|
||||
EXPECT_EQ("whose both fields match, where the second field is a value "
|
||||
"which is 1 more than 0",
|
||||
Explain(explain_second, std::make_pair(0, 1)));
|
||||
Explain(explain_second, make_pair(0, 1)));
|
||||
}
|
||||
|
||||
TEST(PairTest, MatchesCorrectly) {
|
||||
std::pair<int, std::string> p(25, "foo");
|
||||
pair<int, std::string> p(25, "foo");
|
||||
|
||||
// Both fields match.
|
||||
EXPECT_THAT(p, Pair(25, "foo"));
|
||||
@@ -1237,7 +1258,7 @@ TEST(PairTest, MatchesCorrectly) {
|
||||
TEST(PairTest, SafelyCastsInnerMatchers) {
|
||||
Matcher<int> is_positive = Gt(0);
|
||||
Matcher<int> is_negative = Lt(0);
|
||||
std::pair<char, bool> p('a', true);
|
||||
pair<char, bool> p('a', true);
|
||||
EXPECT_THAT(p, Pair(is_positive, _));
|
||||
EXPECT_THAT(p, Not(Pair(is_negative, _)));
|
||||
EXPECT_THAT(p, Pair(_, is_positive));
|
||||
@@ -1246,9 +1267,9 @@ TEST(PairTest, SafelyCastsInnerMatchers) {
|
||||
|
||||
TEST(PairTest, InsideContainsUsingMap) {
|
||||
std::map<int, char> container;
|
||||
container.insert(std::make_pair(1, 'a'));
|
||||
container.insert(std::make_pair(2, 'b'));
|
||||
container.insert(std::make_pair(4, 'c'));
|
||||
container.insert(make_pair(1, 'a'));
|
||||
container.insert(make_pair(2, 'b'));
|
||||
container.insert(make_pair(4, 'c'));
|
||||
EXPECT_THAT(container, Contains(Pair(1, 'a')));
|
||||
EXPECT_THAT(container, Contains(Pair(1, _)));
|
||||
EXPECT_THAT(container, Contains(Pair(_, 'a')));
|
||||
@@ -1397,7 +1418,7 @@ TEST(StdWideStrNeTest, MatchesUnequalString) {
|
||||
|
||||
TEST(StdWideStrNeTest, CanDescribeSelf) {
|
||||
Matcher<const wchar_t*> m = StrNe(L"Hi");
|
||||
EXPECT_EQ("is not equal to L\"Hi\"", Describe(m));
|
||||
EXPECT_EQ("isn't equal to L\"Hi\"", Describe(m));
|
||||
}
|
||||
|
||||
TEST(StdWideStrCaseEqTest, MatchesEqualStringIgnoringCase) {
|
||||
@@ -1456,7 +1477,7 @@ TEST(StdWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) {
|
||||
|
||||
TEST(StdWideStrCaseNeTest, CanDescribeSelf) {
|
||||
Matcher<const wchar_t*> m = StrCaseNe(L"Hi");
|
||||
EXPECT_EQ("is not equal to (ignoring case) L\"Hi\"", Describe(m));
|
||||
EXPECT_EQ("isn't equal to (ignoring case) L\"Hi\"", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that HasSubstr() works for matching wstring-typed values.
|
||||
@@ -1588,7 +1609,7 @@ TEST(GlobalWideStrNeTest, MatchesUnequalString) {
|
||||
|
||||
TEST(GlobalWideStrNeTest, CanDescribeSelf) {
|
||||
Matcher<const wchar_t*> m = StrNe(L"Hi");
|
||||
EXPECT_EQ("is not equal to L\"Hi\"", Describe(m));
|
||||
EXPECT_EQ("isn't equal to L\"Hi\"", Describe(m));
|
||||
}
|
||||
|
||||
TEST(GlobalWideStrCaseEqTest, MatchesEqualStringIgnoringCase) {
|
||||
@@ -1647,7 +1668,7 @@ TEST(GlobalWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) {
|
||||
|
||||
TEST(GlobalWideStrCaseNeTest, CanDescribeSelf) {
|
||||
Matcher<const wchar_t*> m = StrCaseNe(L"Hi");
|
||||
EXPECT_EQ("is not equal to (ignoring case) L\"Hi\"", Describe(m));
|
||||
EXPECT_EQ("isn't equal to (ignoring case) L\"Hi\"", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that HasSubstr() works for matching wstring-typed values.
|
||||
@@ -1827,7 +1848,7 @@ TEST(NotTest, NegatesMatcher) {
|
||||
// Tests that Not(m) describes itself properly.
|
||||
TEST(NotTest, CanDescribeSelf) {
|
||||
Matcher<int> m = Not(Eq(5));
|
||||
EXPECT_EQ("is not equal to 5", Describe(m));
|
||||
EXPECT_EQ("isn't equal to 5", Describe(m));
|
||||
}
|
||||
|
||||
// Tests that monomorphic matchers are safely cast by the Not matcher.
|
||||
@@ -1873,31 +1894,62 @@ TEST(AllOfTest, MatchesWhenAllMatch) {
|
||||
TEST(AllOfTest, CanDescribeSelf) {
|
||||
Matcher<int> m;
|
||||
m = AllOf(Le(2), Ge(1));
|
||||
EXPECT_EQ("(is less than or equal to 2) and "
|
||||
"(is greater than or equal to 1)",
|
||||
Describe(m));
|
||||
EXPECT_EQ("(is <= 2) and (is >= 1)", Describe(m));
|
||||
|
||||
m = AllOf(Gt(0), Ne(1), Ne(2));
|
||||
EXPECT_EQ("(is greater than 0) and "
|
||||
"((is not equal to 1) and "
|
||||
"(is not equal to 2))",
|
||||
EXPECT_EQ("(is > 0) and "
|
||||
"((isn't equal to 1) and "
|
||||
"(isn't equal to 2))",
|
||||
Describe(m));
|
||||
|
||||
|
||||
m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
|
||||
EXPECT_EQ("(is greater than 0) and "
|
||||
"((is not equal to 1) and "
|
||||
"((is not equal to 2) and "
|
||||
"(is not equal to 3)))",
|
||||
EXPECT_EQ("(is > 0) and "
|
||||
"((isn't equal to 1) and "
|
||||
"((isn't equal to 2) and "
|
||||
"(isn't equal to 3)))",
|
||||
Describe(m));
|
||||
|
||||
|
||||
m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
|
||||
EXPECT_EQ("(is greater than or equal to 0) and "
|
||||
"((is less than 10) and "
|
||||
"((is not equal to 3) and "
|
||||
"((is not equal to 5) and "
|
||||
"(is not equal to 7))))", Describe(m));
|
||||
EXPECT_EQ("(is >= 0) and "
|
||||
"((is < 10) and "
|
||||
"((isn't equal to 3) and "
|
||||
"((isn't equal to 5) and "
|
||||
"(isn't equal to 7))))",
|
||||
Describe(m));
|
||||
}
|
||||
|
||||
// Tests that AllOf(m1, ..., mn) describes its negation properly.
|
||||
TEST(AllOfTest, CanDescribeNegation) {
|
||||
Matcher<int> m;
|
||||
m = AllOf(Le(2), Ge(1));
|
||||
EXPECT_EQ("(isn't <= 2) or "
|
||||
"(isn't >= 1)",
|
||||
DescribeNegation(m));
|
||||
|
||||
m = AllOf(Gt(0), Ne(1), Ne(2));
|
||||
EXPECT_EQ("(isn't > 0) or "
|
||||
"((is equal to 1) or "
|
||||
"(is equal to 2))",
|
||||
DescribeNegation(m));
|
||||
|
||||
|
||||
m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
|
||||
EXPECT_EQ("(isn't > 0) or "
|
||||
"((is equal to 1) or "
|
||||
"((is equal to 2) or "
|
||||
"(is equal to 3)))",
|
||||
DescribeNegation(m));
|
||||
|
||||
|
||||
m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
|
||||
EXPECT_EQ("(isn't >= 0) or "
|
||||
"((isn't < 10) or "
|
||||
"((is equal to 3) or "
|
||||
"((is equal to 5) or "
|
||||
"(is equal to 7))))",
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that monomorphic matchers are safely cast by the AllOf matcher.
|
||||
@@ -1915,6 +1967,49 @@ TEST(AllOfTest, AllOfMatcherSafelyCastsMonomorphicMatchers) {
|
||||
Matcher<int&> m5 = AllOf(greater_than_5, less_than_10, less_than_10);
|
||||
}
|
||||
|
||||
TEST(AllOfTest, ExplainsResult) {
|
||||
Matcher<int> m;
|
||||
|
||||
// Successful match. Both matchers need to explain. The second
|
||||
// matcher doesn't give an explanation, so only the first matcher's
|
||||
// explanation is printed.
|
||||
m = AllOf(GreaterThan(10), Lt(30));
|
||||
EXPECT_EQ("which is 15 more than 10", Explain(m, 25));
|
||||
|
||||
// Successful match. Both matchers need to explain.
|
||||
m = AllOf(GreaterThan(10), GreaterThan(20));
|
||||
EXPECT_EQ("which is 20 more than 10, and which is 10 more than 20",
|
||||
Explain(m, 30));
|
||||
|
||||
// Successful match. All matchers need to explain. The second
|
||||
// matcher doesn't given an explanation.
|
||||
m = AllOf(GreaterThan(10), Lt(30), GreaterThan(20));
|
||||
EXPECT_EQ("which is 15 more than 10, and which is 5 more than 20",
|
||||
Explain(m, 25));
|
||||
|
||||
// Successful match. All matchers need to explain.
|
||||
m = AllOf(GreaterThan(10), GreaterThan(20), GreaterThan(30));
|
||||
EXPECT_EQ("which is 30 more than 10, and which is 20 more than 20, "
|
||||
"and which is 10 more than 30",
|
||||
Explain(m, 40));
|
||||
|
||||
// Failed match. The first matcher, which failed, needs to
|
||||
// explain.
|
||||
m = AllOf(GreaterThan(10), GreaterThan(20));
|
||||
EXPECT_EQ("which is 5 less than 10", Explain(m, 5));
|
||||
|
||||
// Failed match. The second matcher, which failed, needs to
|
||||
// explain. Since it doesn't given an explanation, nothing is
|
||||
// printed.
|
||||
m = AllOf(GreaterThan(10), Lt(30));
|
||||
EXPECT_EQ("", Explain(m, 40));
|
||||
|
||||
// Failed match. The second matcher, which failed, needs to
|
||||
// explain.
|
||||
m = AllOf(GreaterThan(10), GreaterThan(20));
|
||||
EXPECT_EQ("which is 5 less than 20", Explain(m, 15));
|
||||
}
|
||||
|
||||
// Tests that AnyOf(m1, ..., mn) matches any value that matches at
|
||||
// least one of the given matchers.
|
||||
TEST(AnyOfTest, MatchesWhenAnyMatches) {
|
||||
@@ -1948,31 +2043,58 @@ TEST(AnyOfTest, MatchesWhenAnyMatches) {
|
||||
TEST(AnyOfTest, CanDescribeSelf) {
|
||||
Matcher<int> m;
|
||||
m = AnyOf(Le(1), Ge(3));
|
||||
EXPECT_EQ("(is less than or equal to 1) or "
|
||||
"(is greater than or equal to 3)",
|
||||
EXPECT_EQ("(is <= 1) or (is >= 3)",
|
||||
Describe(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2));
|
||||
EXPECT_EQ("(is less than 0) or "
|
||||
EXPECT_EQ("(is < 0) or "
|
||||
"((is equal to 1) or (is equal to 2))",
|
||||
Describe(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
|
||||
EXPECT_EQ("(is less than 0) or "
|
||||
EXPECT_EQ("(is < 0) or "
|
||||
"((is equal to 1) or "
|
||||
"((is equal to 2) or "
|
||||
"(is equal to 3)))",
|
||||
Describe(m));
|
||||
|
||||
m = AnyOf(Le(0), Gt(10), 3, 5, 7);
|
||||
EXPECT_EQ("(is less than or equal to 0) or "
|
||||
"((is greater than 10) or "
|
||||
EXPECT_EQ("(is <= 0) or "
|
||||
"((is > 10) or "
|
||||
"((is equal to 3) or "
|
||||
"((is equal to 5) or "
|
||||
"(is equal to 7))))",
|
||||
Describe(m));
|
||||
}
|
||||
|
||||
// Tests that AnyOf(m1, ..., mn) describes its negation properly.
|
||||
TEST(AnyOfTest, CanDescribeNegation) {
|
||||
Matcher<int> m;
|
||||
m = AnyOf(Le(1), Ge(3));
|
||||
EXPECT_EQ("(isn't <= 1) and (isn't >= 3)",
|
||||
DescribeNegation(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2));
|
||||
EXPECT_EQ("(isn't < 0) and "
|
||||
"((isn't equal to 1) and (isn't equal to 2))",
|
||||
DescribeNegation(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
|
||||
EXPECT_EQ("(isn't < 0) and "
|
||||
"((isn't equal to 1) and "
|
||||
"((isn't equal to 2) and "
|
||||
"(isn't equal to 3)))",
|
||||
DescribeNegation(m));
|
||||
|
||||
m = AnyOf(Le(0), Gt(10), 3, 5, 7);
|
||||
EXPECT_EQ("(isn't <= 0) and "
|
||||
"((isn't > 10) and "
|
||||
"((isn't equal to 3) and "
|
||||
"((isn't equal to 5) and "
|
||||
"(isn't equal to 7))))",
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that monomorphic matchers are safely cast by the AnyOf matcher.
|
||||
TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) {
|
||||
// greater_than_5 and less_than_10 are monomorphic matchers.
|
||||
@@ -1988,6 +2110,49 @@ TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) {
|
||||
Matcher<int&> m5 = AnyOf(greater_than_5, less_than_10, less_than_10);
|
||||
}
|
||||
|
||||
TEST(AnyOfTest, ExplainsResult) {
|
||||
Matcher<int> m;
|
||||
|
||||
// Failed match. Both matchers need to explain. The second
|
||||
// matcher doesn't give an explanation, so only the first matcher's
|
||||
// explanation is printed.
|
||||
m = AnyOf(GreaterThan(10), Lt(0));
|
||||
EXPECT_EQ("which is 5 less than 10", Explain(m, 5));
|
||||
|
||||
// Failed match. Both matchers need to explain.
|
||||
m = AnyOf(GreaterThan(10), GreaterThan(20));
|
||||
EXPECT_EQ("which is 5 less than 10, and which is 15 less than 20",
|
||||
Explain(m, 5));
|
||||
|
||||
// Failed match. All matchers need to explain. The second
|
||||
// matcher doesn't given an explanation.
|
||||
m = AnyOf(GreaterThan(10), Gt(20), GreaterThan(30));
|
||||
EXPECT_EQ("which is 5 less than 10, and which is 25 less than 30",
|
||||
Explain(m, 5));
|
||||
|
||||
// Failed match. All matchers need to explain.
|
||||
m = AnyOf(GreaterThan(10), GreaterThan(20), GreaterThan(30));
|
||||
EXPECT_EQ("which is 5 less than 10, and which is 15 less than 20, "
|
||||
"and which is 25 less than 30",
|
||||
Explain(m, 5));
|
||||
|
||||
// Successful match. The first matcher, which succeeded, needs to
|
||||
// explain.
|
||||
m = AnyOf(GreaterThan(10), GreaterThan(20));
|
||||
EXPECT_EQ("which is 5 more than 10", Explain(m, 15));
|
||||
|
||||
// Successful match. The second matcher, which succeeded, needs to
|
||||
// explain. Since it doesn't given an explanation, nothing is
|
||||
// printed.
|
||||
m = AnyOf(GreaterThan(10), Lt(30));
|
||||
EXPECT_EQ("", Explain(m, 0));
|
||||
|
||||
// Successful match. The second matcher, which succeeded, needs to
|
||||
// explain.
|
||||
m = AnyOf(GreaterThan(30), GreaterThan(20));
|
||||
EXPECT_EQ("which is 5 more than 20", Explain(m, 25));
|
||||
}
|
||||
|
||||
// The following predicate function and predicate functor are for
|
||||
// testing the Truly(predicate) matcher.
|
||||
|
||||
@@ -2181,14 +2346,13 @@ TEST(MatcherAssertionTest, WorksWhenMatcherIsNotSatisfied) {
|
||||
// resolved.
|
||||
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Gt(10)),
|
||||
"Value of: n\n"
|
||||
"Expected: is greater than 10\n"
|
||||
"Expected: is > 10\n"
|
||||
" Actual: 5");
|
||||
n = 0;
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
EXPECT_THAT(n, ::testing::AllOf(::testing::Le(7), ::testing::Ge(5))),
|
||||
"Value of: n\n"
|
||||
"Expected: (is less than or equal to 7) and "
|
||||
"(is greater than or equal to 5)\n"
|
||||
"Expected: (is <= 7) and (is >= 5)\n"
|
||||
" Actual: 0");
|
||||
}
|
||||
|
||||
@@ -2205,7 +2369,7 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
|
||||
"Expected: does not reference the variable @");
|
||||
// Tests the "Actual" part.
|
||||
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Not(::testing::Ref(n))),
|
||||
"Actual: 0 (is located @");
|
||||
"Actual: 0, which is located @");
|
||||
}
|
||||
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
@@ -2232,7 +2396,7 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
|
||||
Matcher<int> is_greater_than_5 = Gt(5);
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_THAT(5, is_greater_than_5),
|
||||
"Value of: 5\n"
|
||||
"Expected: is greater than 5\n"
|
||||
"Expected: is > 5\n"
|
||||
" Actual: 5");
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
@@ -2407,11 +2571,11 @@ TEST_F(FloatTest, NanSensitiveFloatEqCanMatchNaN) {
|
||||
TEST_F(FloatTest, FloatEqCanDescribeSelf) {
|
||||
Matcher<float> m1 = FloatEq(2.0f);
|
||||
EXPECT_EQ("is approximately 2", Describe(m1));
|
||||
EXPECT_EQ("is not approximately 2", DescribeNegation(m1));
|
||||
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1));
|
||||
|
||||
Matcher<float> m2 = FloatEq(0.5f);
|
||||
EXPECT_EQ("is approximately 0.5", Describe(m2));
|
||||
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2));
|
||||
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2));
|
||||
|
||||
Matcher<float> m3 = FloatEq(nan1_);
|
||||
EXPECT_EQ("never matches", Describe(m3));
|
||||
@@ -2421,15 +2585,15 @@ TEST_F(FloatTest, FloatEqCanDescribeSelf) {
|
||||
TEST_F(FloatTest, NanSensitiveFloatEqCanDescribeSelf) {
|
||||
Matcher<float> m1 = NanSensitiveFloatEq(2.0f);
|
||||
EXPECT_EQ("is approximately 2", Describe(m1));
|
||||
EXPECT_EQ("is not approximately 2", DescribeNegation(m1));
|
||||
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1));
|
||||
|
||||
Matcher<float> m2 = NanSensitiveFloatEq(0.5f);
|
||||
EXPECT_EQ("is approximately 0.5", Describe(m2));
|
||||
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2));
|
||||
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2));
|
||||
|
||||
Matcher<float> m3 = NanSensitiveFloatEq(nan1_);
|
||||
EXPECT_EQ("is NaN", Describe(m3));
|
||||
EXPECT_EQ("is not NaN", DescribeNegation(m3));
|
||||
EXPECT_EQ("isn't NaN", DescribeNegation(m3));
|
||||
}
|
||||
|
||||
// Instantiate FloatingPointTest for testing doubles.
|
||||
@@ -2462,11 +2626,11 @@ TEST_F(DoubleTest, NanSensitiveDoubleEqCanMatchNaN) {
|
||||
TEST_F(DoubleTest, DoubleEqCanDescribeSelf) {
|
||||
Matcher<double> m1 = DoubleEq(2.0);
|
||||
EXPECT_EQ("is approximately 2", Describe(m1));
|
||||
EXPECT_EQ("is not approximately 2", DescribeNegation(m1));
|
||||
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1));
|
||||
|
||||
Matcher<double> m2 = DoubleEq(0.5);
|
||||
EXPECT_EQ("is approximately 0.5", Describe(m2));
|
||||
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2));
|
||||
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2));
|
||||
|
||||
Matcher<double> m3 = DoubleEq(nan1_);
|
||||
EXPECT_EQ("never matches", Describe(m3));
|
||||
@@ -2476,15 +2640,15 @@ TEST_F(DoubleTest, DoubleEqCanDescribeSelf) {
|
||||
TEST_F(DoubleTest, NanSensitiveDoubleEqCanDescribeSelf) {
|
||||
Matcher<double> m1 = NanSensitiveDoubleEq(2.0);
|
||||
EXPECT_EQ("is approximately 2", Describe(m1));
|
||||
EXPECT_EQ("is not approximately 2", DescribeNegation(m1));
|
||||
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1));
|
||||
|
||||
Matcher<double> m2 = NanSensitiveDoubleEq(0.5);
|
||||
EXPECT_EQ("is approximately 0.5", Describe(m2));
|
||||
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2));
|
||||
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2));
|
||||
|
||||
Matcher<double> m3 = NanSensitiveDoubleEq(nan1_);
|
||||
EXPECT_EQ("is NaN", Describe(m3));
|
||||
EXPECT_EQ("is not NaN", DescribeNegation(m3));
|
||||
EXPECT_EQ("isn't NaN", DescribeNegation(m3));
|
||||
}
|
||||
|
||||
TEST(PointeeTest, RawPointer) {
|
||||
@@ -2547,8 +2711,8 @@ TEST(PointeeTest, MatchesAgainstAValue) {
|
||||
|
||||
TEST(PointeeTest, CanDescribeSelf) {
|
||||
const Matcher<int*> m = Pointee(Gt(3));
|
||||
EXPECT_EQ("points to a value that is greater than 3", Describe(m));
|
||||
EXPECT_EQ("does not point to a value that is greater than 3",
|
||||
EXPECT_EQ("points to a value that is > 3", Describe(m));
|
||||
EXPECT_EQ("does not point to a value that is > 3",
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
@@ -2693,10 +2857,8 @@ TEST(FieldTest, WorksForCompatibleMatcherType) {
|
||||
TEST(FieldTest, CanDescribeSelf) {
|
||||
Matcher<const AStruct&> m = Field(&AStruct::x, Ge(0));
|
||||
|
||||
EXPECT_EQ("is an object whose given field is greater than or equal to 0",
|
||||
Describe(m));
|
||||
EXPECT_EQ("is an object whose given field is not greater than or equal to 0",
|
||||
DescribeNegation(m));
|
||||
EXPECT_EQ("is an object whose given field is >= 0", Describe(m));
|
||||
EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that Field() can explain the match result.
|
||||
@@ -2764,10 +2926,8 @@ TEST(FieldForPointerTest, WorksForArgumentOfSubType) {
|
||||
TEST(FieldForPointerTest, CanDescribeSelf) {
|
||||
Matcher<const AStruct*> m = Field(&AStruct::x, Ge(0));
|
||||
|
||||
EXPECT_EQ("is an object whose given field is greater than or equal to 0",
|
||||
Describe(m));
|
||||
EXPECT_EQ("is an object whose given field is not greater than or equal to 0",
|
||||
DescribeNegation(m));
|
||||
EXPECT_EQ("is an object whose given field is >= 0", Describe(m));
|
||||
EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that Field() can explain the result of matching a pointer.
|
||||
@@ -2900,10 +3060,9 @@ TEST(PropertyTest, WorksForCompatibleMatcherType) {
|
||||
TEST(PropertyTest, CanDescribeSelf) {
|
||||
Matcher<const AClass&> m = Property(&AClass::n, Ge(0));
|
||||
|
||||
EXPECT_EQ("is an object whose given property is greater than or equal to 0",
|
||||
Describe(m));
|
||||
EXPECT_EQ("is an object whose given property "
|
||||
"is not greater than or equal to 0", DescribeNegation(m));
|
||||
EXPECT_EQ("is an object whose given property is >= 0", Describe(m));
|
||||
EXPECT_EQ("is an object whose given property isn't >= 0",
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that Property() can explain the match result.
|
||||
@@ -2980,10 +3139,9 @@ TEST(PropertyForPointerTest, WorksForArgumentOfSubType) {
|
||||
TEST(PropertyForPointerTest, CanDescribeSelf) {
|
||||
Matcher<const AClass*> m = Property(&AClass::n, Ge(0));
|
||||
|
||||
EXPECT_EQ("is an object whose given property is greater than or equal to 0",
|
||||
Describe(m));
|
||||
EXPECT_EQ("is an object whose given property "
|
||||
"is not greater than or equal to 0", DescribeNegation(m));
|
||||
EXPECT_EQ("is an object whose given property is >= 0", Describe(m));
|
||||
EXPECT_EQ("is an object whose given property isn't >= 0",
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that Property() can explain the result of matching a pointer.
|
||||
@@ -3021,7 +3179,7 @@ TEST(ResultOfTest, CanDescribeItself) {
|
||||
EXPECT_EQ("is mapped by the given callable to a value that "
|
||||
"is equal to \"foo\"", Describe(matcher));
|
||||
EXPECT_EQ("is mapped by the given callable to a value that "
|
||||
"is not equal to \"foo\"", DescribeNegation(matcher));
|
||||
"isn't equal to \"foo\"", DescribeNegation(matcher));
|
||||
}
|
||||
|
||||
// Tests that ResultOf() can explain the match result.
|
||||
@@ -3173,7 +3331,7 @@ class DivisibleByImpl {
|
||||
// For testing using ExplainMatchResultTo() with polymorphic matchers.
|
||||
template <typename T>
|
||||
bool MatchAndExplain(const T& n, MatchResultListener* listener) const {
|
||||
*listener << "is " << (n % divider_) << " modulo "
|
||||
*listener << "which is " << (n % divider_) << " modulo "
|
||||
<< divider_;
|
||||
return (n % divider_) == 0;
|
||||
}
|
||||
@@ -3201,28 +3359,28 @@ PolymorphicMatcher<DivisibleByImpl> DivisibleBy(int n) {
|
||||
// asked to explain why.
|
||||
TEST(ExplainMatchResultTest, AllOf_False_False) {
|
||||
const Matcher<int> m = AllOf(DivisibleBy(4), DivisibleBy(3));
|
||||
EXPECT_EQ("is 1 modulo 4", Explain(m, 5));
|
||||
EXPECT_EQ("which is 1 modulo 4", Explain(m, 5));
|
||||
}
|
||||
|
||||
// Tests that when AllOf() fails, only the first failing matcher is
|
||||
// asked to explain why.
|
||||
TEST(ExplainMatchResultTest, AllOf_False_True) {
|
||||
const Matcher<int> m = AllOf(DivisibleBy(4), DivisibleBy(3));
|
||||
EXPECT_EQ("is 2 modulo 4", Explain(m, 6));
|
||||
EXPECT_EQ("which is 2 modulo 4", Explain(m, 6));
|
||||
}
|
||||
|
||||
// Tests that when AllOf() fails, only the first failing matcher is
|
||||
// asked to explain why.
|
||||
TEST(ExplainMatchResultTest, AllOf_True_False) {
|
||||
const Matcher<int> m = AllOf(Ge(1), DivisibleBy(3));
|
||||
EXPECT_EQ("is 2 modulo 3", Explain(m, 5));
|
||||
EXPECT_EQ("which is 2 modulo 3", Explain(m, 5));
|
||||
}
|
||||
|
||||
// Tests that when AllOf() succeeds, all matchers are asked to explain
|
||||
// why.
|
||||
TEST(ExplainMatchResultTest, AllOf_True_True) {
|
||||
const Matcher<int> m = AllOf(DivisibleBy(2), DivisibleBy(3));
|
||||
EXPECT_EQ("is 0 modulo 2; is 0 modulo 3", Explain(m, 6));
|
||||
EXPECT_EQ("which is 0 modulo 2, and which is 0 modulo 3", Explain(m, 6));
|
||||
}
|
||||
|
||||
TEST(ExplainMatchResultTest, AllOf_True_True_2) {
|
||||
@@ -3309,7 +3467,8 @@ TYPED_TEST(ContainerEqTest, ValueMissing) {
|
||||
TypeParam test_set(test_vals, test_vals + 4);
|
||||
const Matcher<TypeParam> m = ContainerEq(my_set);
|
||||
EXPECT_FALSE(m.Matches(test_set));
|
||||
EXPECT_EQ("Not in actual: 3", Explain(m, test_set));
|
||||
EXPECT_EQ("which doesn't have these expected elements: 3",
|
||||
Explain(m, test_set));
|
||||
}
|
||||
|
||||
// Tests that added values are reported.
|
||||
@@ -3320,7 +3479,7 @@ TYPED_TEST(ContainerEqTest, ValueAdded) {
|
||||
TypeParam test_set(test_vals, test_vals + 6);
|
||||
const Matcher<const TypeParam&> m = ContainerEq(my_set);
|
||||
EXPECT_FALSE(m.Matches(test_set));
|
||||
EXPECT_EQ("Only in actual: 46", Explain(m, test_set));
|
||||
EXPECT_EQ("which has these unexpected elements: 46", Explain(m, test_set));
|
||||
}
|
||||
|
||||
// Tests that added and missing values are reported together.
|
||||
@@ -3331,7 +3490,9 @@ TYPED_TEST(ContainerEqTest, ValueAddedAndRemoved) {
|
||||
TypeParam test_set(test_vals, test_vals + 5);
|
||||
const Matcher<TypeParam> m = ContainerEq(my_set);
|
||||
EXPECT_FALSE(m.Matches(test_set));
|
||||
EXPECT_EQ("Only in actual: 46; not in actual: 5", Explain(m, test_set));
|
||||
EXPECT_EQ("which has these unexpected elements: 46,\n"
|
||||
"and doesn't have these expected elements: 5",
|
||||
Explain(m, test_set));
|
||||
}
|
||||
|
||||
// Tests duplicated value -- expect no explanation.
|
||||
@@ -3356,7 +3517,8 @@ TEST(ContainerEqExtraTest, MultipleValuesMissing) {
|
||||
std::vector<int> test_set(test_vals, test_vals + 3);
|
||||
const Matcher<std::vector<int> > m = ContainerEq(my_set);
|
||||
EXPECT_FALSE(m.Matches(test_set));
|
||||
EXPECT_EQ("Not in actual: 3, 8", Explain(m, test_set));
|
||||
EXPECT_EQ("which doesn't have these expected elements: 3, 8",
|
||||
Explain(m, test_set));
|
||||
}
|
||||
|
||||
// Tests that added values are reported.
|
||||
@@ -3368,7 +3530,8 @@ TEST(ContainerEqExtraTest, MultipleValuesAdded) {
|
||||
std::list<size_t> test_set(test_vals, test_vals + 7);
|
||||
const Matcher<const std::list<size_t>&> m = ContainerEq(my_set);
|
||||
EXPECT_FALSE(m.Matches(test_set));
|
||||
EXPECT_EQ("Only in actual: 92, 46", Explain(m, test_set));
|
||||
EXPECT_EQ("which has these unexpected elements: 92, 46",
|
||||
Explain(m, test_set));
|
||||
}
|
||||
|
||||
// Tests that added and missing values are reported together.
|
||||
@@ -3379,7 +3542,8 @@ TEST(ContainerEqExtraTest, MultipleValuesAddedAndRemoved) {
|
||||
std::list<size_t> test_set(test_vals, test_vals + 5);
|
||||
const Matcher<const std::list<size_t> > m = ContainerEq(my_set);
|
||||
EXPECT_FALSE(m.Matches(test_set));
|
||||
EXPECT_EQ("Only in actual: 92, 46; not in actual: 5, 8",
|
||||
EXPECT_EQ("which has these unexpected elements: 92, 46,\n"
|
||||
"and doesn't have these expected elements: 5, 8",
|
||||
Explain(m, test_set));
|
||||
}
|
||||
|
||||
@@ -3412,7 +3576,8 @@ TEST(ContainerEqExtraTest, WorksForMaps) {
|
||||
EXPECT_TRUE(m.Matches(my_map));
|
||||
EXPECT_FALSE(m.Matches(test_map));
|
||||
|
||||
EXPECT_EQ("Only in actual: (0, \"aa\"); not in actual: (0, \"a\")",
|
||||
EXPECT_EQ("which has these unexpected elements: (0, \"aa\"),\n"
|
||||
"and doesn't have these expected elements: (0, \"a\")",
|
||||
Explain(m, test_map));
|
||||
}
|
||||
|
||||
@@ -3795,5 +3960,29 @@ TEST(PolymorphicMatcherTest, CanAccessImpl) {
|
||||
EXPECT_EQ(42, impl.divider());
|
||||
}
|
||||
|
||||
TEST(MatcherTupleTest, ExplainsMatchFailure) {
|
||||
stringstream ss1;
|
||||
ExplainMatchFailureTupleTo(make_tuple(Matcher<char>(Eq('a')), GreaterThan(5)),
|
||||
make_tuple('a', 10), &ss1);
|
||||
EXPECT_EQ("", ss1.str()); // Successful match.
|
||||
|
||||
stringstream ss2;
|
||||
ExplainMatchFailureTupleTo(make_tuple(GreaterThan(5), Matcher<char>(Eq('a'))),
|
||||
make_tuple(2, 'b'), &ss2);
|
||||
EXPECT_EQ(" Expected arg #0: is > 5\n"
|
||||
" Actual: 2, which is 3 less than 5\n"
|
||||
" Expected arg #1: is equal to 'a' (97)\n"
|
||||
" Actual: 'b' (98)\n",
|
||||
ss2.str()); // Failed match where both arguments need explanation.
|
||||
|
||||
stringstream ss3;
|
||||
ExplainMatchFailureTupleTo(make_tuple(GreaterThan(5), Matcher<char>(Eq('a'))),
|
||||
make_tuple(2, 'a'), &ss3);
|
||||
EXPECT_EQ(" Expected arg #0: is > 5\n"
|
||||
" Actual: 2, which is 3 less than 5\n",
|
||||
ss3.str()); // Failed match where only one argument needs
|
||||
// explanation.
|
||||
}
|
||||
|
||||
} // namespace gmock_matchers_test
|
||||
} // namespace testing
|
||||
|
||||
@@ -175,8 +175,8 @@ Google Mock tried the following 1 expectation, but it didn't match:
|
||||
|
||||
FILE:#: EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)))...
|
||||
Expected arg #0: references the variable @0x# "Hi"
|
||||
Actual: "Ho" (is located @0x#)
|
||||
Expected arg #2: is greater than or equal to 0
|
||||
Actual: "Ho", which is located @0x#
|
||||
Expected arg #2: is >= 0
|
||||
Actual: -0.1
|
||||
Expected: to be called once
|
||||
Actual: never called - unsatisfied and active
|
||||
@@ -204,7 +204,7 @@ Unexpected mock function call - returning default value.
|
||||
Google Mock tried the following 1 expectation, but it didn't match:
|
||||
|
||||
FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))...
|
||||
Expected arg #0: is greater than or equal to 2
|
||||
Expected arg #0: is >= 2
|
||||
Actual: 1
|
||||
Expected args: are a pair (x, y) where x >= y
|
||||
Actual: don't match
|
||||
|
||||
Reference in New Issue
Block a user