mirror of
https://github.com/boostorg/redis.git
synced 2026-01-19 04:42:09 +00:00
subdir tests
This commit is contained in:
@@ -15,16 +15,17 @@ target_link_libraries(boost_redis_src PRIVATE boost_redis_project_options)
|
||||
add_library(boost_redis_tests_common STATIC common.cpp)
|
||||
target_compile_features(boost_redis_tests_common PRIVATE cxx_std_17)
|
||||
target_link_libraries(boost_redis_tests_common PRIVATE boost_redis_project_options)
|
||||
if (NOT BOOST_REDIS_MAIN_PROJECT)
|
||||
target_link_libraries(boost_redis_tests_common PUBLIC Boost::unit_test_framework)
|
||||
endif()
|
||||
|
||||
macro(make_test TEST_NAME STANDARD)
|
||||
add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
|
||||
target_link_libraries(${TEST_NAME} PRIVATE boost_redis_src boost_redis_tests_common)
|
||||
target_link_libraries(${TEST_NAME} PRIVATE boost_redis_project_options)
|
||||
target_compile_features(${TEST_NAME} PRIVATE cxx_std_${STANDARD})
|
||||
add_test(${TEST_NAME} ${TEST_NAME})
|
||||
set(EXE_NAME "boost_redis_${TEST_NAME}")
|
||||
add_executable(${EXE_NAME} ${TEST_NAME}.cpp)
|
||||
target_link_libraries(${EXE_NAME} PRIVATE
|
||||
boost_redis_src
|
||||
boost_redis_tests_common
|
||||
boost_redis_project_options
|
||||
)
|
||||
target_compile_features(${EXE_NAME} PRIVATE cxx_std_${STANDARD})
|
||||
add_test(${EXE_NAME} ${EXE_NAME})
|
||||
endmacro()
|
||||
|
||||
make_test(test_conn_quit 17)
|
||||
|
||||
13
test/cmake_b2_test/CMakeLists.txt
Normal file
13
test/cmake_b2_test/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.5...3.22)
|
||||
|
||||
project(boost_redis_b2_test LANGUAGES CXX)
|
||||
|
||||
find_package(Boost REQUIRED COMPONENTS headers)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main PRIVATE Boost::headers Threads::Threads OpenSSL::Crypto OpenSSL::SSL)
|
||||
|
||||
include(CTest)
|
||||
add_test(NAME main COMMAND main)
|
||||
15
test/cmake_b2_test/main.cpp
Normal file
15
test/cmake_b2_test/main.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE.txt)
|
||||
*/
|
||||
|
||||
|
||||
#include <boost/redis/connection.hpp>
|
||||
#include <boost/redis/src.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::redis::connection conn(boost::asio::system_executor{});
|
||||
return static_cast<int>(!conn.will_reconnect());
|
||||
}
|
||||
86
test/cmake_test/CMakeLists.txt
Normal file
86
test/cmake_test/CMakeLists.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
cmake_minimum_required(VERSION 3.5...3.22)
|
||||
|
||||
project(cmake_subdir_test LANGUAGES CXX)
|
||||
|
||||
option(BOOST_CI_INSTALL_TEST "Whether to build install or add_subdirectory tests" OFF)
|
||||
|
||||
if(BOOST_CI_INSTALL_TEST)
|
||||
find_package(boost_redis REQUIRED)
|
||||
else()
|
||||
# Generated by boostdep --brief redis
|
||||
set(_DEPENDENCIES
|
||||
# Primary dependencies
|
||||
asio
|
||||
assert
|
||||
core
|
||||
mp11
|
||||
system
|
||||
throw_exception
|
||||
|
||||
# Secondary dependencies
|
||||
align
|
||||
array
|
||||
bind
|
||||
chrono
|
||||
config
|
||||
context
|
||||
coroutine
|
||||
date_time
|
||||
exception
|
||||
"function"
|
||||
regex
|
||||
smart_ptr
|
||||
type_traits
|
||||
utility
|
||||
static_assert
|
||||
variant2
|
||||
winapi
|
||||
integer
|
||||
move
|
||||
mpl
|
||||
predef
|
||||
ratio
|
||||
typeof
|
||||
pool
|
||||
algorithm
|
||||
io
|
||||
lexical_cast
|
||||
numeric/conversion
|
||||
range
|
||||
tokenizer
|
||||
tuple
|
||||
preprocessor
|
||||
concept_check
|
||||
container_hash
|
||||
iterator
|
||||
unordered
|
||||
describe
|
||||
container
|
||||
conversion
|
||||
detail
|
||||
optional
|
||||
rational
|
||||
intrusive
|
||||
function_types
|
||||
fusion
|
||||
functional
|
||||
)
|
||||
|
||||
# Build our dependencies, so the targets Boost::xxx are defined
|
||||
set(_BOOST_ROOT ../../../..)
|
||||
foreach(_DEPENDENCY IN LISTS _DEPENDENCIES)
|
||||
add_subdirectory(${_BOOST_ROOT}/libs/${_DEPENDENCY} boostorg/${_DEPENDENCY})
|
||||
endforeach()
|
||||
|
||||
# Build our project
|
||||
add_subdirectory(${_BOOST_ROOT}/libs/redis boostorg/redis)
|
||||
endif()
|
||||
|
||||
# Copied from Alexander Grund's Boost.CI
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main PRIVATE Boost::redis)
|
||||
|
||||
include(CTest)
|
||||
add_test(NAME main COMMAND main)
|
||||
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
15
test/cmake_test/main.cpp
Normal file
15
test/cmake_test/main.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE.txt)
|
||||
*/
|
||||
|
||||
|
||||
#include <boost/redis/connection.hpp>
|
||||
#include <boost/redis/src.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::redis::connection conn(boost::asio::system_executor{});
|
||||
return static_cast<int>(!conn.will_reconnect());
|
||||
}
|
||||
97
tools/ci.py
Normal file → Executable file
97
tools/ci.py
Normal file → Executable file
@@ -10,7 +10,10 @@ import argparse
|
||||
|
||||
|
||||
_is_windows = os.name == 'nt'
|
||||
_boost_root = Path(os.path.expanduser('~')).joinpath('boost-root')
|
||||
_home = Path(os.path.expanduser('~'))
|
||||
_boost_root = _home.joinpath('boost-root')
|
||||
_b2_distro = _home.joinpath('boost-b2-distro')
|
||||
_cmake_distro = _home.joinpath('boost-cmake-distro')
|
||||
_b2_command = str(_boost_root.joinpath('b2'))
|
||||
|
||||
|
||||
@@ -68,7 +71,10 @@ def _deduce_boost_branch() -> str:
|
||||
return res
|
||||
|
||||
|
||||
def _install_boost(
|
||||
# Gets Boost (develop or master, depending on the CI branch we're operating on),
|
||||
# with the required dependencies, and leaves it at _boost_root. Places our library,
|
||||
# located under source_dir, under $BOOST_ROOT/libs. Also runs the bootstrap script so b2 is usable.
|
||||
def _setup_boost(
|
||||
source_dir: Path
|
||||
) -> None:
|
||||
assert source_dir.is_absolute()
|
||||
@@ -103,21 +109,22 @@ def _install_boost(
|
||||
_run([_b2_command, 'headers'])
|
||||
|
||||
|
||||
def _build_b2_distro(
|
||||
install_prefix: Path
|
||||
):
|
||||
# Builds a Boost distribution using ./b2 install, and places it into _b2_distro.
|
||||
# This emulates a regular Boost distribution, like the ones in releases
|
||||
def _build_b2_distro():
|
||||
os.chdir(str(_boost_root))
|
||||
_run([
|
||||
_b2_command,
|
||||
'--prefix={}'.format(install_prefix),
|
||||
'--prefix={}'.format(_b2_distro),
|
||||
'--with-system',
|
||||
'-d0',
|
||||
'install'
|
||||
])
|
||||
|
||||
|
||||
# Builds a Boost distribution using cmake, and places it into _cmake_distro.
|
||||
# It includes only our library and any dependency.
|
||||
def _build_cmake_distro(
|
||||
install_prefix: Path,
|
||||
generator: str,
|
||||
build_type: str,
|
||||
cxxstd: str,
|
||||
@@ -133,7 +140,7 @@ def _build_cmake_distro(
|
||||
'-DCMAKE_CXX_STANDARD={}'.format(cxxstd),
|
||||
'-DBOOST_INCLUDE_LIBRARIES=redis',
|
||||
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
|
||||
'-DCMAKE_INSTALL_PREFIX={}'.format(install_prefix),
|
||||
'-DCMAKE_INSTALL_PREFIX={}'.format(_cmake_distro),
|
||||
'-DBUILD_TESTING=ON',
|
||||
'-DBoost_VERBOSE=ON',
|
||||
'-DCMAKE_INSTALL_MESSAGE=NEVER',
|
||||
@@ -144,8 +151,10 @@ def _build_cmake_distro(
|
||||
_run(['cmake', '--build', '.', '--target', 'install', '--config', build_type])
|
||||
|
||||
|
||||
# Builds and runs our CMake tests as a standalone project
|
||||
# (BOOST_REDIS_MAIN_PROJECT is ON) and we find_package Boost.
|
||||
# This ensures that all our test suite is run.
|
||||
def _run_cmake_standalone_tests(
|
||||
b2_distro: Path,
|
||||
generator: str,
|
||||
build_type: str,
|
||||
cxxstd: str,
|
||||
@@ -155,7 +164,7 @@ def _run_cmake_standalone_tests(
|
||||
_run([
|
||||
'cmake',
|
||||
'-DBUILD_TESTING=ON',
|
||||
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(b2_distro)),
|
||||
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_b2_distro)),
|
||||
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
|
||||
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
|
||||
'-DCMAKE_CXX_STANDARD={}'.format(cxxstd),
|
||||
@@ -167,6 +176,7 @@ def _run_cmake_standalone_tests(
|
||||
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
|
||||
|
||||
|
||||
# Tests that the library can be consumed using add_subdirectory()
|
||||
def _run_cmake_add_subdirectory_tests(
|
||||
generator: str,
|
||||
build_type: str,
|
||||
@@ -188,8 +198,8 @@ def _run_cmake_add_subdirectory_tests(
|
||||
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
|
||||
|
||||
|
||||
# Tests that the library can be consumed using find_package on a distro built by cmake
|
||||
def _run_cmake_find_package_tests(
|
||||
cmake_distro: Path,
|
||||
generator: str,
|
||||
build_type: str,
|
||||
build_shared_libs: bool = False
|
||||
@@ -203,15 +213,15 @@ def _run_cmake_find_package_tests(
|
||||
'-DBOOST_CI_INSTALL_TEST=ON',
|
||||
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
|
||||
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
|
||||
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(cmake_distro)),
|
||||
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_cmake_distro)),
|
||||
'..'
|
||||
])
|
||||
_run(['cmake', '--build', '.', '--config', build_type])
|
||||
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
|
||||
|
||||
|
||||
# Tests that the library can be consumed using find_package on a distro built by b2
|
||||
def _run_cmake_b2_find_package_tests(
|
||||
b2_distro: Path,
|
||||
generator: str,
|
||||
build_type: str,
|
||||
build_shared_libs: bool = False
|
||||
@@ -222,7 +232,7 @@ def _run_cmake_b2_find_package_tests(
|
||||
'-G',
|
||||
generator,
|
||||
'-DBUILD_TESTING=ON',
|
||||
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(b2_distro)),
|
||||
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_b2_distro)),
|
||||
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
|
||||
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
|
||||
'-DBUILD_TESTING=ON',
|
||||
@@ -232,60 +242,18 @@ def _run_cmake_b2_find_package_tests(
|
||||
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
|
||||
|
||||
|
||||
def _run_b2_tests(
|
||||
toolset: str,
|
||||
cxxstd: str,
|
||||
variant: str,
|
||||
stdlib: str = 'native',
|
||||
address_model: str = '64',
|
||||
address_sanitizer: bool = False,
|
||||
undefined_sanitizer: bool = False,
|
||||
):
|
||||
os.chdir(str(_boost_root))
|
||||
_run([
|
||||
_b2_command,
|
||||
'--abbreviate-paths',
|
||||
'toolset={}'.format(toolset),
|
||||
'cxxstd={}'.format(cxxstd),
|
||||
'address-model={}'.format(address_model),
|
||||
'variant={}'.format(variant),
|
||||
'stdlib={}'.format(stdlib),
|
||||
] + (['address-sanitizer=norecover'] if address_sanitizer else []) # can only be disabled by omitting the arg
|
||||
+ (['undefined-sanitizer=norecover'] if undefined_sanitizer else []) # can only be disabled by omitting the arg
|
||||
+ [
|
||||
'warnings-as-errors=on',
|
||||
'-j4',
|
||||
'libs/redis/test',
|
||||
'libs/redis/example'
|
||||
])
|
||||
|
||||
# Get Boost
|
||||
# Generate "pre-built" b2 distro
|
||||
# Build the library, run the tests, and install, from the superproject
|
||||
# Library tests, using the b2 Boost distribution generated before (this tests our normal dev workflow)
|
||||
# Subdir tests, using add_subdirectory() (lib can be consumed using add_subdirectory)
|
||||
# Subdir tests, using find_package with the library installed in the previous step
|
||||
# (library can be consumed using find_package on a distro built by cmake)
|
||||
|
||||
# Subdir tests, using find_package with the b2 distribution
|
||||
# (library can be consumed using find_package on a distro built by b2)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
subp = subparsers.add_parser('install-boost')
|
||||
subp = subparsers.add_parser('setup-boost')
|
||||
subp.add_argument('--source-dir', type=Path, required=True)
|
||||
subp.set_defaults(func=_install_boost)
|
||||
subp.set_defaults(func=_setup_boost)
|
||||
|
||||
subp = subparsers.add_parser('build-b2-distro')
|
||||
subp.add_argument('--install-prefix', type=Path, required=True)
|
||||
subp.set_defaults(func=_build_b2_distro)
|
||||
|
||||
subp = subparsers.add_parser('build-cmake-distro')
|
||||
subp.add_argument('--install-prefix', type=Path, required=True)
|
||||
subp.add_argument('--generator', default='Unix Makefiles')
|
||||
subp.add_argument('--build-type', default='Debug')
|
||||
subp.add_argument('--cxxstd', default='20')
|
||||
@@ -293,7 +261,6 @@ def main():
|
||||
subp.set_defaults(func=_build_cmake_distro)
|
||||
|
||||
subp = subparsers.add_parser('run-cmake-standalone-tests')
|
||||
subp.add_argument('--b2-distro', type=Path, required=True)
|
||||
subp.add_argument('--generator', default='Unix Makefiles')
|
||||
subp.add_argument('--build-type', default='Debug')
|
||||
subp.add_argument('--cxxstd', default='20')
|
||||
@@ -307,29 +274,17 @@ def main():
|
||||
subp.set_defaults(func=_run_cmake_add_subdirectory_tests)
|
||||
|
||||
subp = subparsers.add_parser('run-cmake-find-package-tests')
|
||||
subp.add_argument('--cmake-distro', type=Path, required=True)
|
||||
subp.add_argument('--generator', default='Unix Makefiles')
|
||||
subp.add_argument('--build-type', default='Debug')
|
||||
subp.add_argument('--build-shared-libs', type=_str2bool, default=False)
|
||||
subp.set_defaults(func=_run_cmake_find_package_tests)
|
||||
|
||||
subp = subparsers.add_parser('run-cmake-b2-find-package-tests')
|
||||
subp.add_argument('--cmake-distro', type=Path, required=True)
|
||||
subp.add_argument('--generator', default='Unix Makefiles')
|
||||
subp.add_argument('--build-type', default='Debug')
|
||||
subp.add_argument('--build-shared-libs', type=_str2bool, default=False)
|
||||
subp.set_defaults(func=_run_cmake_b2_find_package_tests)
|
||||
|
||||
subp = subparsers.add_parser('run-b2-tests')
|
||||
subp.add_argument('--toolset', required=True)
|
||||
subp.add_argument('--cxxstd', default='20')
|
||||
subp.add_argument('--variant', default='debug,release')
|
||||
subp.add_argument('--stdlib', default='native')
|
||||
subp.add_argument('--address-model', default='64')
|
||||
subp.add_argument('--address-sanitizer', type=_str2bool, default=False)
|
||||
subp.add_argument('--undefined-sanitizer', type=_str2bool, default=False)
|
||||
subp.set_defaults(func=_run_b2_tests)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
os.environ['CMAKE_BUILD_PARALLEL_LEVEL'] = '4'
|
||||
|
||||
Reference in New Issue
Block a user