我想以以下方式通过CMake添加一个测试:
ADD_UNIT_TEST(MyTest)
set_tests_properties(
MyTest
PROPERTIES
PASS_REGULAR_EXPRESSION
"This matches the first line\n"
"This matches the second line"
)
这个是可能的吗?多么?
发布于 2016-07-03 18:39:52
我找到了这帖子,并用文章中建议的代码修改了示例:
\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
https://stackoverflow.com/questions/38035328
复制相似问题