Skip to content
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

Open
DaanDeMeyer opened this issue Apr 7, 2019 · 6 comments
Open

Comments

@DaanDeMeyer
Copy link
Contributor

DaanDeMeyer commented Apr 7, 2019

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.

@onqtam
Copy link
Member

onqtam commented Apr 7, 2019

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.

@DaanDeMeyer
Copy link
Contributor Author

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).

@onqtam
Copy link
Member

onqtam commented Apr 7, 2019

Well... I could actually add that runtime option if it would be of use to you: --working-directory=<...>

@DaanDeMeyer
Copy link
Contributor Author

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.

@onqtam
Copy link
Member

onqtam commented Apr 7, 2019

Hmmm it seems that it is possible?

@DaanDeMeyer
Copy link
Contributor Author

To clarify, I meant passing arguments when invoking the custom target. For example: ninja -C build reproc-tests <doctest-cli-args>. As far as I know, this is not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants