freyc / googlemock

Automatically exported from code.google.com/p/googlemock
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

MatchesRegex and MSVC (GTEST_USES_SIMPLE_RE) #102

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

What steps will reproduce the problem?
I try to use gmock MatchesRegex on windows with vc2005.
In Google test documentation is written that on windows you use your own
simplified regex(GTEST_USES_SIMPLE_RE=1).
I think it could be valuable to use it in MatchesRegex.
I try to compile something like this:

TCHAR result[] =_T("Line 855");
EXPECT_THAT(result, ::testing::MatchesRegex(_T("Line \\d+")));
But I can’t.

What is the expected output? What do you see instead?
I get following errors:
error C2039: 'MatchesRegex' : is not a member of 'testing'
error C3861: 'MatchesRegex': identifier not found
error C2248: 'testing::AssertionResult::AssertionResult' : cannot access
private member declared in class 'testing::AssertionResult'

Any advice is welcome.

What version of the product are you using? On what operating system?
winxp, msvc2005, gmock 1.4.0

Original issue reported on code.google.com by pmi...@gmail.com on 4 Mar 2010 at 3:38

GoogleCodeExporter commented 9 years ago
This was already fixed in the trunk.  Will be part of release 1.5.0.

Original comment by w...@google.com on 4 Mar 2010 at 5:29

GoogleCodeExporter commented 9 years ago
When do you expect official release on 1.5.0?
Has it been settled already?

Original comment by pmi...@gmail.com on 5 Mar 2010 at 6:07

GoogleCodeExporter commented 9 years ago
In the next several weeks.  You can use the code from the SVN today if you 
can't wait.

Original comment by w...@google.com on 5 Mar 2010 at 6:09

GoogleCodeExporter commented 9 years ago
I got version from svn and tried it.
I tried to compile following tests:
TEST(MSVC_MatchesRegex, ansi)
{
  char res[]="line 123";
  EXPECT_THAT(res, ::testing::MatchesRegex("line \\d+"));
}

TEST(MSVC_MatchesRegex, wide)
{
  wchar_t res[]=L"line 123";
  EXPECT_THAT(res, ::testing::MatchesRegex(L"line \\d+"));
}

TEST(MSVC_MatchesRegex, tchar)
{
  TCHAR res[]=L"line 123";
  EXPECT_THAT(res, ::testing::MatchesRegex(_T("line \\d+")));
}

I got errors for version with wide chars:
error C2665: 'testing::MatchesRegex' : none of the 2 overloads could convert 
all the
argument types
C2512: 'testing::AssertionResult' : no appropriate default constructor available

It seems that it doesn't work with wide chars wchar_t.
Is there any workaround or what am I doing wrong?

Original comment by pmi...@gmail.com on 5 Mar 2010 at 8:37

GoogleCodeExporter commented 9 years ago
I also find out that I can use backslash in regex used in windows version regex.

TEST(MSVC_MatchesRegex, backslash)
{
    char res[]="\\Device\\HarddiskVolume1\\windows\\system32\\hal.dll";
    EXPECT_THAT(res,
::testing::MatchesRegex("\\Device\\HarddiskVolume\\d+\\windows\\system32\\hal.dl
l"));
}

Is it possible?
I can't find it here
http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide#Regular_Express
ion_Syntax
If not what about to define new escape code for example \\\ for \\.

Original comment by pmi...@gmail.com on 5 Mar 2010 at 9:51

GoogleCodeExporter commented 9 years ago
No, we don't support wide string.  You need to convert it to narrow string 
yourself.

Write \\\\ to match a single \.  This is standard in C++ regular expressions.

Original comment by w...@google.com on 5 Mar 2010 at 5:21

GoogleCodeExporter commented 9 years ago
>No, we don't support wide string.  You need to convert it to narrow string 
yourself.
Do you plan to add support for wide string MatchesRegex?

Original comment by pmi...@gmail.com on 8 Mar 2010 at 6:41

GoogleCodeExporter commented 9 years ago
No, we don't.  Unless someone contributes a patch.

Original comment by w...@google.com on 8 Mar 2010 at 8:51

GoogleCodeExporter commented 9 years ago
Is this issue related just to Windows platform or all platforms (meaning that 
it is
design of Your internal regex implementation)?

Original comment by pmi...@gmail.com on 8 Mar 2010 at 9:45