Commit 51f9a94c918977b4532b2785753a1f0fcb4b7e75

Authored by Jean Guyomarc'h
Committed by jarro2783
1 parent 84feb4bd

Fix invalid exception type in catch (#149)

g++ 8.2.0 refuses to compile the test suite because of polymorphic types
that are caught by value. They shall be caught by reference instead.
Showing 1 changed file with 13 additions and 13 deletions
test/options.cpp
... ... @@ -94,7 +94,7 @@ TEST_CASE("Basic options", "[options]")
94 94 CHECK(arguments[2].key() == "value");
95 95 CHECK(arguments[3].key() == "av");
96 96  
97   - CHECK_THROWS_AS(result["nothing"].as<std::string>(), std::domain_error);
  97 + CHECK_THROWS_AS(result["nothing"].as<std::string>(), std::domain_error&);
98 98 }
99 99  
100 100 TEST_CASE("Short options", "[options]")
... ... @@ -115,7 +115,7 @@ TEST_CASE(&quot;Short options&quot;, &quot;[options]&quot;)
115 115 CHECK(result["a"].as<std::string>() == "value");
116 116  
117 117 REQUIRE_THROWS_AS(options.add_options()("", "nothing option"),
118   - cxxopts::invalid_option_format_error);
  118 + cxxopts::invalid_option_format_error&);
119 119 }
120 120  
121 121 TEST_CASE("No positional", "[positional]")
... ... @@ -345,7 +345,7 @@ TEST_CASE(&quot;Unsigned integers&quot;, &quot;[options]&quot;)
345 345 auto argc = av.argc();
346 346  
347 347 options.parse_positional("positional");
348   - CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::argument_incorrect_type);
  348 + CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::argument_incorrect_type&);
349 349 }
350 350  
351 351 TEST_CASE("Integer bounds", "[integer]")
... ... @@ -382,12 +382,12 @@ TEST_CASE(&quot;Overflow on boundary&quot;, &quot;[integer]&quot;)
382 382 int8_t si;
383 383 uint8_t ui;
384 384  
385   - CHECK_THROWS_AS((integer_parser("128", si)), cxxopts::argument_incorrect_type);
386   - CHECK_THROWS_AS((integer_parser("-129", si)), cxxopts::argument_incorrect_type);
387   - CHECK_THROWS_AS((integer_parser("256", ui)), cxxopts::argument_incorrect_type);
388   - CHECK_THROWS_AS((integer_parser("-0x81", si)), cxxopts::argument_incorrect_type);
389   - CHECK_THROWS_AS((integer_parser("0x80", si)), cxxopts::argument_incorrect_type);
390   - CHECK_THROWS_AS((integer_parser("0x100", ui)), cxxopts::argument_incorrect_type);
  385 + CHECK_THROWS_AS((integer_parser("128", si)), cxxopts::argument_incorrect_type&);
  386 + CHECK_THROWS_AS((integer_parser("-129", si)), cxxopts::argument_incorrect_type&);
  387 + CHECK_THROWS_AS((integer_parser("256", ui)), cxxopts::argument_incorrect_type&);
  388 + CHECK_THROWS_AS((integer_parser("-0x81", si)), cxxopts::argument_incorrect_type&);
  389 + CHECK_THROWS_AS((integer_parser("0x80", si)), cxxopts::argument_incorrect_type&);
  390 + CHECK_THROWS_AS((integer_parser("0x100", ui)), cxxopts::argument_incorrect_type&);
391 391 }
392 392  
393 393 TEST_CASE("Integer overflow", "[options]")
... ... @@ -402,7 +402,7 @@ TEST_CASE(&quot;Integer overflow&quot;, &quot;[options]&quot;)
402 402 auto argc = av.argc();
403 403  
404 404 options.parse_positional("positional");
405   - CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::argument_incorrect_type);
  405 + CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::argument_incorrect_type&);
406 406 }
407 407  
408 408 TEST_CASE("Floats", "[options]")
... ... @@ -443,7 +443,7 @@ TEST_CASE(&quot;Invalid integers&quot;, &quot;[integer]&quot;) {
443 443 auto argc = av.argc();
444 444  
445 445 options.parse_positional("positional");
446   - CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::argument_incorrect_type);
  446 + CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::argument_incorrect_type&);
447 447 }
448 448  
449 449 TEST_CASE("Booleans", "[boolean]") {
... ... @@ -522,7 +522,7 @@ TEST_CASE(&quot;Unrecognised options&quot;, &quot;[options]&quot;) {
522 522 auto argc = av.argc();
523 523  
524 524 SECTION("Default behaviour") {
525   - CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::option_not_exists_exception);
  525 + CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::option_not_exists_exception&);
526 526 }
527 527  
528 528 SECTION("After allowing unrecognised options") {
... ... @@ -545,6 +545,6 @@ TEST_CASE(&quot;Invalid option syntax&quot;, &quot;[options]&quot;) {
545 545 auto argc = av.argc();
546 546  
547 547 SECTION("Default behaviour") {
548   - CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::option_syntax_exception);
  548 + CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::option_syntax_exception&);
549 549 }
550 550 }
... ...