jiridanek commented on a change in pull request #303: URL: https://github.com/apache/qpid-proton/pull/303#discussion_r606149268
########## File path: cpp/src/url_test.cpp ########## @@ -111,6 +116,54 @@ TEST_CASE("parse URL","[url]") { "amqp", "user", "pass", "::1", "1234", "path", "amqp://user:pass@[::1]:1234/path"); } + SECTION("port") { + CHECK("host:1234" == url("amqp://host:1234/path").host_port()); + CHECK(5672 == url("amqp://foo/path").port_int()); + CHECK(5671 == url("amqps://foo/path").port_int()); + CHECK(1234 == url("amqps://foo:1234/path").port_int()); + + url u("amqps://foo:xyz/path"); + url_error caught_error(""); + try{ + u.port_int(); + } + catch(url_error& err){ + caught_error=err; + } + CHECK(std::string("invalid port 'xyz'") == std::string(caught_error.what())); Review comment: You can use a Catch1 feature to check the expected exception is thrown. https://github.com/catchorg/Catch2/blob/Catch1.x/docs/assertions.md#exceptions The feature allows you to only check exception type or exception string, but not both at the same time. To check both, you'd have to use `REQUIRE_THROWS_MATCHES` which is only available in Catch2, not Catch1. ``` CHECK_THROWS_WITH(openThePodBayDoors(), Contains( "afraid" ) && Contains( "can't do that" )); ``` Personally, I'd write two tests: first to assert that `url` throws `url_error` when it gets some completely bogus string. And then, here, I'd simply assert on the exception string and assume the exception type stayed the same... I guess your version may actually be better than what I just proposed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org