2

I have the ctest setting and work fine with all executable I've built for the project. The problem is I want to add some test with a system command, it has nothing to do with program in the solution, I cannot get it run by ctest.

I added a simple test as below, it just run the command echo:

add_test(NAME toto_test COMMAND echo bla bla bla)

Then the when I run ctest, I got the error

Start  1: toto_test
Could not find executable echo
Looked in the following places:
echo
echo.exe
Release/echo
Release/echo.exe
Release/echo
Release/echo.exe
Unable to find executable: echo
1/10 Test  #1: toto_test ........................***Not Run   0.00 sec

The following tests FAILED:
      1 - toto_test (Not Run)
Errors while running CTest

And when I run ctest with verbose option, I get

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: toto_test
Could not find executable echo
Looked in the following places:
echo
echo.exe
Release/echo
Release/echo.exe
Release/echo
Release/echo.exe

1: Test command:  "bla" "bla" "bla"
Unable to find executable: echo
1/1 Test #1: toto_test ........................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.02 sec

The following tests FAILED:
      1 - toto_test (Not Run)
Errors while running CTest

Can anyone come to help please. Thanks a lot

1
  • you should try FIND_PROGRAM() or ${CMAKE_COMMAND} -E echo it will be much more portable Commented Dec 29, 2017 at 9:45

1 Answer 1

0

I found the way to do it. For the general purpose of running a test with an external program, use add_custom_target, then use ${CMAKE_COMMAND} to build this target when running the tests :

add_custom_target(run_toto COMMAND echo bla bla bla)
add_test(NAME test_toto COMMAND ${CMAKE_COMMAND} --build . --target run_toto)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.