虽然命令直接起作用,但CTest给出“not run”和“BAD_COMMAND”

时间:2017-11-10 13:39:02

标签: cmake

我有一些代码,我想用一个小脚本来测试。它还没有完全完成,但它至少应该在以后失败。这是脚本:

set -e
set -u
set -x

echo "Hello!"
"$1/contract" -i test_all.ini
h5diff FILE1 FILE2

当我使用

从命令行调用它时
/usr/bin/bash \
    "/home/mu/Projekte/sLapH-contractions/integration-test-L4/run-integration-test" \
    "/home/mu/Build/sLapH-contractions"

它按预期工作:

$ /usr/bin/bash "/home/mu/Projekte/sLapH-contractions/integration-test-L4/run-integration-test" "/home/mu/Build/sLapH-contractions"
+ echo 'Hello!'
Hello!
+ /home/mu/Build/sLapH-contractions/contract -i test_all.ini
CANNOT open input file: test_all.ini
+ h5diff FILE1 FILE2
h5diff: <FILE1>: unable to open file

现在我想在我的项目中从ctestmake test运行此测试。我已将以下内容添加到CMakeLists.txt

enable_testing()

add_test(NAME sanity-1
    COMMAND bash -c "echo Sanity 1"
    WORKING_DIRECTORY /tmp)

add_test(NAME integration-L4
    COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/integration-test-L4/run-integration-test" "${CMAKE_CURRENT_BINARY_DIR}"
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/integration-test-L4/integration-test-L4")

当我使用ctest运行它时,它甚至没有运行测试!

$ ctest -VV
UpdateCTestConfiguration  from :/home/mu/Build/sLapH-contractions/DartConfiguration.tcl
UpdateCTestConfiguration  from :/home/mu/Build/sLapH-contractions/DartConfiguration.tcl
Test project /home/mu/Build/sLapH-contractions
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: sanity-1

1: Test command: /usr/bin/bash "-c" "echo Sanity 1"
1: Test timeout computed to be: 9.99988e+06
1: Sanity 1
1/2 Test #1: sanity-1 .........................   Passed    0.00 sec
test 2
    Start 2: integration-L4

2: Test command: /usr/bin/bash "/home/mu/Projekte/sLapH-contractions/integration-test-L4/run-integration-test" "/home/mu/Build/sLapH-contractions"
2: Test timeout computed to be: 9.99988e+06
2/2 Test #2: integration-L4 ...................***Not Run   0.00 sec

50% tests passed, 1 tests failed out of 2

Total Test time (real) =   0.01 sec

The following tests FAILED:
          2 - integration-L4 (BAD_COMMAND)
Errors while running CTest

我发现BAD_COMMAND错误没有任何帮助。

可能会发生什么阻止此测试的运行?

2 个答案:

答案 0 :(得分:3)

您指定"${CMAKE_CURRENT_SOURCE_DIR}/integration-test-L4/integration-test-L4"作为工作目录。确保目录实际存在(如果重复出错,则删除最后一位)。

答案 1 :(得分:1)

我在使用较旧的CMake(v2.8.12)的Windows上看到了类似的问题-该命令在提示符下运行,但由于CTest的BAD_COMMAND而失败。根本问题是由于外壳程序执行了可执行文件搜索-有关更多信息,请参见this answer

因此,用add_test(my_test c:/node_js/npm run test)添加测试是行不通的,因为尽管c:\node_js\npm存在,但实际上执行了c:\node_js\npm.cmd。通过在要执行的命令后附加.cmd来解决。