New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DOCTEST_WORKING_DIRECTORY to run tests from a fixed directory #222
Comments
It could be made as a runtime parameter instead of a compile-time config option - suppose you need to run a test from multiple directories - why would you have to compile multiple binaries? However this is a very niche problem and is easily solved with a custom main function as you have demonstrated... I'm really careful not to bloat doctest with too much functionality and configuration - it already has plenty. So I don't think this should be added at this stage. It can stay open and if other people are interested I might add it at a later stage. As a side note - the test runner outside of doctest could just change the working directory too. |
I agree, but when integrating doctest with cmake I can either add a custom command with a fixed working directory or add the doctest executable to ctest. Unfortunately both options don't seem to allow me to pass arguments to doctest. I could try to fix #171 so I'd be able to do everything via ctest's command line instead of doctest's command line but the annoying thing with ctest is that you have to run it from the build directory whereas with doctest I can just run the tests executable from the project root directory. These aren't really arguments for implementing DOCTEST_WORKING_DIRECTORY, just general issues I've come across trying to establish a simple testing workflow using doctest and cmake (although I think these issues apply to most testing frameworks). |
Well... I could actually add that runtime option if it would be of use to you: |
I'll keep the custom main with compile time working directory for now (with a runtime option I'd have to remember to type it each time). Thinking about it more, the problem is really on CMake's side for not providing support for passing arguments to custom targets. |
Hmmm it seems that it is possible? |
To clarify, I meant passing arguments when invoking the custom target. For example: |
The reproc tests depend on a few external binaries. Previously I just passed their (absolute) locations as compile time parameters so the tests could be executed from any directory but ideally I could pass the working directory for the tests executable as a compile time parameter and the executable would just change its directory before executing the tests.
I've implemented this myself using a custom main function here but I was wondering if this could be added to doctest itself.
I'd propose to check if
DOCTEST_WORKING_DIRECTORY
is defined at compile time and change the working directory to that directory when running the executable if it is.I'm willing to submit a PR but I thought I'd check first to see if you'd be interested in merging this.
The text was updated successfully, but these errors were encountered: