Running only one single test with CMake + make
einpoklum is not fully correct. Actually you can use make test
if you like. CMake will generate a Makefile and I found out that it accepts an ARGS
variable.
Meaning you are able run specific tests via for example the -R (regex) parameter. Which will look like this when using make test:
make test ARGS="-R '^test_'"
This will run only the testcases files that starts with test_
in their filename.
Note: -R
above is just an example, it will accept all the arguments that ctest
command will accept as well.
Anyway the make test example above will do exactly the same as running:
ctest -R '^test_'
tl;dr - Do this:
cd $YOUR_BUILD_DIRECTORY
ctest -R name_of_your_test
Explanation
Here is how you likely got confused:
You were trying to do this with
make
, sincemake test
runs all the tests for you. This won't work for a single test (although there's a workaround - see @danger89's answer).ctest
is the cross-platform way to do it.You started using
ctest
, e.g. in your main project directory, and you probably got something like:********************************* No test configuration file found! ********************************* Usage ctest [options]
which wasn't helpful.
... So you thought "Ok, maybe
ctest
has a-C
switch, like CMake and GNU Make" - and indeed, it has a-C
switch! but that didn't do what you expected:[joeuser:/home/joeuser/src/myproj]$ ctest -C build Test project /home/joeuser/src/myproj No tests were found!!!
What you actually need to do:
cd $YOUR_BUILD_DIRECTORY
ctest -R name_of_your_test
(note that -R
matches a regular expression.) This should work. Note that you can list the tests to be run rather than actually run them by passing -N
to ctest
.
Thanks goes to @RTsyvarev for pointing me in the right direction