CTest 给出“not 运行”和“BAD_COMMAND”,尽管命令直接工作
CTest gives “not run” and “BAD_COMMAND” although commands work directly
我有一些代码想用一个小脚本来测试。它没有完全完成,但它至少应该在以后失败。这是脚本:
set -e
set -u
set -x
echo "Hello!"
"/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
现在我想在我的项目中 运行 来自 ctest
或 make 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
错误有用的信息。
是什么原因导致此测试根本无法 运行?
您正在指定 "${CMAKE_CURRENT_SOURCE_DIR}/integration-test-L4/integration-test-L4"
作为工作目录。确保该目录确实存在(如果重复有误,则删除最后一位)。
我在 Windows 上看到类似的问题与旧的 CMake (v2.8.12) - 一个在提示符下运行但失败的命令来自 CTest BAD_COMMAND
。根本问题是由于 shell 执行的可执行搜索 - 有关详细信息,请参阅 this answer。
所以用 add_test(my_test c:/node_js/npm run test)
添加测试是行不通的,因为尽管 c:\node_js\npm
存在,但它实际上执行 c:\node_js\npm.cmd
。通过将 .cmd
附加到要执行的命令来修复。
我有一些代码想用一个小脚本来测试。它没有完全完成,但它至少应该在以后失败。这是脚本:
set -e
set -u
set -x
echo "Hello!"
"/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
现在我想在我的项目中 运行 来自 ctest
或 make 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
错误有用的信息。
是什么原因导致此测试根本无法 运行?
您正在指定 "${CMAKE_CURRENT_SOURCE_DIR}/integration-test-L4/integration-test-L4"
作为工作目录。确保该目录确实存在(如果重复有误,则删除最后一位)。
我在 Windows 上看到类似的问题与旧的 CMake (v2.8.12) - 一个在提示符下运行但失败的命令来自 CTest BAD_COMMAND
。根本问题是由于 shell 执行的可执行搜索 - 有关详细信息,请参阅 this answer。
所以用 add_test(my_test c:/node_js/npm run test)
添加测试是行不通的,因为尽管 c:\node_js\npm
存在,但它实际上执行 c:\node_js\npm.cmd
。通过将 .cmd
附加到要执行的命令来修复。