我想通过以下方式通过 CMake 添加测试:
ADD_UNIT_TEST(MyTest)
set_tests_properties(
MyTest
PROPERTIES
PASS_REGULAR_EXPRESSION
"This matches the first line\n"
"This matches the second line"
)
Run Code Online (Sandbox Code Playgroud)
这可能吗?如何?
我找到了这篇文章,并使用文章中建议的代码修改了您的示例:
\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"
)
Run Code Online (Sandbox Code Playgroud)
会给出:
> ctest -C Debug
[...]
Start 1: MyTest
1/1 Test #1: MyTest ........................... Passed 0.03 sec
Run Code Online (Sandbox Code Playgroud)
而不是(当使用原始代码时):
> 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
Run Code Online (Sandbox Code Playgroud)