Regex CMake';s PASS\u正则表达式是否匹配多行输出?

Regex CMake';s PASS\u正则表达式是否匹配多行输出?,regex,cmake,Regex,Cmake,我想通过以下方式通过CMake添加一个测试: ADD_UNIT_TEST(MyTest) set_tests_properties( MyTest PROPERTIES PASS_REGULAR_EXPRESSION "This matches the first line\n" "This matches the second line" ) 这可能吗?怎么做?我找到了这篇文章,并用文章中建议的代码修改了您的示例:

我想通过以下方式通过CMake添加一个测试:

ADD_UNIT_TEST(MyTest)
set_tests_properties(
    MyTest
    PROPERTIES
        PASS_REGULAR_EXPRESSION
           "This matches the first line\n"
           "This matches the second line"
)
这可能吗?怎么做?

我找到了这篇文章,并用文章中建议的代码修改了您的示例:

  • \n
    替换为
    [\r\n\t]*
我的CMake版本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"
)
将提供:

> ctest -C Debug
[...]
    Start 1: MyTest
1/1 Test #1: MyTest ...........................   Passed    0.03 sec
而不是(使用原始代码时):


嗯,奇怪。我的缺点是,我认为我在构建系统中使用的另一个工具导致了我的示例失败,而不是CMake本身。@modocache对任何误解表示抱歉。您的代码(如您在问题中提供的)在我的Windows环境中不起作用。我认为这是Windows上CRLF的一个问题。因此,我测试的代码(取自链接帖子)不接受要匹配的两个字符串之间的制表符
\t
、空格`
、回车符
\r`或换行符
\n
的任意组合(应适用于所有主机平台)。我已经相应地更新了我的答案。
> 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