It should work.<br><br>But I'm pretty sure we don't recognize "\s" for white space. Try "[ \\t\\n\\r]" instead of \\s.<br><br>But..... watch out for white space after "(" and before ")" too. You might miss some lines if they have spaces there.<br>
<br><br><div class="gmail_quote">On Fri, Jan 7, 2011 at 2:55 PM, Ben Medina <span dir="ltr"><<a href="mailto:ben.medina@gmail.com">ben.medina@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I need to parse a C++ file for Google Test macros. (I'm aware the<br>
GTEST_ADD_TESTS provided by FindGtest.cmake, but I need the test list<br>
for my own purposes). I had been using a regex similar to the one in<br>
GTEST_ADD_TESTS to match tests:<br>
<br>
string (REGEX MATCHALL "TEST_?F?\\([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})<br>
<br>
But this doesn't work when the test is split onto two lines, like this:<br>
<br>
TEST(SampleTest,\<br>
MultilineTest)<br>
<br>
So, I've been trying to build a regex that will match tests split onto<br>
multiple lines. This should work:<br>
<br>
string (REGEX MATCHALL "TEST_?F?\\([A-Za-z_0-9<br>
]+,[\\s\\\\]*[A-Za-z_0-9 ]+\\)" found_tests ${contents})<br>
<br>
After the comma, the regex should greedily match all whitespace<br>
(including newlines) via the "\\s" and backslashes via the "\\\\"<br>
(Note that all special characters are escaped). This works in other<br>
regex engines, but fails in CMake.<br>
<br>
Is this possible in CMake, or do I need to use another tool?<br>
<br>
Here is my test file (named tests.cpp):<br>
<br>
TEST(SampleTest, SingleLineTest)<br>
TEST(SampleTest,\<br>
MultilineTest)<br>
TEST_F(SampleTest, SingleLineFixtureTest)<br>
TEST_F(SampleTest,\<br>
MultilineFixtureTest)<br>
<br>
And my CMakeLists.txt:<br>
<br>
cmake_minimum_required (VERSION 2.8)<br>
<br>
file (READ "tests.cpp" contents)<br>
string (REGEX MATCHALL "TEST_?F?\\([A-Za-z_0-9<br>
]+,[\\s\\\\]*[A-Za-z_0-9 ]+\\)" found_tests ${contents})<br>
message ("Found tests:")<br>
foreach (test ${found_tests})<br>
message ("${test}")<br>
endforeach ()<br>
<br>
Thanks,<br>
Ben<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div><br>