8

I added my own command line option using a custom main file:

https://github.com/catchorg/Catch2/blob/master/docs/own-main.md#adding-your-own-command-line-options

  // ...
  auto cli 
    = session.cli() // Get Catch's composite command line parser
    | Opt( height, "height" ) // bind variable to a new option, with a hint string
        ["-g"]["--height"]    // the option names it will respond to
        ("how high?");        // description string for the help output

  // ...
}

Now I want to use the height command line option from within a test case. What would be the best way to do this?

yacc
  • 2,915
  • 4
  • 19
  • 33
Sparkler
  • 2,581
  • 1
  • 22
  • 41
  • 2
    Couldn't find any other way than by adding a global variable, as described here: https://stackoverflow.com/questions/37530546/catch-dynamically-pass-arguments-to-test-cases I looked through the source code. ```runTests()``` is a non-member function and is called with an argument of type ```Config```, which sounds promising but doesn't appear to expose any access to command line options :/ – RL-S Jul 28 '21 at 10:59
  • When adding your own command line option, the option letters already taken are ```abcdefilorstvwx#```, as you can look up in ```catch::makeCommandLineParser( ConfigData& )```. Empty option names are not allowed, so use one of ```ghjkmnpquyz``` or special characters. – RL-S Jul 28 '21 at 11:26

0 Answers0