ctest不能用简单的命令运行

时间:2017-12-29 00:34:24

标签: cmake ctest

我有ctest设置,可以正常使用我为项目构建的所有可执行文件。问题是我想用系统命令添加一些测试,它与解决方案中的程序无关,我无法通过ctest运行它。

我添加了一个简单的测试,如下所示,只需运行命令 echo

add_test(NAME toto_test COMMAND echo bla bla bla)

然后当我运行ctest时,我收到了错误

Start  1: toto_test
Could not find executable echo
Looked in the following places:
echo
echo.exe
Release/echo
Release/echo.exe
Release/echo
Release/echo.exe
Unable to find executable: echo
1/10 Test  #1: toto_test ........................***Not Run   0.00 sec

The following tests FAILED:
      1 - toto_test (Not Run)
Errors while running CTest

当我使用详细选项运行ctest时,我得到了

Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: toto_test
Could not find executable echo
Looked in the following places:
echo
echo.exe
Release/echo
Release/echo.exe
Release/echo
Release/echo.exe

1: Test command:  "bla" "bla" "bla"
Unable to find executable: echo
1/1 Test #1: toto_test ........................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.02 sec

The following tests FAILED:
      1 - toto_test (Not Run)
Errors while running CTest

任何人都可以来帮忙。 非常感谢

1 个答案:

答案 0 :(得分:0)

我找到了办法。对于使用外部程序运行测试的一般目的,请使用add_custom_target,然后在运行测试时使用$ {CMAKE_COMMAND}来构建此目标:

add_custom_target(run_toto COMMAND echo bla bla bla)
add_test(NAME test_toto COMMAND ${CMAKE_COMMAND} --build . --target run_toto)
相关问题