Cmake Cte​​st 仅检查子字符串

问题描述

我对 cmake ctest 有问题。我正在检查完整字符串中的子字符串。但是遇到了找不到字符串的问题。如何指定只查找子字符串而不是完整字符串?

neg_message="App error: Error code=5"
set_tests_properties(test_app PROPERTIES
        FAIL_REGULAR_EXPRESSION "${neg_message}")

App error: Error code=5,Index=1,Line number=1389,aborting...
1/1 Test #1: test_neg_app ..............***Failed  Error regular expression found in output. Regex=[App error: Error code=5]  1.32 sec

解决方法

FAIL_REGULAR_EXPRESSION

匹配消息前后的任何内容,以便正则表达式匹配它。

... FAIL_REGULAR_EXPRESSION ".*${neg_message}.*")
,

这个话题可以关闭了。我必须使用 PASS_REGULAR_EXPRESSION 而不是 FAIL_REGULAR_EXPRESSION 来检查预期的子字符串。无需额外命令即可正常工作。