Friday, September 2, 2022

[SOLVED] CTest misparsing add_test calls

Issue

I am trying to run some tests using CTest.

My CTestTestFile.cmake contains a single test

add_test(NAME test1 
COMMAND python script.py args
)

but when I try run ctest it outputs the following

Start 1: NAME
Could not find executable test1
Looked in the following places:
test1
test1.exe
Release/test1
Release/test1.exe
Debug/test1
Debug/test1.exe
MinSizeRel/test1
MinSizeRel/test1.exe
RelWithDebInfo/test1
RelWithDebInfo/test1.exe
Deployment/test1
Deployment/test1.exe
Development/test1
Development/test1.exe
Unable to find executable: test1
1/1 Test #1: NAME .............................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.14 sec

The following tests FAILED:
          1 - NAME (Not Run)

This suggests CTest thinks I'm using the short version of the command, so that my test's name is NAME, the command is test1 and python script.py args are the arguments to the command, when this is of course not the case, as I'm obviously using the long version of the command.

I have CMake version 3.24.1 installed.


Solution

The CTest runtime, unlike CMake, accepts only the "basic" signature documented at the end of the usual add_test documentation:

add_test(<name> <command> [<arg>...])

Notice that CTest thought your test was named NAME.

So you have to write:

add_test(test1 "python" "script.py" "args")


Answered By - Alex Reinking
Answer Checked By - David Goodson (WPSolving Volunteer)