Skip to content

add_test with cmd not working as intended

Minimal working example:

cmake_minimum_required(VERSION 3.20)
project(test-project)

include(CTest)

add_test(
    NAME test_windows_echo
    COMMAND cmd /c "echo hello"
)

Gives:

> ctest . -C Debug -VV


test 1
    Start 1: test_windows_echo

1: Test command: C:\Windows\System32\cmd.exe "/c" "echo hello"
1: Working Directory: C:/intraffic-software/sandbox/build
1: Test timeout computed to be: 1500
1: The syntax of the command is incorrect.
1/1 Test #1: test_windows_echo ................***Failed    0.01 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.02 sec

The following tests FAILED:
          1 - test_windows_echo (Failed)
Errors while running CTest
Output from these tests are in: C:/intraffic-software/sandbox/build/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.

With its corresponding LastTest.log:

Start testing: Oct 11 13:45 W. Europe Daylight Time
----------------------------------------------------------
1/1 Testing: test_windows_echo
1/1 Test: test_windows_echo
Command: "C:/Windows/System32/cmd.exe" "/c" "echo hello"
Directory: C:/intraffic-software/sandbox/build
"test_windows_echo" start time: Oct 11 13:45 W. Europe Daylight Time
Output:
----------------------------------------------------------
The syntax of the command is incorrect.
<end of output>
Test time =   0.01 sec
----------------------------------------------------------
Test Failed.
"test_windows_echo" end time: Oct 11 13:45 W. Europe Daylight Time
"test_windows_echo" time elapsed: 00:00:00
----------------------------------------------------------

End testing: Oct 11 13:45 W. Europe Daylight Time

While on Linux:

cmake_minimum_required(VERSION 3.13)
project(project)
include(CTest)

add_executable(exe main.cpp)
add_test(NAME dummy COMMAND bash -c "echo foo")

Gives:

> ctest3 

Test project /home/prl/sandbox/build
    Start 1: dummy
1/1 Test #1: dummy ............................   Passed    0.00 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.01 sec
Edited by Marc
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information