diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f84ed28..818356f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -# Copyright 2022 Alexander Grund +# Copyright 2022-2025 Alexander Grund # # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) @@ -32,7 +32,7 @@ jobs: with: clangFormatVersion: 10 - posix: + Build: defaults: run: shell: bash @@ -42,7 +42,7 @@ jobs: matrix: include: # Linux, gcc - - { compiler: gcc-7, cxxstd: '14,17', boostBranch: boost-1.86.0, os: ubuntu-20.04 } + - { compiler: gcc-7, cxxstd: '14,17', boostBranch: boost-1.86.0, os: ubuntu-latest, container: 'ubuntu:20.04' } - { compiler: gcc-10, cxxstd: '14,17,20', boostBranch: boost-1.86.0, os: ubuntu-22.04 } - { compiler: gcc-12, cxxstd: '14,17,20', boostBranch: master, os: ubuntu-22.04 } - { compiler: gcc-14, cxxstd: '14,17,20', boostBranch: boost-1.86.0, os: ubuntu-24.04 } @@ -53,8 +53,13 @@ jobs: - { compiler: clang-18, cxxstd: '14,17,20', boostBranch: boost-1.86.0, os: ubuntu-24.04 } - { compiler: clang-18, cxxstd: '14,17,20', boostBranch: master, os: ubuntu-24.04 } + # Windows + - { toolset: msvc-14.2, os: windows-2019, cxxstd: 14, generator: 'Visual Studio 16 2019' } + - { toolset: gcc, os: windows-2019, cxxstd: 17, generator: 'MinGW Makefiles' } + - { toolset: msvc-14.3, os: windows-2022, cxxstd: 20, generator: 'Visual Studio 17 2022' } + - { name: Collect coverage, coverage: yes, - compiler: gcc-8, cxxstd: '14', boostBranch: boost-1.86.0, os: ubuntu-20.04 } + compiler: gcc-8, cxxstd: '14', boostBranch: boost-1.86.0, os: ubuntu-latest, container: 'ubuntu:20.04' } timeout-minutes: 120 runs-on: ${{matrix.os}} @@ -75,6 +80,7 @@ jobs: apt-get -o Acquire::Retries=$NET_RETRY_COUNT update apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y g++ git cmake git config --global pack.threads 0 + git config --global --add safe.directory "$GITHUB_WORKSPACE" # Avoid ownership issues of repo in container - uses: actions/checkout@v4 with: @@ -83,7 +89,7 @@ jobs: # Checking out Boost and all its submodules takes ages... - name: Cache Boost - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: boost-root key: boost-${{matrix.boostBranch}} @@ -98,6 +104,8 @@ jobs: - name: Install packages and setup env run: | + B2_TOOLSET=${{matrix.toolset}} + if [[ ! "${{matrix.os}}" == "windows-"* ]]; then sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update CXX=${{matrix.compiler}} CXX="${CXX/gcc-/g++-}" @@ -107,19 +115,30 @@ jobs: CXX="ccache ${CXX/clang-/clang++-}" echo "CXX=$CXX" >> $GITHUB_ENV echo "CC=${{matrix.compiler}}" >> $GITHUB_ENV - if [[ "$CXX" =~ clang ]]; then - B2_TOOLSET=clang - else - B2_TOOLSET=gcc + if [[ -z $B2_TOOLSET ]]; then + if [[ "$CXX" =~ clang ]]; then + B2_TOOLSET=clang + else + B2_TOOLSET=gcc + fi fi - echo "B2_TOOLSET=$B2_TOOLSET" >> $GITHUB_ENV - echo "using $B2_TOOLSET : : $CXX ;" > ~/user-config.jam - # Move the Boost root to a sibling folder - mv boost-root .. - echo "BOOST_ROOT=${{github.workspace}}/../boost-root" >> $GITHUB_ENV + [[ -z $CXX ]] || echo "using $B2_TOOLSET : : $CXX ;" > ~/user-config.jam + fi + echo "B2_TOOLSET=$B2_TOOLSET" >> $GITHUB_ENV + + B2_FLAGS+=" --toolset=$B2_TOOLSET cxxstd=${{matrix.cxxstd}}" + if [[ "${{matrix.coverage}}" == "yes" ]]; then + B2_FLAGS+=" cxxflags=--coverage linkflags=--coverage" + fi + echo "B2_FLAGS=$B2_FLAGS" >> $GITHUB_ENV + + # Move the Boost root to a sibling folder + mv boost-root .. + echo "BOOST_ROOT=${{github.workspace}}/../boost-root" >> $GITHUB_ENV - name: Cache ccache uses: hendrikmuhs/ccache-action@v1 + if: startsWith(matrix.os, 'ubuntu') with: key: ${{matrix.os}}-${{matrix.compiler}}-${{matrix.boostBranch}} @@ -129,11 +148,17 @@ jobs: - name: Boost build run: | - B2_FLAGS="cxxstd=${{matrix.cxxstd}}" - if [[ "${{matrix.coverage}}" == "yes" ]]; then - B2_FLAGS="$B2_FLAGS cxxflags=--coverage linkflags=--coverage" - fi - scripts/build.sh --toolset=$B2_TOOLSET $B2_FLAGS -j3 + ./b2 "$GITHUB_WORKSPACE/test" -q $B2_FLAGS -j3 + ./b2 "$GITHUB_WORKSPACE/doc//mock_examples" -q $B2_FLAGS "$@" + working-directory: ${{env.BOOST_ROOT}} + + - name: Run inspect check + run: ./b2 "$GITHUB_WORKSPACE/test//inspect" -q $B2_FLAGS + working-directory: ${{env.BOOST_ROOT}} + + - name: Build doc + if: startsWith(matrix.os, 'ubuntu') + run: scripts/build_doc.sh $B2_FLAGS -j3 - name: Collect coverage if: matrix.coverage @@ -164,9 +189,21 @@ jobs: run: | mkdir build && cd build CXX_STANDARD="${{matrix.cxxstd}}" - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-std=c++${CXX_STANDARD##*,}" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_VERBOSE_MAKEFILE=ON - cmake --build . --config Debug -- -j3 - ctest --output-on-failure --build-config Debug -j3 + if [[ "${{matrix.os}}" == "windows-"* ]]; then + extra_args=() + else + extra_args=(-DCMAKE_CXX_COMPILER_LAUNCHER=ccache) + fi + if [[ -n "${{matrix.generator}}" ]]; then + extra_args+=(-G "${{matrix.generator}}") + fi + if [[ "${{matrix.generator}}" == "MinGW"* ]]; then + extra_args+=(-DCMAKE_CXX_FLAGS="-Wa,-mbig-obj") + fi + echo "Using extra args: ${extra_args[*]}" + cmake .. -DCMAKE_BUILD_TYPE=Debug -DBoost_ROOT="$BOOST_ROOT/stage" -DCMAKE_CXX_STANDARD="${CXX_STANDARD##*,}" "${extra_args[@]}" -DCMAKE_VERBOSE_MAKEFILE=ON -DBoost_DEBUG=ON -DBoost_VERBOSE=ON + cmake --build . --config Debug --parallel 3 + ctest --output-on-failure --build-config Debug - name: Cleanup Boost folder to reduce cache usage if: ${{ always() }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2666c20..a0b79ae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -# Copyright 2020 Alexander Grund +# Copyright 2020-2025 Alexander Grund # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) @@ -14,7 +14,7 @@ jobs: name: Create Release runs-on: ubuntu-latest env: - BOOST_VERSION: 1.71.0 + BOOST_VERSION: 1.87.0 BOOST_ROOT: ${{github.workspace}}/dependencies/boost steps: - uses: actions/checkout@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ddc100..c232f78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ -# Copyright 2019 Alexander Grund +# Copyright 2019-2025 Alexander Grund # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.8) -project(turtle VERSION 1.3.2 LANGUAGES CXX) +cmake_minimum_required(VERSION 3.16..3.20) +project(turtle VERSION 2.0.0 LANGUAGES CXX) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(IS_ROOT_PROJECT ON) @@ -18,7 +18,11 @@ option(TURTLE_INSTALL "Enable to add install target" ${IS_ROOT_PROJECT}) if(WIN32 AND NOT DEFINED Boost_USE_STATIC_LIBS) set(Boost_USE_STATIC_LIBS ON) endif() -find_package(Boost 1.58 REQUIRED) + +# Allows boost to be build by parent project +if(NOT TARGET Boost::boost) + find_package(Boost 1.58 REQUIRED) +endif() set(MOCK_VERSION "\"${PROJECT_VERSION}\"") set(_turtleVersionFile ${CMAKE_CURRENT_BINARY_DIR}/include/turtle/version.hpp) @@ -67,14 +71,7 @@ if(TURTLE_INSTALL) INSTALL_DESTINATION ${configInstallDestination} ) - if(NOT CMAKE_VERSION VERSION_LESS 3.14) - write_basic_package_version_file(${versionFile} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) - else() - set(OLD_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) - set(CMAKE_SIZEOF_VOID_P "") - write_basic_package_version_file(${versionFile} COMPATIBILITY SameMajorVersion) - set(CMAKE_SIZEOF_VOID_P ${OLD_CMAKE_SIZEOF_VOID_P}) - endif() + write_basic_package_version_file(${versionFile} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) install(FILES ${configFile} ${versionFile} DESTINATION ${configInstallDestination}) diff --git a/appveyor.yml b/appveyor.yml index faa42f7..c02348d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,8 +2,8 @@ # subject to the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) # -# Copyright Mathieu Champlon 2015. -# Copyright Alexander Grund 2020. +# Copyright 2015 Mathieu Champlon +# Copyright 2020-2025 Alexander Grund skip_branch_with_pr: true @@ -12,6 +12,10 @@ branches: - main environment: + global: + ADDRESS_MODEL: 32,64 + VARIANT: debug,release + matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 BOOST: 1_65_1 @@ -19,17 +23,38 @@ environment: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 BOOST: 1_65_1 TOOLSET: msvc-14.1 - CXX_STANDARD: 14 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - BOOST: 1_67_0 + BOOST: 1_69_0 TOOLSET: msvc-14.1 - CXX_STANDARD: 14 - # CXX_STANDARD: 17 + CXX_STANDARD: 14,17 + ADDRESS_MODEL: 64 + VARIANT: debug + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + BOOST: 1_83_0 + TOOLSET: msvc-14.3 + CXX_STANDARD: 14,17,20 + ADDRESS_MODEL: 64 + VARIANT: debug + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + BOOST: 1_86_0 + TOOLSET: msvc-14.3 + CXX_STANDARD: 14,17 + ADDRESS_MODEL: 64 + VARIANT: debug + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + BOOST: 1_86_0 + TOOLSET: msvc-14.3 + CXX_STANDARD: 20 + + # CMake builds - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 BOOST: 1_65_1 CMAKE: true - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - BOOST: 1_77_0 + BOOST: 1_83_0 + CMAKE: true + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + BOOST: 1_86_0 CMAKE: true install: @@ -55,8 +80,9 @@ build_script: - cd %BOOST_ROOT% - call bootstrap.bat - cd %APPVEYOR_BUILD_FOLDER% - - if NOT "%CXX_STANDARD%"=="" set CXX_FLAGS=cxxflags=/std:c++%CXX_STANDARD% - - set BUILD_ARGS=address-model=32,64 variant=debug,release + - if NOT "%CXX_STANDARD%"=="" set CXX_FLAGS=cxxstd=%CXX_STANDARD% + - set BUILD_ARGS=address-model=%ADDRESS_MODEL% variant=%VARIANT% + - set BOOST_TEST_LOG_LEVEL=all - call scripts\build.bat --toolset=%TOOLSET% %CXX_FLAGS% -j3 for: diff --git a/doc/example/reference.cpp b/doc/example/reference.cpp index 2b19a4e..33d71b5 100644 --- a/doc/example/reference.cpp +++ b/doc/example/reference.cpp @@ -544,6 +544,7 @@ bool custom_constraint(int expected, int actual) return expected == actual; } +#if MOCK_CXX_VERSION < 201703L BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_standard_library_functor) { mock_class c; @@ -551,6 +552,7 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_standard_lib std::bind1st(std::ptr_fun(&custom_constraint), 42)); // std::ptr_fun creates an std::unary_function c.method(42); } +#endif //] } // namespace constraints_example_3 diff --git a/include/turtle/config.hpp b/include/turtle/config.hpp index 111d09d..9395005 100644 --- a/include/turtle/config.hpp +++ b/include/turtle/config.hpp @@ -1,6 +1,7 @@ // http://turtle.sourceforge.net // // Copyright Mathieu Champlon 2009 +// Copyright 2020-2025 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -24,10 +25,24 @@ # endif #endif -#if defined(__cpp_lib_uncaught_exceptions) || defined(_MSC_VER) && (_MSC_VER >= 1900) -# ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS +#ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS +# if(defined(__cpp_lib_uncaught_exceptions) && __cpp_lib_uncaught_exceptions >= 201411) || \ + (defined(_MSC_VER) && _MSC_VER >= 1900) # define MOCK_UNCAUGHT_EXCEPTIONS # endif #endif +#if BOOST_VERSION >= 107700 +# define MOCK_CXX_VERSION BOOST_CXX_VERSION +#elif defined(_MSC_VER) +# ifdef _MSVC_LANG +# define MOCK_CXX_VERSION _MSVC_LANG +# elif defined(_HAS_CXX17) +# define MOCK_CXX_VERSION 201703L +# endif +#endif +#ifndef MOCK_CXX_VERSION +# define MOCK_CXX_VERSION __cplusplus +#endif + #endif // MOCK_CONFIG_HPP_INCLUDED diff --git a/include/turtle/constraint.hpp b/include/turtle/constraint.hpp index 8dddb22..2eb7cf5 100644 --- a/include/turtle/constraint.hpp +++ b/include/turtle/constraint.hpp @@ -1,6 +1,7 @@ // http://turtle.sourceforge.net // // Copyright Mathieu Champlon 2008 +// Copyright 2020-2025 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -17,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/include/turtle/detail/function_impl.hpp b/include/turtle/detail/function_impl.hpp index e3524a2..c11f386 100644 --- a/include/turtle/detail/function_impl.hpp +++ b/include/turtle/detail/function_impl.hpp @@ -1,6 +1,7 @@ // http://turtle.sourceforge.net // -// Copyright Mathieu Champlon 2012 +// Copyright 2012 Mathieu Champlon +// Copyright 2025 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -80,7 +81,7 @@ namespace mock { namespace detail { typedef safe_error> error_type; public: - function_impl() : context_(0), valid_(true), exceptions_(exceptions()), mutex_(std::make_shared()) {} + function_impl() : exceptions_(exceptions()), mutex_(std::make_shared()) {} virtual ~function_impl() { if(valid_ && exceptions_ >= exceptions()) @@ -314,8 +315,8 @@ namespace mock { namespace detail { }; std::list expectations_; - context* context_; - mutable bool valid_; + context* context_ = nullptr; + mutable bool valid_ = true; const int exceptions_; const std::shared_ptr mutex_; }; diff --git a/include/turtle/detail/mock_impl.hpp b/include/turtle/detail/mock_impl.hpp index 211e81c..59fe4e0 100644 --- a/include/turtle/detail/mock_impl.hpp +++ b/include/turtle/detail/mock_impl.hpp @@ -1,6 +1,7 @@ // http://turtle.sourceforge.net // // Copyright Mathieu Champlon 2008 +// Copyright 2022-2025 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,7 +15,7 @@ #include "signature.hpp" #include "signature_traits.hpp" #include "type_name.hpp" -#include +#include #include #include @@ -49,47 +50,47 @@ namespace mock { namespace detail { return t##_mock_; \ } -#define MOCK_PARAM(S) mock::detail::parameter_t < S -#define MOCK_DECL_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > p##n -#define MOCK_DECL_PARAMS(n, S) BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S)) -#define MOCK_DECL(M, n, S, c) mock::detail::result_type_t M(MOCK_DECL_PARAMS(n, S)) c +#define MOCK_PARAM(S, n) mock::detail::parameter_t -#define MOCK_FORWARD_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n >> (p##n) -#define MOCK_FORWARD_PARAMS(n, S) BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, std::forward < MOCK_PARAM(S)) -#define MOCK_METHOD_AUX(M, n, S, t, c) \ - static_assert(n == mock::detail::function_arity_t::value, "Arity mismatch"); \ - MOCK_DECL(M, n, S, c) { return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); } +#define MOCK_DECL_PARAM(z, n, S) MOCK_PARAM(S, n) p##n +#define MOCK_DECL_PARAMS(n, S) BOOST_PP_ENUM(n, MOCK_DECL_PARAM, S) +#define MOCK_DECL(name, arity, signature, qualifier) \ + mock::detail::result_type_t name(MOCK_DECL_PARAMS(arity, signature)) qualifier -#define MOCK_METHOD_EXT(M, n, S, t) \ - MOCK_METHOD_AUX(M, n, S, t, ) \ - MOCK_METHOD_AUX(M, n, S, t, const) \ - MOCK_METHOD_HELPER(S, t) -#define MOCK_CONST_METHOD_EXT(M, n, S, t) \ - MOCK_METHOD_AUX(M, n, S, t, const) \ - MOCK_METHOD_HELPER(S, t) -#define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) \ - MOCK_METHOD_AUX(M, n, S, t, ) \ - MOCK_METHOD_HELPER(S, t) - -#define MOCK_FUNCTION_HELPER(S, t, s) \ - s mock::detail::function& t##_mock(mock::detail::context& context, boost::unit_test::const_string instance) \ - { \ - static mock::detail::function f; \ - return f(context, instance); \ +#define MOCK_FORWARD_PARAM(z, n, S) std::forward(p##n) +#define MOCK_FORWARD_PARAMS(n, S) BOOST_PP_ENUM(n, MOCK_FORWARD_PARAM, S) +#define MOCK_METHOD_AUX(name, arity, signature, identifier, qualifier) \ + MOCK_DECL(name, arity, signature, qualifier) \ + { \ + return MOCK_ANONYMOUS_HELPER(identifier)(MOCK_FORWARD_PARAMS(arity, signature)); \ } -#define MOCK_CONSTRUCTOR_AUX(T, n, A, t) \ - T(MOCK_DECL_PARAMS(n, void A)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A)); } \ - MOCK_FUNCTION_HELPER(void A, t, static) +#define MOCK_METHOD_EXT(name, arity, signature, identifier) \ + MOCK_METHOD_AUX(name, arity, signature, identifier, ) \ + MOCK_METHOD_AUX(name, arity, signature, identifier, const) \ + MOCK_METHOD_HELPER(signature, identifier) +#define MOCK_CONST_METHOD_EXT(name, arity, signature, identifier) \ + MOCK_METHOD_AUX(name, arity, signature, identifier, const) \ + MOCK_METHOD_HELPER(signature, identifier) +#define MOCK_NON_CONST_METHOD_EXT(name, arity, signature, identifier) \ + MOCK_METHOD_AUX(name, arity, signature, identifier, ) \ + MOCK_METHOD_HELPER(signature, identifier) -#define MOCK_FUNCTION_AUX(F, n, S, t, s) \ - MOCK_FUNCTION_HELPER(S, t, s) \ - static_assert(n == mock::detail::function_arity_t::value, "Arity mismatch"); \ - s MOCK_DECL(F, n, S, ) { return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); } +#define MOCK_FUNCTION_HELPER(signature, identifier, prefix) \ + prefix mock::detail::function& identifier##_mock(mock::detail::context& context, \ + boost::unit_test::const_string instance) \ + { \ + static mock::detail::function f; \ + return f(context, instance); \ + } -#define MOCK_VARIADIC_ELEM_0(e0, ...) e0 -#define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1 -#define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2 +#define MOCK_FUNCTION_AUX(name, arity, signature, identifier, prefix) \ + MOCK_FUNCTION_HELPER(signature, identifier, prefix) \ + static_assert(arity == mock::detail::function_arity_t::value, "Arity mismatch"); \ + prefix MOCK_DECL(name, arity, signature, ) \ + { \ + return MOCK_HELPER(identifier)(MOCK_FORWARD_PARAMS(arity, signature)); \ + } #define MOCK_REPLACED_MACRO_ERROR(oldName, newName) static_assert(false, #oldName " has been replaced by " #newName) // Replaced macros diff --git a/include/turtle/mock.hpp b/include/turtle/mock.hpp index 9e78a4f..31d5dc8 100644 --- a/include/turtle/mock.hpp +++ b/include/turtle/mock.hpp @@ -1,6 +1,7 @@ // http://turtle.sourceforge.net // // Copyright Mathieu Champlon 2008 +// Copyright 2022-2025 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -15,6 +16,7 @@ #include "object.hpp" #include "reset.hpp" #include "verify.hpp" +#include /// MOCK_CLASS( name ) /// Define a class @@ -51,7 +53,12 @@ /// MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier ) /// As constructors do not have a return type, the usual signature gets restricted here to just the parameters. -#define MOCK_CONSTRUCTOR(T, arity, parameters, identifier) MOCK_CONSTRUCTOR_AUX(T, arity, parameters, identifier) +#define MOCK_CONSTRUCTOR(T, arity, parameters, identifier) \ + T(MOCK_DECL_PARAMS(arity, void parameters)) \ + { \ + MOCK_HELPER(identifier)(MOCK_FORWARD_PARAMS(arity, void parameters)); \ + } \ + MOCK_FUNCTION_HELPER(void parameters, identifier, static) /// MOCK_DESTRUCTOR( [calling convention] ~name, identifier ) #define MOCK_DESTRUCTOR(T, identifier) \ @@ -69,39 +76,41 @@ /// generates both const and non-const methods /// The 'signature' can be omitted if it can be uniquely identified from the base class /// if 'identifier' is omitted it will default to 'name' -#define MOCK_METHOD(M, ...) \ - MOCK_METHOD_EXT(M, \ - MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \ - MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \ - MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, )) +#define MOCK_METHOD(M, ...) \ + MOCK_METHOD_EXT(M, \ + BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), \ + BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, MOCK_SIGNATURE(M), ), \ + BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__, M, M, )) /// MOCK_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) /// generates only the const version of the method /// The 'signature' can be omitted if it can be uniquely identified from the base class /// if 'identifier' is omitted it will default to 'name' -#define MOCK_CONST_METHOD(M, ...) \ - MOCK_CONST_METHOD_EXT(M, \ - MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \ - MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \ - MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, )) +#define MOCK_CONST_METHOD(M, ...) \ + MOCK_CONST_METHOD_EXT(M, \ + BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), \ + BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, MOCK_SIGNATURE(M), ), \ + BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__, M, M, )) /// MOCK_NON_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) /// generates only the non-const version of the method /// The 'signature' can be omitted if it can be uniquely identified from the base class /// if 'identifier' is omitted it will default to 'name' -#define MOCK_NON_CONST_METHOD(M, ...) \ - MOCK_NON_CONST_METHOD_EXT(M, \ - MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \ - MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \ - MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, )) +#define MOCK_NON_CONST_METHOD(M, ...) \ + MOCK_NON_CONST_METHOD_EXT(M, \ + BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), \ + BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, MOCK_SIGNATURE(M), ), \ + BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__, M, M, )) /// MOCK_FUNCTION( [calling convention] name, arity, signature[, identifier] ) /// if 'identifier' is omitted it will default to 'name' #define MOCK_FUNCTION(F, arity, ...) \ - MOCK_FUNCTION_AUX(F, arity, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), inline) + MOCK_FUNCTION_AUX( \ + F, arity, BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, F, ), inline) /// MOCK_STATIC_METHOD( [calling convention] name, arity, signature[, identifier] ) /// if 'identifier' is omitted it will default to 'name' #define MOCK_STATIC_METHOD(F, arity, ...) \ - MOCK_FUNCTION_AUX(F, arity, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static) + MOCK_FUNCTION_AUX( \ + F, arity, BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, F, ), static) /// MOCK_EXPECT( identifier ) /// Begin setting up expectation for the identifier diff --git a/scripts/build.sh b/scripts/build.sh index 3261c23..2b69951 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,6 +1,7 @@ #!/bin/sh # Copyright (C) 2015 Mathieu Champlon +# Copyright (C) 2025 Alexander Grund # # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) @@ -18,3 +19,6 @@ scripts/build_doc.sh "$@" cd "$BOOST_ROOT" ./b2 "$PROJECT_DIR/doc//mock_examples" -q "$@" + +cd "$BOOST_ROOT" +./b2 "$PROJECT_DIR/test//inspect" -q "$@" diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 4575a0e..31a4292 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -1,4 +1,5 @@ -# Copyright Mathieu Champlon 2012 +# Copyright 2012 Mathieu Champlon +# Copyright 2025 Alexander Grund # # Distributed under the Boost Software License version 1.0. (See # accompanying file LICENSE_1_0.txt or copy at @@ -15,22 +16,27 @@ project path-constant parent : .. ; -alias mock_inspect : - [ run /boost/tools/inspect//inspect/release - : $(parent) -text -brief : : : inspect - ] -; +run /boost/tools/inspect//inspect/release : $(parent) -text -brief : : always_show_run_output : inspect ; +explicit inspect ; -rule run-test ( name ) +rule run-test ( name : options * ) { - run $(name) defined_1.cpp defined_2.cpp undefined.cpp /boost//unit_test_framework : : : : $(name)_ ; - run $(name) undefined.cpp /boost//unit_test_framework : : : MOCK_USE_CONVERSIONS : $(name)_use_conversions ; - run $(name) undefined.cpp /boost//unit_test_framework /boost//thread : : : MOCK_THREAD_SAFE BOOST_THREAD_USES_MOVE multi : $(name)_thread_safe ; + run $(name) defined_1.cpp defined_2.cpp undefined.cpp /boost//unit_test_framework : : : $(options) : $(name)_ ; + run $(name) undefined.cpp /boost//unit_test_framework : : : $(options) MOCK_USE_CONVERSIONS : $(name)_use_conversions ; + run $(name) undefined.cpp /boost//unit_test_framework /boost//thread : : : $(options) MOCK_THREAD_SAFE BOOST_THREAD_USES_MOVE multi : $(name)_thread_safe ; } rule run-tests { - for name in [ glob test_*.cpp detail/test_*.cpp ] { run-test $(name) ; } + for name in [ glob test_*.cpp ] { run-test $(name) ; } + # Avoid object file getting to big on MinGW + run-test detail/test_function.cpp : + gcc,windows:on + gcc,windows:space ; + run-test detail/test_invocation.cpp ; + run-test detail/test_is_functor.cpp ; + run-test detail/test_signature.cpp ; + run-test detail/test_type_name.cpp ; } alias mock_tests : [ run-tests ] ; diff --git a/test/detail/test_is_functor.cpp b/test/detail/test_is_functor.cpp index 1a50e29..0a2f5b2 100644 --- a/test/detail/test_is_functor.cpp +++ b/test/detail/test_is_functor.cpp @@ -67,6 +67,8 @@ BOOST_AUTO_TEST_CASE(function_pointer_is_functor) is_not_functor(&f2); } +// ptr_fun, bin1st is removed in C++17 +#if MOCK_CXX_VERSION < 201703L BOOST_AUTO_TEST_CASE(std_ptr_fun_is_functor) { is_functor(std::ptr_fun(&f1)); @@ -77,6 +79,7 @@ BOOST_AUTO_TEST_CASE(std_bind_first_is_functor) { is_functor(std::bind1st(std::ptr_fun(&f2), "")); } +#endif BOOST_AUTO_TEST_CASE(bind_is_functor) {