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

Passing arguments to a test #622

Closed
mrzv opened this issue Mar 25, 2016 · 6 comments
Closed

Passing arguments to a test #622

mrzv opened this issue Mar 25, 2016 · 6 comments

Comments

@mrzv
Copy link

mrzv commented Mar 25, 2016

I'd like to write a test that takes some arguments on the command line and based on those performs some action. A simple example would be some of the vector tests from the documentation that take the initial vector size on the command-line.

The only way I see how to do this is to create a fixture that has the arguments as static members, then to provide my own main that parses the command-line arguments, initializes the fixture member variables, and passes control to session.run(). That seems a little verbose. Is there no simpler way to do this?

@DraTeots
Copy link

I've found this here

Adding your own command line options

Catch embeds a powerful command line parser which you can also use to parse your own options out. This capability is still in active development but will be documented here when it is ready.

So what is the status of it? Maybe it is kind of more ready now?

What I need to do is to pass different connection strings corresponding to different databases to check that all tests are passing with all supported databases. Now I do this with environment variables but it is... mmm... dirty?.. I would definitely prefer CATCH handling the situation with its argument parser, giving the values to the tests that require them.

@lightmare
Copy link
Contributor

Take a look at https://github.com/mapnik/mapnik/blob/master/test/unit/run.cpp (adds options --prefix and --working-directory). For this to work you'll need to change Catch::Session:cli() return type to non-const reference. I think you can omit the single-letter variants, which I'd recommend as those are more likely to clash with future additions to basic Catch options.

edit: with flag (value-less) option --keep-temporary-files https://github.com/lightmare/mapnik/blob/f7d6950b41a47caccaefa20769ea507e043488d1/test/unit/run.cpp

@czipperz
Copy link

This is the command line parser https://github.com/philsquared/Clara.

@KingDuckZ
Copy link

I'm also interested in this, or at least int a way to get the list of unprocessed parameters back from Catch/Clara.

@dhaumann
Copy link

dhaumann commented Jul 3, 2017

Any news on this, even if preliminary?

@horenmar
Copy link
Member

horenmar commented Mar 5, 2018

See #793.

The short version is that Catch2 makes it fairly easy to add arguments.

@horenmar horenmar closed this as completed Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants