Pulls in gtest r615.

Renames internal enums to the kFoo naming style.

Fixes gmock doctor to work with newer versions of Clang.
This commit is contained in:
zhanyong.wan 2012-05-31 20:40:56 +00:00
parent 79a367eb21
commit 2fd619edd3
8 changed files with 61 additions and 57 deletions

View File

@ -2216,9 +2216,6 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
// TODO(wan@google.com): move the following to a different .h file
// such that we don't have to run 'pump' every time the code is
// updated.
namespace testing {
// The ACTION*() macros trigger warning C4100 (unreferenced formal

View File

@ -739,9 +739,6 @@ $$ } // This meta comment fixes auto-indentation in Emacs. It won't
$$ // show up in the generated code.
// TODO(wan@google.com): move the following to a different .h file
// such that we don't have to run 'pump' every time the code is
// updated.
namespace testing {
// The ACTION*() macros trigger warning C4100 (unreferenced formal

View File

@ -353,12 +353,11 @@ class OnCallSpec : public UntypedOnCallSpecBase {
Action<F> action_;
}; // class OnCallSpec
// Possible reactions on uninteresting calls. TODO(wan@google.com):
// rename the enum values to the kFoo style.
// Possible reactions on uninteresting calls.
enum CallReaction {
ALLOW,
WARN,
FAIL
kAllow,
kWarn,
kFail
};
} // namespace internal
@ -422,7 +421,7 @@ class GTEST_API_ Mock {
// Returns the reaction Google Mock will have on uninteresting calls
// made on the given mock object.
static internal::CallReaction GetReactionOnUninterestingCalls(
const void* mock_obj);
const void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
// Verifies that all expectations on the given mock object have been
@ -1163,7 +1162,7 @@ class TypedExpectation : public ExpectationBase {
<< action_count << " WillOnce()"
<< (action_count == 1 ? " is" : "s are") << " specified - ";
mocker->DescribeDefaultActionTo(args, &ss);
Log(WARNING, ss.str(), 1);
Log(kWarning, ss.str(), 1);
}
return count <= action_count ?
@ -1251,7 +1250,7 @@ class MockSpec {
// the newly created spec.
internal::OnCallSpec<F>& InternalDefaultActionSetAt(
const char* file, int line, const char* obj, const char* call) {
LogWithLocation(internal::INFO, file, line,
LogWithLocation(internal::kInfo, file, line,
string("ON_CALL(") + obj + ", " + call + ") invoked");
return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
}
@ -1261,7 +1260,7 @@ class MockSpec {
internal::TypedExpectation<F>& InternalExpectedAt(
const char* file, int line, const char* obj, const char* call) {
const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
LogWithLocation(internal::INFO, file, line, source_text + " invoked");
LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
return function_mocker_->AddNewExpectation(
file, line, source_text, matchers_);
}

View File

@ -260,7 +260,7 @@ class FailureReporterInterface {
public:
// The type of a failure (either non-fatal or fatal).
enum FailureType {
NONFATAL, FATAL
kNonfatal, kFatal
};
virtual ~FailureReporterInterface() {}
@ -281,7 +281,7 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter();
inline void Assert(bool condition, const char* file, int line,
const string& msg) {
if (!condition) {
GetFailureReporter()->ReportFailure(FailureReporterInterface::FATAL,
GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
file, line, msg);
}
}
@ -294,7 +294,7 @@ inline void Assert(bool condition, const char* file, int line) {
inline void Expect(bool condition, const char* file, int line,
const string& msg) {
if (!condition) {
GetFailureReporter()->ReportFailure(FailureReporterInterface::NONFATAL,
GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
file, line, msg);
}
}
@ -304,8 +304,8 @@ inline void Expect(bool condition, const char* file, int line) {
// Severity level of a log.
enum LogSeverity {
INFO = 0,
WARNING = 1
kInfo = 0,
kWarning = 1
};
// Valid values for the --gmock_verbose flag.

View File

@ -332,7 +332,7 @@ def _OverloadedMethodActionDiagnoser(msg):
r'(.*\n)*?'
r'.*\bgmock-\w+-actions\.h:\d+:\d+: '
r'note: candidate function template not viable: '
r'requires 1 argument, but 2 were provided')
r'requires .*, but 2 (arguments )?were provided')
diagnosis = """
The second argument you gave to Invoke() is an overloaded method. Please
tell your compiler which overloaded version you want to use.
@ -474,6 +474,10 @@ def _TypeInTemplatedBaseDiagnoser(msg):
r'(?P=file):(?P=line):(?P=column): error: '
r'C\+\+ requires a type specifier for all declarations'
)
clang_regex_unknown_type = (
_CLANG_FILE_LINE_RE +
r'error: unknown type name \'(?P<type>[^\']+)\''
)
diagnosis = """
In a mock class template, types or typedefs defined in the base class
@ -483,7 +487,7 @@ need to make it visible. One way to do it is:
typedef typename Base<T>::%(type)s %(type)s;"""
return _GenericDiagnoser(
for diag in _GenericDiagnoser(
'TTB', 'Type in Template Base',
[(gcc_4_3_1_regex_type_in_retval, diagnosis % {'type': 'Foo'}),
(gcc_4_4_0_regex_type_in_retval, diagnosis % {'type': 'Foo'}),
@ -491,7 +495,13 @@ need to make it visible. One way to do it is:
(gcc_regex_type_of_a_param, diagnosis),
(clang_regex_type_of_retval_or_sole_param, diagnosis),
(clang_regex_type_of_a_param, diagnosis % {'type': 'Foo'})],
msg)
msg):
yield diag
# Avoid overlap with the NUS pattern.
for m in _FindAllMatches(clang_regex_unknown_type, msg):
type_ = m.groupdict()['type']
if type_ not in _COMMON_GMOCK_SYMBOLS:
yield ('TTB', 'Type in Template Base', diagnosis % m.groupdict())
def _WrongMockMethodMacroDiagnoser(msg):

View File

@ -77,13 +77,13 @@ class GoogleTestFailureReporter : public FailureReporterInterface {
public:
virtual void ReportFailure(FailureType type, const char* file, int line,
const string& message) {
AssertHelper(type == FATAL ?
AssertHelper(type == kFatal ?
TestPartResult::kFatalFailure :
TestPartResult::kNonFatalFailure,
file,
line,
message.c_str()) = Message();
if (type == FATAL) {
if (type == kFatal) {
posix::Abort();
}
}
@ -117,7 +117,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
} else {
// If --gmock_verbose is neither "info" nor "error", we treat it
// as "warning" (its default value).
return severity == WARNING;
return severity == kWarning;
}
}
@ -140,7 +140,7 @@ GTEST_API_ void Log(LogSeverity severity,
// "using ::std::cout;" doesn't work with Symbian's STLport, where cout is a
// macro.
if (severity == WARNING) {
if (severity == kWarning) {
// Prints a GMOCK WARNING marker to make the warnings easily searchable.
std::cout << "\nGMOCK WARNING:";
}

View File

@ -217,7 +217,7 @@ void ExpectationBase::CheckActionCountIfNotDone() const
ss << " and a WillRepeatedly()";
}
ss << ".";
Log(WARNING, ss.str(), -1); // -1 means "don't print stack trace".
Log(kWarning, ss.str(), -1); // -1 means "don't print stack trace".
}
}
@ -246,11 +246,11 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
// manner specified by 'reaction'.
void ReportUninterestingCall(CallReaction reaction, const string& msg) {
switch (reaction) {
case ALLOW:
Log(INFO, msg, 3);
case kAllow:
Log(kInfo, msg, 3);
break;
case WARN:
Log(WARNING, msg, 3);
case kWarn:
Log(kWarning, msg, 3);
break;
default: // FAIL
Expect(false, NULL, -1, msg);
@ -345,10 +345,10 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
const bool need_to_report_uninteresting_call =
// If the user allows this uninteresting call, we print it
// only when he wants informational messages.
reaction == ALLOW ? LogIsVisible(INFO) :
reaction == kAllow ? LogIsVisible(kInfo) :
// If the user wants this to be a warning, we print it only
// when he wants to see warnings.
reaction == WARN ? LogIsVisible(WARNING) :
reaction == kWarn ? LogIsVisible(kWarning) :
// Otherwise, the user wants this to be an error, and we
// should always print detailed information in the error.
true;
@ -391,7 +391,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
// True iff we need to print the call's arguments and return value.
// This definition must be kept in sync with the uses of Expect()
// and Log() in this function.
const bool need_to_report_call = !found || is_excessive || LogIsVisible(INFO);
const bool need_to_report_call =
!found || is_excessive || LogIsVisible(kInfo);
if (!need_to_report_call) {
// Perform the action without printing the call information.
return
@ -427,7 +428,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
} else {
// We had an expected call and the matching expectation is
// described in ss.
Log(INFO, loc.str() + ss.str(), 2);
Log(kInfo, loc.str() + ss.str(), 2);
}
return result;
@ -606,21 +607,21 @@ void SetReactionOnUninterestingCalls(const void* mock_obj,
// object.
void Mock::AllowUninterestingCalls(const void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
SetReactionOnUninterestingCalls(mock_obj, internal::ALLOW);
SetReactionOnUninterestingCalls(mock_obj, internal::kAllow);
}
// Tells Google Mock to warn the user about uninteresting calls on the
// given mock object.
void Mock::WarnUninterestingCalls(const void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
SetReactionOnUninterestingCalls(mock_obj, internal::WARN);
SetReactionOnUninterestingCalls(mock_obj, internal::kWarn);
}
// Tells Google Mock to fail uninteresting calls on the given mock
// object.
void Mock::FailUninterestingCalls(const void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
SetReactionOnUninterestingCalls(mock_obj, internal::FAIL);
SetReactionOnUninterestingCalls(mock_obj, internal::kFail);
}
// Tells Google Mock the given mock object is being destroyed and its
@ -638,7 +639,7 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
internal::MutexLock l(&internal::g_gmock_mutex);
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
internal::WARN : g_uninteresting_call_reaction[mock_obj];
internal::kWarn : g_uninteresting_call_reaction[mock_obj];
}
// Tells Google Mock to ignore mock_obj when checking for leaked mock

View File

@ -359,20 +359,20 @@ class LogIsVisibleTest : public ::testing::Test {
TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
GMOCK_FLAG(verbose) = kInfoVerbosity;
EXPECT_TRUE(LogIsVisible(INFO));
EXPECT_TRUE(LogIsVisible(WARNING));
EXPECT_TRUE(LogIsVisible(kInfo));
EXPECT_TRUE(LogIsVisible(kWarning));
}
TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
GMOCK_FLAG(verbose) = kErrorVerbosity;
EXPECT_FALSE(LogIsVisible(INFO));
EXPECT_FALSE(LogIsVisible(WARNING));
EXPECT_FALSE(LogIsVisible(kInfo));
EXPECT_FALSE(LogIsVisible(kWarning));
}
TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
GMOCK_FLAG(verbose) = kWarningVerbosity;
EXPECT_FALSE(LogIsVisible(INFO));
EXPECT_TRUE(LogIsVisible(WARNING));
EXPECT_FALSE(LogIsVisible(kInfo));
EXPECT_TRUE(LogIsVisible(kWarning));
}
#if GTEST_HAS_STREAM_REDIRECTION
@ -390,7 +390,7 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
if (should_print) {
EXPECT_THAT(GetCapturedStdout().c_str(),
ContainsRegex(
severity == WARNING ?
severity == kWarning ?
"^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
"^\nTest log\\.\nStack trace:\n"));
} else {
@ -405,7 +405,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
const string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = kInfoVerbosity;
CaptureStdout();
Log(INFO, "Test log.\n", -1);
Log(kInfo, "Test log.\n", -1);
EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
GMOCK_FLAG(verbose) = saved_flag;
}
@ -414,7 +414,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
// treated as 0.
TEST(LogTest, NoSkippingStackFrameInOptMode) {
CaptureStdout();
Log(WARNING, "Test log.\n", 100);
Log(kWarning, "Test log.\n", 100);
const String log = GetCapturedStdout();
# if defined(NDEBUG) && GTEST_GOOGLE3_MODE_
@ -436,29 +436,29 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
// Tests that all logs are printed when the value of the
// --gmock_verbose flag is "info".
TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
TestLogWithSeverity(kInfoVerbosity, INFO, true);
TestLogWithSeverity(kInfoVerbosity, WARNING, true);
TestLogWithSeverity(kInfoVerbosity, kInfo, true);
TestLogWithSeverity(kInfoVerbosity, kWarning, true);
}
// Tests that only warnings are printed when the value of the
// --gmock_verbose flag is "warning".
TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
TestLogWithSeverity(kWarningVerbosity, INFO, false);
TestLogWithSeverity(kWarningVerbosity, WARNING, true);
TestLogWithSeverity(kWarningVerbosity, kInfo, false);
TestLogWithSeverity(kWarningVerbosity, kWarning, true);
}
// Tests that no logs are printed when the value of the
// --gmock_verbose flag is "error".
TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
TestLogWithSeverity(kErrorVerbosity, INFO, false);
TestLogWithSeverity(kErrorVerbosity, WARNING, false);
TestLogWithSeverity(kErrorVerbosity, kInfo, false);
TestLogWithSeverity(kErrorVerbosity, kWarning, false);
}
// Tests that only warnings are printed when the value of the
// --gmock_verbose flag is invalid.
TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
TestLogWithSeverity("invalid", INFO, false);
TestLogWithSeverity("invalid", WARNING, true);
TestLogWithSeverity("invalid", kInfo, false);
TestLogWithSeverity("invalid", kWarning, true);
}
#endif // GTEST_HAS_STREAM_REDIRECTION