Executing a complex command in CTest

The most simple solution is to encapsulate your commands in a CMake script and launch this script through add_test.

The script: myscript.cmake:

execute_process (COMMAND myexecutable --param1 RESULT_VARIABLE status)
if (NOT status)
execute_process (COMMAND myexecutable --param2 RESULT_VARIABLE status) 
endif()
# etc...

if (status)
message (FATAL_ERROR "test failed")
endif()

and the test:

add_test (NAME myexecutabletest COMMAND ${CMAKE_COMMAND} -P "my_script.cmake")