Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
d14aaed7
Commit
d14aaed7
authored
Jan 14, 2010
by
zhanyong.wan
Browse files
Enables regex matchers on all platforms.
parent
6953a725
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
52 deletions
+18
-52
include/gmock/gmock-matchers.h
include/gmock/gmock-matchers.h
+0
-8
include/gmock/internal/gmock-port.h
include/gmock/internal/gmock-port.h
+0
-18
test/gmock-matchers_test.cc
test/gmock-matchers_test.cc
+4
-9
test/gmock-spec-builders_test.cc
test/gmock-spec-builders_test.cc
+14
-13
test/gmock_link_test.h
test/gmock_link_test.h
+0
-4
No files found.
include/gmock/gmock-matchers.h
View file @
d14aaed7
...
...
@@ -1117,8 +1117,6 @@ bool MatchAndExplain(const EndsWithMatcher<StringType>& impl, T& s,
return
impl
.
Matches
(
s
);
}
#if GMOCK_HAS_REGEX
// Implements polymorphic matchers MatchesRegex(regex) and
// ContainsRegex(regex), which can be used as a Matcher<T> as long as
// T can be converted to a string.
...
...
@@ -1165,8 +1163,6 @@ bool MatchAndExplain(const MatchesRegexMatcher& impl, T& s,
return
impl
.
Matches
(
s
);
}
#endif // GMOCK_HAS_REGEX
// Implements a matcher that compares the two fields of a 2-tuple
// using one of the ==, <=, <, etc, operators. The two fields being
// compared don't have to have the same type.
...
...
@@ -2718,8 +2714,6 @@ inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
suffix
));
}
#ifdef GMOCK_HAS_REGEX
// Matches a string that fully matches regular expression 'regex'.
// The matcher takes ownership of 'regex'.
inline
PolymorphicMatcher
<
internal
::
MatchesRegexMatcher
>
MatchesRegex
(
...
...
@@ -2742,8 +2736,6 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
return
ContainsRegex
(
new
internal
::
RE
(
regex
));
}
#endif // GMOCK_HAS_REGEX
#if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
// Wide string matchers.
...
...
include/gmock/internal/gmock-port.h
View file @
d14aaed7
...
...
@@ -52,26 +52,8 @@
#if GTEST_OS_LINUX
// On some platforms, <regex.h> needs someone to define size_t, and
// won't compile otherwise. We can #include it here as we already
// included <stdlib.h>, which is guaranteed to define size_t through
// <stddef.h>.
#include <regex.h> // NOLINT
// Defines this iff Google Mock uses the enhanced POSIX regular
// expression syntax. This is public as it affects how a user uses
// regular expression matchers.
#define GMOCK_USES_POSIX_RE 1
#endif // GTEST_OS_LINUX
#if defined(GMOCK_USES_PCRE) || defined(GMOCK_USES_POSIX_RE)
// Defines this iff regular expression matchers are supported. This
// is public as it tells a user whether he can use regular expression
// matchers.
#define GMOCK_HAS_REGEX 1
#endif // defined(GMOCK_USES_PCRE) || defined(GMOCK_USES_POSIX_RE)
namespace
testing
{
namespace
internal
{
...
...
test/gmock-matchers_test.cc
View file @
d14aaed7
...
...
@@ -126,11 +126,9 @@ using testing::internal::linked_ptr;
using
testing
::
internal
::
scoped_ptr
;
using
testing
::
internal
::
string
;
#ifdef GMOCK_HAS_REGEX
using
testing
::
ContainsRegex
;
using
testing
::
MatchesRegex
;
using
testing
::
internal
::
RE
;
#endif // GMOCK_HAS_REGEX
// For testing ExplainMatchResultTo().
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
...
...
@@ -1249,8 +1247,6 @@ TEST(EndsWithTest, CanDescribeSelf) {
EXPECT_EQ
(
"ends with
\"
Hi
\"
"
,
Describe
(
m
));
}
#ifdef GMOCK_HAS_REGEX
// Tests MatchesRegex().
TEST
(
MatchesRegexTest
,
MatchesStringMatchingGivenRegex
)
{
...
...
@@ -1269,8 +1265,8 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
Matcher
<
const
std
::
string
>
m1
=
MatchesRegex
(
string
(
"Hi.*"
));
EXPECT_EQ
(
"matches regular expression
\"
Hi.*
\"
"
,
Describe
(
m1
));
Matcher
<
const
char
*>
m2
=
MatchesRegex
(
new
RE
(
"
[a-z]
.*"
));
EXPECT_EQ
(
"matches regular expression
\"
[a-z]
.*
\"
"
,
Describe
(
m2
));
Matcher
<
const
char
*>
m2
=
MatchesRegex
(
new
RE
(
"
a
.*"
));
EXPECT_EQ
(
"matches regular expression
\"
a
.*
\"
"
,
Describe
(
m2
));
}
// Tests ContainsRegex().
...
...
@@ -1291,10 +1287,9 @@ TEST(ContainsRegexTest, CanDescribeSelf) {
Matcher
<
const
std
::
string
>
m1
=
ContainsRegex
(
"Hi.*"
);
EXPECT_EQ
(
"contains regular expression
\"
Hi.*
\"
"
,
Describe
(
m1
));
Matcher
<
const
char
*>
m2
=
ContainsRegex
(
new
RE
(
"
[a-z]
.*"
));
EXPECT_EQ
(
"contains regular expression
\"
[a-z]
.*
\"
"
,
Describe
(
m2
));
Matcher
<
const
char
*>
m2
=
ContainsRegex
(
new
RE
(
"
a
.*"
));
EXPECT_EQ
(
"contains regular expression
\"
a
.*
\"
"
,
Describe
(
m2
));
}
#endif // GMOCK_HAS_REGEX
// Tests for wide strings.
#if GTEST_HAS_STD_WSTRING
...
...
test/gmock-spec-builders_test.cc
View file @
d14aaed7
...
...
@@ -68,6 +68,7 @@ using testing::AtMost;
using
testing
::
Between
;
using
testing
::
Cardinality
;
using
testing
::
CardinalityInterface
;
using
testing
::
ContainsRegex
;
using
testing
::
Const
;
using
testing
::
DoAll
;
using
testing
::
DoDefault
;
...
...
@@ -978,8 +979,6 @@ TEST(UnexpectedCallTest, UnmatchedArguments) {
b
.
DoB
(
1
);
}
#ifdef GMOCK_HAS_REGEX
// Tests that Google Mock explains that an expectation with
// unsatisfied pre-requisites doesn't match the call.
TEST
(
UnexpectedCallTest
,
UnsatisifiedPrerequisites
)
{
...
...
@@ -1010,31 +1009,33 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
// Verifies that the failure message contains the two unsatisfied
// pre-requisites but not the satisfied one.
const
char
*
const
pattern
=
#if GMOCK_USES_PCRE
#if GTEST_USES_PCRE
EXPECT_THAT
(
r
.
message
(),
ContainsRegex
(
// PCRE has trouble using (.|\n) to match any character, but
// supports the (?s) prefix for using . to match any character.
"(?s)the following immediate pre-requisites are not satisfied:
\n
"
".*: pre-requisite #0
\n
"
".*: pre-requisite #1"
;
#else
".*: pre-requisite #1"
));
#elif GTEST_USES_POSIX_RE
EXPECT_THAT
(
r
.
message
(),
ContainsRegex
(
// POSIX RE doesn't understand the (?s) prefix, but has no trouble
// with (.|\n).
"the following immediate pre-requisites are not satisfied:
\n
"
"(.|
\n
)*: pre-requisite #0
\n
"
"(.|
\n
)*: pre-requisite #1"
;
#endif // GMOCK_USES_PCRE
"(.|
\n
)*: pre-requisite #1"
));
#else
// We can only use Google Test's own simple regex.
EXPECT_THAT
(
r
.
message
(),
ContainsRegex
(
"the following immediate pre-requisites are not satisfied:"
));
EXPECT_THAT
(
r
.
message
(),
ContainsRegex
(
": pre-requisite #0"
));
EXPECT_THAT
(
r
.
message
(),
ContainsRegex
(
": pre-requisite #1"
));
#endif // GTEST_USES_PCRE
EXPECT_TRUE
(
::
testing
::
internal
::
RE
::
PartialMatch
(
r
.
message
(),
pattern
))
<<
" where the message is "
<<
r
.
message
();
b
.
DoB
(
1
);
b
.
DoB
(
3
);
b
.
DoB
(
4
);
}
#endif // GMOCK_HAS_REGEX
TEST
(
UndefinedReturnValueTest
,
ReturnValueIsMandatory
)
{
MockA
a
;
// TODO(wan@google.com): We should really verify the output message,
...
...
test/gmock_link_test.h
View file @
d14aaed7
...
...
@@ -185,10 +185,8 @@ using testing::SetErrnoAndReturn;
using
testing
::
Throw
;
#endif
#if GMOCK_HAS_REGEX
using
testing
::
ContainsRegex
;
using
testing
::
MatchesRegex
;
#endif
class
Interface
{
public:
...
...
@@ -547,7 +545,6 @@ TEST(LinkTest, TestMatchersFloatingPoint) {
.
WillByDefault
(
Return
());
}
#if GMOCK_HAS_REGEX
// Tests the linkage of the ContainsRegex matcher.
TEST
(
LinkTest
,
TestMatcherContainsRegex
)
{
Mock
mock
;
...
...
@@ -561,7 +558,6 @@ TEST(LinkTest, TestMatcherMatchesRegex) {
ON_CALL
(
mock
,
VoidFromString
(
MatchesRegex
(
".*"
))).
WillByDefault
(
Return
());
}
#endif // GMOCK_HAS_REGEX
// Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
TEST
(
LinkTest
,
TestMatchersSubstrings
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment