google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.58k stars 10.1k forks source link

MatchesRegEx doesn't seem to work. #3084

Open ronaldfenner opened 3 years ago

ronaldfenner commented 3 years ago

I'm trying to to use MatchesRegEx to match a date but it always returns failed. I'm run this test on MacOS so it's a posix system but i'm just trying to use the simplified syntax so i don't have to have 2 versions.

The code I'm trying to use is EXPECT_THAT(Log::GenerateISO8601Time(true), ::testing::MatchesRegex("\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ"));

I figured maybe it wasn't correct so i went to a simple test for just EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex("\\d+"));

It also doesn't work.

This does work though EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex("2020")); EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex(".+"));

I did browse through the chromium repo looking at its use of MatchesRegEx. I'm also using bazel as the build system so it build gtest as a dependency of the test.

theShmoo commented 3 years ago

For me, it works with [0-9] instead of \\d (using current trunk build: a3460d1aeeaa43fdf137a6adefef10ba0b59fe4b)

tntljc commented 2 years ago

I found this issue only appeared on Linux + gcc. \d works on Windows.

snakethatlovesstaticlibs commented 1 year ago

Also having this issue on 1.11, using [0-9] fixed it but was unpleasant to debug

GCUGreyArea commented 1 year ago

Same problem. EXPECT_THAT("name 1", MatchesRegex("name \\d+")); fails!

schmidt-sebastian commented 1 year ago

\d+ works for me on Windows, but not [0-9]+ :(

Kikadass commented 1 year ago

As per the documentation, Windows works differently:

On Windows, GoogleTest uses its own simple regular expression implementation. It lacks many features. For example, we don't support union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and repetition count ("x{5,7}"), among others. Below is what we do support (A denotes a literal character, period (.), or a single \ escape sequence; x and y denote regular expressions.):

https://github.com/google/googletest/blob/main/docs/advanced.md#regular-expression-syntax

cmorty commented 1 month ago

This is kind of annoying as \d+ is one of the examples: http://google.github.io/googletest/reference/assertions.html#EXPECT_THAT

cmorty commented 1 month ago

Here is a testcase that fails due to this issue:

As as I get the SLA sorted out I'll open a MR. :-) Or anyone else may "reproduce" those few lines. ;)