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

Session::run should take a const parameter #1031

Closed
michaelcowan opened this issue Oct 1, 2017 · 2 comments
Closed

Session::run should take a const parameter #1031

michaelcowan opened this issue Oct 1, 2017 · 2 comments

Comments

@michaelcowan
Copy link
Contributor

Description

I configure Catch programmatically like this:

        Catch::Session session;
        
        Catch::ConfigData config;
        config.showDurations = Catch::ShowDurations::Always;
        config.useColour = Catch::UseColour::No;
        session.useConfigData(config);
        
        char * argv[] = { "TestApp", "-r", "junit" };
        int numberFailed = session.run(3, argv);

This throws a compiler warning

ISO C++11 does not allow conversion from string literal to 'char *'

Steps to reproduce

Use the code snippet above.

Extra information

As of C++11 the implicit conversion from char * to const char * has been deprecated.

To fix this the signatures can be changed to:

int run(int argc, const char* argv[]);

Args(int argc, const char *argv[]) {

int applyCommandLine(int argc, const char* argv[]);

I have tested this on the version below and it seems to work fine.

  • Catch version: 2.0.0-develop.4
  • Operating System: OSX
  • Compiler+version: Clang
@lightmare
Copy link
Contributor

lightmare commented Oct 4, 2017

Standard says main takes char**, that is a pointer to char*. That thing doesn't implicitly convert to const char** (pointer to const char*). So there'd need to be extra overloads and some const_casts for this usage.

If your example is all you want this for, try

#define CATCH_CONFIG_DEFAULT_REPORTER "junit"

@michaelcowan
Copy link
Contributor Author

michaelcowan commented Oct 4, 2017

@lightmare I see your point. Thats a real shame as the parameter is not being modified and strictly speaking is const - but I get your point that this is painful when passing arguments from main.

I set the arguments programatically because I am embedding Catch into a platform abstraction, and really currently only use it to set the application name - so the junit define doesn't help but I may use it in the future - thanks.

The solution for me is to simply perform the casting myself, which seems reasonable.
Thank you for your reply.

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

3 participants