Enables regex matchers on all platforms.

This commit is contained in:
zhanyong.wan
2010-01-14 05:36:32 +00:00
parent 6953a725fc
commit d14aaed74b
5 changed files with 18 additions and 52 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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) {