PASS_REGULAR_EXPRESSION 在 CMake 中

PASS_REGULAR_EXPRESSION in CMake

我一直在阅读 CMake tutorial

"Installing and Testing (Step 3)" 部分有以下测试脚本:

add_test (TutorialComp25 Tutorial 25)
set_tests_properties (TutorialComp25 
  PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5")

根据 CMake 文档,add_test 很简单,但我不了解 set_tests_properties 是如何工作的;特别是这个“25 是 5”。

听起来像

if (INPUT_ARG is OUTPUT_RESULT)
  test passed
else
  test failed

对吗?

来自 PASS_REGULAR_EXPRESSION 的文档:

The output must match this regular expression for the test to pass.

If set, the test output will be checked against the specified regular expressions and at least one of the regular expressions has to match, otherwise the test will fail.

教程示例的第一个测试(称为 TutorialRuns)没有设置任何属性。这意味着如果 Tutorial exe returns 0 完成时,CTest 将把测试视为已通过,已通过参数 25.

第二次测试,调用

set_tests_properties (TutorialComp25 PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5")

意味着来自 运行 的控制台输出 Tutorial arg 为 25 的 exe 必须包含字符串 "25 is 5" 才能被视为通过。 return 值在这种情况下被忽略。由于测试exe输出:

The square root of 25 is 5

它通过了。

请记住,这是应用的正则表达式。如果 PASS_REGULAR_EXPRESSION 设置为例如"^25 is 5",测试会失败,因为这是在输出的 start 处寻找短语 25 is 5string 命令的文档中有 CMake 的正则表达式语法的简要说明。