MCPcopy Create free account
hub / github.com/bfgroup/Lyra / main

Function main

tests/single_include_test.cpp:11–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "mini_test.hpp"
10
11int 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}

Callers

nothing calls this directly

Calls 7

ConfigClass · 0.70
helpClass · 0.50
optClass · 0.50
argClass · 0.50
parseMethod · 0.45
typeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected