Merge 6cc5825e84d35069f98a2c7fcc4602246413e690 into 67cc66080d64e3fa5124fe57ed0cf15e2cecfdeb

This commit is contained in:
pgrzech1 2020-03-26 01:05:17 -04:00 committed by GitHub
commit 3f5c6adb5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -706,6 +706,7 @@ class GTEST_API_ ExpectationBase {
const char* file() const { return file_; } const char* file() const { return file_; }
int line() const { return line_; } int line() const { return line_; }
const char* source_text() const { return source_text_.c_str(); } const char* source_text() const { return source_text_.c_str(); }
std::string extra_info() const { return extra_info_.str(); }
// Returns the cardinality specified in the expectation spec. // Returns the cardinality specified in the expectation spec.
const Cardinality& cardinality() const { return cardinality_; } const Cardinality& cardinality() const { return cardinality_; }
@ -719,6 +720,11 @@ class GTEST_API_ ExpectationBase {
void DescribeCallCountTo(::std::ostream* os) const void DescribeCallCountTo(::std::ostream* os) const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
template<typename TYPE>
::std::ostream& operator<<(const TYPE& obj) {
return extra_info_ << obj;
}
// If this mock method has an extra matcher (i.e. .With(matcher)), // If this mock method has an extra matcher (i.e. .With(matcher)),
// describes it to the ostream. // describes it to the ostream.
virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0; virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
@ -857,6 +863,7 @@ class GTEST_API_ ExpectationBase {
const char* file_; // The file that contains the expectation. const char* file_; // The file that contains the expectation.
int line_; // The line number of the expectation. int line_; // The line number of the expectation.
const std::string source_text_; // The EXPECT_CALL(...) source text. const std::string source_text_; // The EXPECT_CALL(...) source text.
::std::ostringstream extra_info_; // extra context attached to the expectation.
// True if and only if the cardinality is specified explicitly. // True if and only if the cardinality is specified explicitly.
bool cardinality_specified_; bool cardinality_specified_;
Cardinality cardinality_; // The cardinality of the expectation. Cardinality cardinality_; // The cardinality of the expectation.
@ -1173,7 +1180,15 @@ class TypedExpectation : public ExpectationBase {
// we warn the user when the WillOnce() clauses ran out. // we warn the user when the WillOnce() clauses ran out.
::std::stringstream ss; ::std::stringstream ss;
DescribeLocationTo(&ss); DescribeLocationTo(&ss);
ss << "Actions ran out in " << source_text() << "...\n"
ss << "Actions ran out in " << source_text();
std::string context(extra_info());
if (context.size() > 0) {
ss << " with [" + context + "]";
}
ss << "...\n"
<< "Called " << count << " times, but only " << "Called " << count << " times, but only "
<< action_count << " WillOnce()" << action_count << " WillOnce()"
<< (action_count == 1 ? " is" : "s are") << " specified - "; << (action_count == 1 ? " is" : "s are") << " specified - ";
@ -1218,7 +1233,14 @@ class TypedExpectation : public ExpectationBase {
} }
// Must be done after IncrementCount()! // Must be done after IncrementCount()!
*what << "Mock function call matches " << source_text() <<"...\n"; *what << "Mock function call matches " << source_text();
std::string context(extra_info());
if (context.size() > 0) {
*what << " with [" + context + "]";
}
*what << "...\n";
return &(GetCurrentAction(mocker, args)); return &(GetCurrentAction(mocker, args));
} }
@ -1773,7 +1795,14 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase {
if (count > 1) { if (count > 1) {
*why << "tried expectation #" << i << ": "; *why << "tried expectation #" << i << ": ";
} }
*why << expectation->source_text() << "...\n"; *why << expectation->source_text();
std::string context(expectation->extra_info());
if (context.size() > 0) {
*why << " with [" + context + "]";
}
*why << "...\n";
expectation->ExplainMatchResultTo(args, why); expectation->ExplainMatchResultTo(args, why);
expectation->DescribeCallCountTo(why); expectation->DescribeCallCountTo(why);
} }