Integrate bash test scripts in cmake

2019-04-11 04:53发布

问题:

I have a C++ cmake project that uses Boost Test for unit testing. Now I would like to expose a series of bash scripts (used for integration testing) to cmake. Suppose each of this script to return 0 in case of PASS or something != 0 in case of FAILURE. I would like each script to be executed whenever I run cmake test.

What's the simplest and quickest way to obtain such behavior

回答1:

Basically, you want to start by locating the bash program

find_program (BASH_PROGRAM bash)

Then just add your script to the list of tests

if (BASH_PROGRAM)
  add_test (mytest ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/script.sh)
endif (BASH_PROGRAM)

And all of that should work.



标签: c++ bash cmake