Skip to content

Commit

Permalink
Fix, format, and move modules tests together
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Dec 1, 2024
1 parent 9729156 commit 62951db
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 42 deletions.
2 changes: 1 addition & 1 deletion asio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
include(cmake/install-rules.cmake)
configure_file(asio.pc.cmake asio.pc)
install(FILES ${PROJECT_BINARY_DIR}/asio.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(DIRECTORY module DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/asio)
install(FILES module/asio.cppm DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/asio/module)
endif()

# ---- Developer mode ----
Expand Down
2 changes: 1 addition & 1 deletion asio/cmake/dev-mode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(ASIO_BUILD_TESTING)
enable_testing()

add_subdirectory(src/tests)
add_subdirectory(src/examples)
add_subdirectory(module/tests)
endif()

option(ASIO_BUILD_MCSS_DOCS "Build documentation using Doxygen and m.css" OFF)
Expand Down
2 changes: 1 addition & 1 deletion asio/cmake/lint-targets.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(ACIO_FORMAT_PATTERNS *.json # src/*.cpp src/*.hpp include/*.hpp tests/*.cpp tests/*.hpp
set(ACIO_FORMAT_PATTERNS *.json *.cppm # src/*.cpp src/*.hpp include/*.hpp tests/*.cpp tests/*.hpp
CACHE STRING "; separated patterns relative to the project source dir to format"
)

Expand Down
30 changes: 18 additions & 12 deletions asio/module/asio.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module;

export module asio;

namespace asio {
namespace asio
{
export using asio::io_context;
export using asio::post;
export using asio::any_completion_executor;
Expand Down Expand Up @@ -37,31 +38,36 @@ export using asio::buffer;
export using asio::socket_base;
export using asio::co_spawn;

namespace error {
namespace error
{
export using asio::error::make_error_code;
}
} // namespace error

namespace this_coro {
namespace this_coro
{
export using asio::this_coro::executor;
}
} // namespace this_coro

namespace ip {
namespace ip
{
export using asio::ip::tcp;
export using asio::ip::address;
export using asio::ip::address_v4;
}
} // namespace ip

namespace ssl {
namespace ssl
{
export using asio::ssl::context;
export using asio::ssl::context_base;
export using asio::ssl::host_name_verification;
export using asio::ssl::stream_base;
export using asio::ssl::verify_context;
export using asio::ssl::stream;
namespace error {
namespace error
{
export using asio::ssl::error::stream_errors;
export using asio::ssl::error::make_error_code;
}
}
} // namespace error
} // namespace ssl

}
} // namespace asio
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.25...3.31)

project(asio_examples LANGUAGES CXX)
project(asio_moddule_examples LANGUAGES CXX)

if(PROJECT_IS_TOP_LEVEL)
# Find the Asio package containing the function to build the module
find_package(asio 1.32.0.1 EXACT REQUIRED HINT ../stagedir/lib)
find_package(asio 1.32.0.1 EXACT REQUIRED HINT ../../stagedir/lib)
enable_testing()

# Use modules?
Expand Down Expand Up @@ -35,15 +35,14 @@ if(PROJECT_IS_TOP_LEVEL)

endif()

# set(ALL_EXAMPLES cpp20/operations/callback_wrapper.cpp)
# list(APPEND ALL_EXAMPLES ../../module/tests/main.cpp)
# list(APPEND ALL_EXAMPLES module/tests/main.cpp)
set(ALL_EXAMPLES main)

message(STATUS "Examples to be built: ${ALL_EXAMPLES}")

foreach(example ${ALL_EXAMPLES})
add_executable(${example})
target_sources(${example} PRIVATE ../../module/tests/${example}.cpp)
target_sources(${example} PRIVATE ${example}.cpp)
if(USE_MODULES)
target_link_libraries(${example} asio_module)
target_compile_definitions(${example} PUBLIC USE_MODULES)
Expand Down
2 changes: 1 addition & 1 deletion asio/module/tests/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ inline net::awaitable<void> do_listen()
{
tcp::socket socket{ex};
co_await acceptor.async_accept(socket, net::deferred);
net::co_spawn(ex, [s = std::move(socket)] mutable {
net::co_spawn(ex, [s = std::move(socket)]() mutable {
return do_session(std::move(s));
}, net::detached);
}
Expand Down
21 changes: 2 additions & 19 deletions asio/src/examples/cpp20/operations/callback_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifdef USE_MODULES
# ifdef HAS_STDLIB_MODULES
import std;
import std.compat;
# else
# include <cstdlib>
# include <exception>
# include <future>
# include <iostream>
# include <string>
# include <system_error>
# include <thread>
# include <utility>
# endif
import asio;
# else
# include <asio.hpp>
# include <iostream>
# endif
#include <asio.hpp>
#include <iostream>

//------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions asio/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include(../../cmake/windows-set-path.cmake OPTIONAL)
# ---- Dependencies ----

if(PROJECT_IS_TOP_LEVEL)
find_package(asio 1.32.0 EXACT REQUIRED)
find_package(asio 1.32.0.1 EXACT REQUIRED)
enable_testing()
endif()

Expand All @@ -35,7 +35,7 @@ if(NOT PROJECT_IS_TOP_LEVEL)
add_test(
NAME find-package-test
COMMAND ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C Debug --build-and-test
"${CMAKE_SOURCE_DIR}/src/examples" "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator
"${CMAKE_SOURCE_DIR}/module/tests" "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator
${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
Expand Down

0 comments on commit 62951db

Please sign in to comment.