Skip to content

Commit

Permalink
Switch to fmtlib-9.1.0.
Browse files Browse the repository at this point in the history
Fix compilation problems with clang-14, c++20 and
FMT_ENFORCE_COMPILE_STRING.
  • Loading branch information
eao197 committed Sep 5, 2022
1 parent c6f864d commit a5b6685
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 46 deletions.
44 changes: 29 additions & 15 deletions dev/sample/tls_inspector/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ init_resp( RESP resp )
namespace rr = restinio::router;
using router_t = rr::express_router_t<>;

std::string make_no_restrictions_body( const std::string & user )
{
return fmt::format(
RESTINIO_FMT_FORMAT_STRING(
"There is no any restrictions for user '{}' "
"on that resource\n" ),
user );
}

std::string make_user_has_access_body( const std::string & user )
{
return fmt::format(
RESTINIO_FMT_FORMAT_STRING(
"User '{}' have access to limited resource\n" ),
user );
}

std::string make_user_has_no_access_body( const std::string & user )
{
return fmt::format(
RESTINIO_FMT_FORMAT_STRING(
"User '{}' haven't access to limited resource\n" ),
user );
}

auto server_handler( const user_connections_shptr_t& user_connections )
{
auto router = std::make_unique< router_t >();
Expand All @@ -90,11 +115,8 @@ auto server_handler( const user_connections_shptr_t& user_connections )
restinio::http_field::content_type,
"text/plain; charset=utf-8" )
.set_body(
fmt::format(
RESTINIO_FMT_FORMAT_STRING(
"There is no any restrictions "
"for user '{}' on that resource\n" ),
user_connections->query( req->connection_id() ) ) )
make_no_restrictions_body(
user_connections->query( req->connection_id() ) ) )
.done();

return restinio::request_accepted();
Expand All @@ -110,17 +132,9 @@ auto server_handler( const user_connections_shptr_t& user_connections )

const auto & user = user_connections->query( req->connection_id() );
if( "alice" == user )
resp.set_body(
fmt::format(
RESTINIO_FMT_FORMAT_STRING(
"User '{}' have access to limited resource\n" ),
user ) );
resp.set_body( make_user_has_access_body( user ) );
else
resp.set_body(
fmt::format(
RESTINIO_FMT_FORMAT_STRING(
"User '{}' haven't access to limited resource\n" ),
user ) );
resp.set_body( make_user_has_no_access_body( user ) );

resp.done();

Expand Down
43 changes: 28 additions & 15 deletions dev/test/handle_requests/connection_state/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,32 @@ TEST_CASE( "ordinary connection" , "[ordinary_connection]" )
REQUIRE( 0 == state_listener->m_upgraded_to_websocket.load() );
}

// eao197: helper function to simpilfy the code of
// "remote_endpoint for WS" unit-test.
// Otherwise we'll get an error on clang-14 with
// c++20 and FMT_ENFORCE_COMPILE_STRING=1.
template< class Traits >
void
do_upgrade_attempt(
restinio::request_handle_t & req,
std::string & endpoint_value_ws_receiver )
{
namespace rws = restinio::websocket::basic;
auto ws =
rws::upgrade< Traits >(
*req,
rws::activation_t::immediate,
[]( const rws::ws_handle_t&,
const rws::message_handle_t& ){} );

endpoint_value_ws_receiver = fmt::format(
RESTINIO_FMT_FORMAT_STRING( "{}" ),
restinio::fmtlib_tools::streamed(
ws->remote_endpoint() ) );

ws->kill();
}

TEST_CASE( "connection state for WS" , "[connection_state][ws]" )
{
std::string endpoint_value;
Expand Down Expand Up @@ -299,22 +325,9 @@ TEST_CASE( "connection state for WS" , "[connection_state][ws]" )
{
try
{
namespace rws = restinio::websocket::basic;
auto ws =
rws::upgrade< test_traits >(
*req,
rws::activation_t::immediate,
[]( rws::ws_handle_t,
rws::message_handle_t ){} );
do_upgrade_attempt< test_traits >(
req, endpoint_value_ws );


endpoint_value_ws = fmt::format(
RESTINIO_FMT_FORMAT_STRING( "{}" ),
restinio::fmtlib_tools::streamed(
ws->remote_endpoint() ) );

ws->kill();

return restinio::request_accepted();
}
catch( const std::exception & ex )
Expand Down
44 changes: 29 additions & 15 deletions dev/test/handle_requests/remote_endpoint/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ TEST_CASE( "remote_endpoint extraction" , "[remote_endpoint]" )
REQUIRE( !endpoint_value.empty() );
}

// eao197: helper function to simpilfy the code of
// "remote_endpoint for WS" unit-test.
// Otherwise we'll get an error on clang-14 with
// c++20 and FMT_ENFORCE_COMPILE_STRING=1.
template< class Traits >
void
do_upgrade_attempt(
restinio::request_handle_t & req,
std::string & endpoint_value_ws_receiver )
{
namespace rws = restinio::websocket::basic;
auto ws =
rws::upgrade< Traits >(
*req,
rws::activation_t::immediate,
[]( const rws::ws_handle_t&,
const rws::message_handle_t& ){} );

endpoint_value_ws_receiver = fmt::format(
RESTINIO_FMT_FORMAT_STRING( "{}" ),
restinio::fmtlib_tools::streamed(
ws->remote_endpoint() ) );

ws->kill();
}

TEST_CASE( "remote_endpoint for WS" , "[remote_endpoint][ws]" )
{
Expand Down Expand Up @@ -101,21 +126,8 @@ TEST_CASE( "remote_endpoint for WS" , "[remote_endpoint][ws]" )
{
try
{
namespace rws = restinio::websocket::basic;
auto ws =
rws::upgrade< traits_t >(
*req,
rws::activation_t::immediate,
[]( const rws::ws_handle_t&,
const rws::message_handle_t& ){} );


endpoint_value_ws = fmt::format(
RESTINIO_FMT_FORMAT_STRING( "{}" ),
restinio::fmtlib_tools::streamed(
ws->remote_endpoint() ) );

ws->kill();
do_upgrade_attempt< traits_t >(
req, endpoint_value_ws );

return restinio::request_accepted();
}
Expand All @@ -125,6 +137,7 @@ TEST_CASE( "remote_endpoint for WS" , "[remote_endpoint][ws]" )
<< ex.what() << std::endl;
}
}

return restinio::request_rejected();
} );
} };
Expand Down Expand Up @@ -152,3 +165,4 @@ TEST_CASE( "remote_endpoint for WS" , "[remote_endpoint][ws]" )
REQUIRE( !endpoint_value.empty() );
REQUIRE( endpoint_value == endpoint_value_ws );
}

2 changes: 1 addition & 1 deletion externals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

MxxRu::arch_externals :fmt do |e|
e.url 'https://github.com/fmtlib/fmt/archive/9.0.0.zip'
e.url 'https://github.com/fmtlib/fmt/archive/9.1.0.zip'
# e.url 'https://github.com/fmtlib/fmt/archive/8.1.1.zip'
# e.url 'https://github.com/fmtlib/fmt/archive/7.1.3.zip'

Expand Down

0 comments on commit a5b6685

Please sign in to comment.