我想通过以下方式通过CMake添加测试:
ADD_UNIT_TEST(MyTest)
set_tests_properties(
MyTest
PROPERTIES
PASS_REGULAR_EXPRESSION
"This matches the first line\n"
"This matches the second line"
)
这可能吗?怎么样?
答案 0 :(得分:4)
我发现了this帖子并使用帖子中建议的代码修改了您的示例:
\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
而不是(当使用原始代码时):
> 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