1

I have a project containing some unit test code using a template file as a resource. So I have something like this :

std::ofstream out { "../templates/file.cpp" };

But depending on where I run the unit tests it does not work. I use these commands :

cd _build
cmake ../src
make -j 4
ctest

Is it possible to manage properly resources with cmake (as we can do with Qt) ? Or is it possible to specify to ctest the run directory ? I tried the --build-run-dir option like this :

ctest --build-run-dir ..

but the argument is not working.

Many thanks !

Maluna34
  • 245
  • 1
  • 16

1 Answers1

1

add_test has an optional parameter WORKING_DIRECTORY that allows you to specify the working directory for a test. That should allow you to correctly specify the path to the template file from within the unit test code.

Quoting from the manual:

WORKING_DIRECTORY

Set the WORKING_DIRECTORY test property to specify the working directory in which to execute the test. If not specified the test will be run with the current working directory set to the build directory corresponding to the current source directory.

Ton van den Heuvel
  • 10,157
  • 6
  • 43
  • 82