0
0
mirror of https://github.com/google/googletest.git synced 2025-03-20 19:03:48 +00:00

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(\ p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 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 { namespace testing {
// The ACTION*() macros trigger warning C4100 (unreferenced formal // 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. $$ // 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 { namespace testing {
// The ACTION*() macros trigger warning C4100 (unreferenced formal // The ACTION*() macros trigger warning C4100 (unreferenced formal

View File

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

View File

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

View File

@ -332,7 +332,7 @@ def _OverloadedMethodActionDiagnoser(msg):
r'(.*\n)*?' r'(.*\n)*?'
r'.*\bgmock-\w+-actions\.h:\d+:\d+: ' r'.*\bgmock-\w+-actions\.h:\d+:\d+: '
r'note: candidate function template not viable: ' r'note: candidate function template not viable: '
r'requires 1 argument, but 2 were provided') r'requires .*, but 2 (arguments )?were provided')
diagnosis = """ diagnosis = """
The second argument you gave to Invoke() is an overloaded method. Please The second argument you gave to Invoke() is an overloaded method. Please
tell your compiler which overloaded version you want to use. 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'(?P=file):(?P=line):(?P=column): error: '
r'C\+\+ requires a type specifier for all declarations' 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 = """ diagnosis = """
In a mock class template, types or typedefs defined in the base class 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;""" typedef typename Base<T>::%(type)s %(type)s;"""
return _GenericDiagnoser( for diag in _GenericDiagnoser(
'TTB', 'Type in Template Base', 'TTB', 'Type in Template Base',
[(gcc_4_3_1_regex_type_in_retval, diagnosis % {'type': 'Foo'}), [(gcc_4_3_1_regex_type_in_retval, diagnosis % {'type': 'Foo'}),
(gcc_4_4_0_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), (gcc_regex_type_of_a_param, diagnosis),
(clang_regex_type_of_retval_or_sole_param, diagnosis), (clang_regex_type_of_retval_or_sole_param, diagnosis),
(clang_regex_type_of_a_param, diagnosis % {'type': 'Foo'})], (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): def _WrongMockMethodMacroDiagnoser(msg):

View File

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

View File

@ -217,7 +217,7 @@ void ExpectationBase::CheckActionCountIfNotDone() const
ss << " and a WillRepeatedly()"; ss << " and a WillRepeatedly()";
} }
ss << "."; 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'. // manner specified by 'reaction'.
void ReportUninterestingCall(CallReaction reaction, const string& msg) { void ReportUninterestingCall(CallReaction reaction, const string& msg) {
switch (reaction) { switch (reaction) {
case ALLOW: case kAllow:
Log(INFO, msg, 3); Log(kInfo, msg, 3);
break; break;
case WARN: case kWarn:
Log(WARNING, msg, 3); Log(kWarning, msg, 3);
break; break;
default: // FAIL default: // FAIL
Expect(false, NULL, -1, msg); Expect(false, NULL, -1, msg);
@ -345,10 +345,10 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
const bool need_to_report_uninteresting_call = const bool need_to_report_uninteresting_call =
// If the user allows this uninteresting call, we print it // If the user allows this uninteresting call, we print it
// only when he wants informational messages. // 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 // If the user wants this to be a warning, we print it only
// when he wants to see warnings. // 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 // Otherwise, the user wants this to be an error, and we
// should always print detailed information in the error. // should always print detailed information in the error.
true; 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. // 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() // This definition must be kept in sync with the uses of Expect()
// and Log() in this function. // 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) { if (!need_to_report_call) {
// Perform the action without printing the call information. // Perform the action without printing the call information.
return return
@ -427,7 +428,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
} else { } else {
// We had an expected call and the matching expectation is // We had an expected call and the matching expectation is
// described in ss. // described in ss.
Log(INFO, loc.str() + ss.str(), 2); Log(kInfo, loc.str() + ss.str(), 2);
} }
return result; return result;
@ -606,21 +607,21 @@ void SetReactionOnUninterestingCalls(const void* mock_obj,
// object. // object.
void Mock::AllowUninterestingCalls(const void* mock_obj) void Mock::AllowUninterestingCalls(const void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { 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 // Tells Google Mock to warn the user about uninteresting calls on the
// given mock object. // given mock object.
void Mock::WarnUninterestingCalls(const void* mock_obj) void Mock::WarnUninterestingCalls(const void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { 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 // Tells Google Mock to fail uninteresting calls on the given mock
// object. // object.
void Mock::FailUninterestingCalls(const void* mock_obj) void Mock::FailUninterestingCalls(const void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { 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 // 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) { GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
internal::MutexLock l(&internal::g_gmock_mutex); internal::MutexLock l(&internal::g_gmock_mutex);
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ? 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 // 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) { TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
GMOCK_FLAG(verbose) = kInfoVerbosity; GMOCK_FLAG(verbose) = kInfoVerbosity;
EXPECT_TRUE(LogIsVisible(INFO)); EXPECT_TRUE(LogIsVisible(kInfo));
EXPECT_TRUE(LogIsVisible(WARNING)); EXPECT_TRUE(LogIsVisible(kWarning));
} }
TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) { TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
GMOCK_FLAG(verbose) = kErrorVerbosity; GMOCK_FLAG(verbose) = kErrorVerbosity;
EXPECT_FALSE(LogIsVisible(INFO)); EXPECT_FALSE(LogIsVisible(kInfo));
EXPECT_FALSE(LogIsVisible(WARNING)); EXPECT_FALSE(LogIsVisible(kWarning));
} }
TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) { TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
GMOCK_FLAG(verbose) = kWarningVerbosity; GMOCK_FLAG(verbose) = kWarningVerbosity;
EXPECT_FALSE(LogIsVisible(INFO)); EXPECT_FALSE(LogIsVisible(kInfo));
EXPECT_TRUE(LogIsVisible(WARNING)); EXPECT_TRUE(LogIsVisible(kWarning));
} }
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
@ -390,7 +390,7 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
if (should_print) { if (should_print) {
EXPECT_THAT(GetCapturedStdout().c_str(), EXPECT_THAT(GetCapturedStdout().c_str(),
ContainsRegex( ContainsRegex(
severity == WARNING ? severity == kWarning ?
"^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" : "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
"^\nTest log\\.\nStack trace:\n")); "^\nTest log\\.\nStack trace:\n"));
} else { } else {
@ -405,7 +405,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
const string saved_flag = GMOCK_FLAG(verbose); const string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = kInfoVerbosity; GMOCK_FLAG(verbose) = kInfoVerbosity;
CaptureStdout(); CaptureStdout();
Log(INFO, "Test log.\n", -1); Log(kInfo, "Test log.\n", -1);
EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str()); EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG(verbose) = saved_flag;
} }
@ -414,7 +414,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
// treated as 0. // treated as 0.
TEST(LogTest, NoSkippingStackFrameInOptMode) { TEST(LogTest, NoSkippingStackFrameInOptMode) {
CaptureStdout(); CaptureStdout();
Log(WARNING, "Test log.\n", 100); Log(kWarning, "Test log.\n", 100);
const String log = GetCapturedStdout(); const String log = GetCapturedStdout();
# if defined(NDEBUG) && GTEST_GOOGLE3_MODE_ # if defined(NDEBUG) && GTEST_GOOGLE3_MODE_
@ -436,29 +436,29 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
// Tests that all logs are printed when the value of the // Tests that all logs are printed when the value of the
// --gmock_verbose flag is "info". // --gmock_verbose flag is "info".
TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) { TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
TestLogWithSeverity(kInfoVerbosity, INFO, true); TestLogWithSeverity(kInfoVerbosity, kInfo, true);
TestLogWithSeverity(kInfoVerbosity, WARNING, true); TestLogWithSeverity(kInfoVerbosity, kWarning, true);
} }
// Tests that only warnings are printed when the value of the // Tests that only warnings are printed when the value of the
// --gmock_verbose flag is "warning". // --gmock_verbose flag is "warning".
TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) { TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
TestLogWithSeverity(kWarningVerbosity, INFO, false); TestLogWithSeverity(kWarningVerbosity, kInfo, false);
TestLogWithSeverity(kWarningVerbosity, WARNING, true); TestLogWithSeverity(kWarningVerbosity, kWarning, true);
} }
// Tests that no logs are printed when the value of the // Tests that no logs are printed when the value of the
// --gmock_verbose flag is "error". // --gmock_verbose flag is "error".
TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) { TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
TestLogWithSeverity(kErrorVerbosity, INFO, false); TestLogWithSeverity(kErrorVerbosity, kInfo, false);
TestLogWithSeverity(kErrorVerbosity, WARNING, false); TestLogWithSeverity(kErrorVerbosity, kWarning, false);
} }
// Tests that only warnings are printed when the value of the // Tests that only warnings are printed when the value of the
// --gmock_verbose flag is invalid. // --gmock_verbose flag is invalid.
TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
TestLogWithSeverity("invalid", INFO, false); TestLogWithSeverity("invalid", kInfo, false);
TestLogWithSeverity("invalid", WARNING, true); TestLogWithSeverity("invalid", kWarning, true);
} }
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION