Directory prj/test
contains some test scripts t01.exe
, t02.exe
etc. Some of them need input data d01.dat
etc, also provided in prj/test
. The names of these data files are hard-coded in the tests, and I cannot easily change this. The control file CMakeLists.txt
contains
enable_testing()
file(GLOB test_sources "t*")
foreach(test_src ${test_sources})
string(REGEX REPLACE ".*/" "" test_name "${test_src}")
string(REGEX REPLACE ".exe$" "" test_name "${test_name}")
add_test(${test_name} "${test_src}")
endforeach(test_src)
I'm building the project in a subdirectory prj/build
. ctest
works fine ... until a test requires input data. Obviously, they are not found because they reside in prj/test
whereas the test runs in prj/build/test
.
Hence my questions:
- What's the standard way to let the tests find their input data?
- Is there a way that does not require copying the data (in case they are huge)?
- True that symlinks don't work under Windows, and therefore are no acceptable solution?
add_test
command acceptsWORKING_DIRECTORY
option. You can set this option toprj/test
(${CMAKE_SOURCE_DIR}/test
) directory, so test will be run from directory where it is located. As I understand from your question, such way test will find data files. – Sequelaadd_test(NAME ${test_name} COMMAND "${test_src}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
works perfectly. Will you repost your comment as an answer so that I can accept it? – Blazer