Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can CMake's PASS_REGULAR_EXPRESSION match multiple lines of output?

Tags:

regex

cmake

I'd like to add a test via CMake in the following manner:

ADD_UNIT_TEST(MyTest)
set_tests_properties(
    MyTest
    PROPERTIES
        PASS_REGULAR_EXPRESSION
           "This matches the first line\n"
           "This matches the second line"
)

Is this possible? How?

like image 240
modocache Avatar asked Jun 26 '16 04:06

modocache


1 Answers

I've found this post and modified your example with the code suggested in the post:

  • Replaced \n with [\r\n\t ]*

The following did work successfully with my CMake version 3.5.2:

cmake_minimum_required(VERSION 3.5)

project(RegExMultiLine)

enable_testing()

add_test(
    NAME 
        MyTest 
    COMMAND 
        ${CMAKE_COMMAND} -E echo 
            "Some other line\n"
            "This matches the first line\n"
            "This matches the second line\n"
            "Another line"
)

set_tests_properties(
    MyTest
    PROPERTIES
        PASS_REGULAR_EXPRESSION
           "This matches the first line[\r\n\t ]*This matches the second line"
)

Would give:

> ctest -C Debug
[...]
    Start 1: MyTest
1/1 Test #1: MyTest ...........................   Passed    0.03 sec

Instead of (when using your original code):

> ctest -C Debug
[...]
    Start 1: MyTest
1/1 Test #1: MyTest ...........................***Failed  Required regular expression not found.Regex=[This matches the first line
This matches the second line
]  0.03 sec
like image 166
Florian Avatar answered Nov 15 '22 06:11

Florian