clion doesn't use WORKING_DIRECTORY property of tests
Answered
If I set a tests working_directory in the cmake file when running the test under ctest it will run the test in the correct location but clion doesn't seem to pick this up. Is there something I'm doing wrong?
For example if I have something like:
add_executable(MyTest MyTest.cpp)
add_test(NAME RunMyTest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND MyTest)
When running the test or any test case from clion the cwd will remain the runtime directory instead of being updated to be CMAKE_CURRENT_SOURCE_DIR
Please sign in to leave a comment.
Yes. Currently blocking also our testing workflow.
Hi Dev!
Do you use CTest and set the working directory in the CMakeLists.txt as described in the original question?
Breaking workflow here too. We use "add_test(… WORKING_DIRECTORY <some path> …) but CLion still runs tests in the same directory where the test binary is, not in <some path> as expected. CTest runs tests in the correct directory.
Hi all!
Here is the related issue in our tracker - CPP-28105. Feel free to comment or upvote the issue in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.
Anna Falevskaya I'm not sure it's exactly the same issue. CPP-28105 relates to automatically picking the working directory for individual tests (i.e. inferring the target from the test, which is not necessarily trivial).
I think that the current request is more about having the working directory automatically set to the WORKING_DIRECTORY value for a run configuration specifying that cmake target (especially when these run configurations are automatically created from the test targets when a project is initialized or a target is created).
Should a separate issue be created for that issue / feature?
Thomas, as far as I can see, the problem that is being discussed in this thread is that
WORKING_DIRECTORY
is not properly picked up fromadd_test(<…> WORKING_DIRECTORY <…>)
by CLion. It looks to me the same as CPP-28105. But my understanding might be incorrect. If you feel that CPP-28105 does not describe the functionality you would like to observe, feel free to create another feature request/issue.OK, I just added a complement of information to CPP-28105 to make the point that automatically setting the working directory when the target is automatically created is probably easier than supporting automatic detection of the actual target when right-clicking on a test (which possibly does already exist though).