使用ctest/cmake测试非零退出状态 [英] test for non-zero exit status using ctest/cmake

查看:77
本文介绍了使用ctest/cmake测试非零退出状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感兴趣的应用程序是编译器,当它在源中遇到错误时,它将返回非零退出代码.编译器的单元测试由一些小片段组成,这些小片段有意触发错误.

The application of interest is a compiler which returns a non-zero exit code when it encounters an error in the source. The unit tests for the compiler are composed of small snippets which intentionally triggers errors.

用于添加测试的功能是:

The function used to add a test is:

function(add_compiler_test test_name options)
  add_test(NAME ${test_name}
    COMMAND $<TARGET_FILE:pawncc> ${DEFAULT_COMPILER_OPTIONS} ${options})
  set_tests_properties(${test_name} PROPERTIES
    ENVIRONMENT PATH=$<TARGET_FILE_DIR:pawnc>)
endfunction()

尽管程序是正确的行为,但当程序返回非零退出代码时,这会导致测试失败.

This causes the test to fail when the program returns a non-zero exit code despite that being the correct behaviour.

如何测试程序的退出状态?

How can the exit status of the program be tested?

推荐答案

如果您希望在测试返回非零退出状态且失败的情况下将测试报告为成功",否则,请设置

If you want the test(s) to be reported as SUCCESS when it returns non-zero exit status and FAILED otherwise, set WILL_FAIL property for the test(s):

set_tests_properties(<test1> <test2> ... PROPERTIES WILL_FAIL TRUE)

这篇关于使用ctest/cmake测试非零退出状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆