Skip to content

Commit bc61d7b

Browse files
committed
Test parameter-retrieval failures
1 parent 1bd0f35 commit bc61d7b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/configuration.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@
22

33
#include "boost/json.hpp"
44
#include "catch2/catch_test_macros.hpp"
5+
#include "catch2/matchers/catch_matchers_string.hpp"
56

67
using namespace phlex::experimental;
78

9+
TEST_CASE("Check parameter-retrieval errors", "[config]")
10+
{
11+
boost::json::object underlying_config;
12+
underlying_config["b"] = 2.5;
13+
configuration const config{underlying_config};
14+
15+
CHECK(config.keys() == std::vector<std::string>{"b"});
16+
17+
CHECK_THROWS_WITH(config.get<int>("a"),
18+
Catch::Matchers::ContainsSubstring("Error retrieving parameter 'a'"));
19+
CHECK_THROWS_WITH(config.get<std::string>("b"),
20+
Catch::Matchers::ContainsSubstring("Error retrieving parameter 'b'"));
21+
}
22+
823
TEST_CASE("Retrieve value that is a configuration object", "[config]")
924
{
1025
boost::json::object underlying_config;

0 commit comments

Comments
 (0)