【问题标题】:ctest cannot run with simple commandctest 不能用简单的命令运行
【发布时间】:2017-12-29 00:34:23
【问题描述】:

我有 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

有人可以帮忙吗。 非常感谢

【问题讨论】:

  • 你应该试试FIND_PROGRAM()${CMAKE_COMMAND} -E echo 会更便携

标签: cmake ctest


【解决方案1】:

我找到了方法。对于使用外部程序运行测试的一般目的,请使用 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)

【讨论】:

    猜你喜欢
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2019-05-28
    • 2013-04-02
    • 2015-01-01
    • 1970-01-01
    相关资源
    最近更新 更多