| 9 | #include "mini_test.hpp" |
| 10 | |
| 11 | int main() |
| 12 | { |
| 13 | using namespace lyra; |
| 14 | bfg::mini_test::scope test; |
| 15 | bool show_help = false; |
| 16 | struct Config |
| 17 | { |
| 18 | int seed = 0; |
| 19 | std::string name; |
| 20 | std::vector<std::string> tests; |
| 21 | bool flag = false; |
| 22 | double value = 0; |
| 23 | } config; |
| 24 | auto parser |
| 25 | = help( show_help ) |
| 26 | | opt( config.seed, "time|value" ) |
| 27 | ["--rng-seed"]["-r"] |
| 28 | ("set a specific seed for random numbers" ) |
| 29 | | opt( config.name, "name" ) |
| 30 | ["-n"]["--name"] |
| 31 | ( "the name to use" ) |
| 32 | | opt( config.flag ) |
| 33 | ["-f"]["--flag"] |
| 34 | ( "a flag to set" ) |
| 35 | | opt( [&]( double value ){ config.value = value; }, "number" ) |
| 36 | ["-d"]["--double"] |
| 37 | ( "just some number" ) |
| 38 | | arg( config.tests, "test name|tags|pattern" ) |
| 39 | ( "which test or tests to use" ); |
| 40 | |
| 41 | show_help = false; |
| 42 | config = Config(); |
| 43 | { |
| 44 | auto result = parser.parse( { "TestApp", "-n", "Bill", "-d=123.45", "-f", "test1", "test2" } ); |
| 45 | test |
| 46 | (REQUIRE( result )) |
| 47 | (REQUIRE( result.value().type() == parser_result_type::matched )) |
| 48 | (REQUIRE( config.name == "Bill" )) |
| 49 | (REQUIRE( config.value == 123.45 )) |
| 50 | (REQUIRE( (config.tests == std::vector<std::string> { "test1", "test2" }) )) |
| 51 | (REQUIRE( show_help == false )) |
| 52 | ; |
| 53 | } |
| 54 | show_help = false; |
| 55 | config = Config(); |
| 56 | { |
| 57 | auto result = parser.parse( { "TestApp", "-?", "-n=NotSet" } ); |
| 58 | test |
| 59 | (REQUIRE( result )) |
| 60 | (REQUIRE( result.value().type() == parser_result_type::short_circuit_all )) |
| 61 | (REQUIRE( config.name == "" )) // We should never have processed -n:NotSet |
| 62 | (REQUIRE( show_help == true )) |
| 63 | ; |
| 64 | } |
| 65 | |
| 66 | return test; |
| 67 | } |