为什么ctests通过此“失败”。即使在失败_regular_expression时测试不匹配?

发布于 2025-02-12 05:36:31 字数 1261 浏览 2 评论 0原文

我在.cmake文件中使用以下几行添加了一个简单的测试:

add_test( NAME ktxsc-test-many-in-one-out
    COMMAND ktxsc -o foo a.ktx2 b.ktx2 c.ktx2
)
set_tests_properties(
    ktxsc-test-many-in-one-out
PROPERTIES
    WILL_FAIL TRUE
    FAIL_REGULAR_EXPRESSION "^Can't use -o when there are multiple infiles."
)

测试传递,testlog显示

----------------------------------------------------------
Test Pass Reason:
Error regular expression found in output. Regex=[^Can't use -o when there are multiple infiles.]
"ktxsc-test-many-in-one-out" end time: Jun 30 16:34 JST
"ktxsc-test-many-in-one-out" time elapsed: 00:00:00
----------------------------------------------------------

我是否将fail_regular_expression转换为

FAIL_REGULAR_EXPRESSION "some rubbish"

测试,即使即使应用与以前打印相同的消息。这次,测试日志显示了

----------------------------------------------------------
Test Passed.
"ktxsc-test-many-in-one-out" end time: Jun 30 16:53 JST
"ktxsc-test-many-in-one-out" time elapsed: 00:00:00
----------------------------------------------------------

我通常在没有*_常规_expression时通常看到的。

为什么会发生这种情况?当fail_regular_expression与不匹配时,如何使CTEST失败测试?

I added a simple test to ctest with the following lines in a .cmake file:

add_test( NAME ktxsc-test-many-in-one-out
    COMMAND ktxsc -o foo a.ktx2 b.ktx2 c.ktx2
)
set_tests_properties(
    ktxsc-test-many-in-one-out
PROPERTIES
    WILL_FAIL TRUE
    FAIL_REGULAR_EXPRESSION "^Can't use -o when there are multiple infiles."
)

The test passes and the TestLog shows

----------------------------------------------------------
Test Pass Reason:
Error regular expression found in output. Regex=[^Can't use -o when there are multiple infiles.]
"ktxsc-test-many-in-one-out" end time: Jun 30 16:34 JST
"ktxsc-test-many-in-one-out" time elapsed: 00:00:00
----------------------------------------------------------

If I change FAIL_REGULAR_EXPRESSION to

FAIL_REGULAR_EXPRESSION "some rubbish"

the test still passes even though the app is printing the same message as before. This time the test log shows

----------------------------------------------------------
Test Passed.
"ktxsc-test-many-in-one-out" end time: Jun 30 16:53 JST
"ktxsc-test-many-in-one-out" time elapsed: 00:00:00
----------------------------------------------------------

which is what I normally see when no *_REGULAR_EXPRESSION is set.

Why is this happening? How can I get ctest to fail the test when the FAIL_REGULAR_EXPRESSION doesn't match?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二手情话 2025-02-19 05:36:31

感谢@tsyvarev的答案。

CTEST正在做

match FAIL_REGULAR_EXPRESSION || exit code != 0

确定测试是否失败。如果比赛成功,则未检查退出代码。如果比赛失败,则将检查退出代码,并忽略了失败的匹配。

该文档尚不清楚。我已经阅读了很多次,直到@tsyvarev朝正确的方向转向正确的方向。我也发现这是一个糟糕的行为选择。我所有的工具在存在错误条件时都输出非零错误代码和消息。我需要两者都测试。我之前曾问过这个问题。它需要重复测试。

Thanks to @Tsyvarev for this answer.

ctest is doing

match FAIL_REGULAR_EXPRESSION || exit code != 0

to determine if a test has failed. If the match succeeds the exit code is not checked. If the match fails the exit code is checked and the failed match is ignored.

The documentation is unclear. I've read it many times and still didn't figure out this behavior until steered in the right direction by @Tsyvarev. I also find this a poor behavioral choice. All my tools output both a non-zero error code and a message when there is an error condition. I need to test both. I previously asked this question about that. It requires duplicating tests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文