Compare commits

..

No commits in common. "main" and "v2.0.0" have entirely different histories.
main ... v2.0.0

13 changed files with 116 additions and 219 deletions

View file

@ -1,4 +1,4 @@
# Copyright 2022-2025 Alexander Grund # Copyright 2022 Alexander Grund
# #
# Distributed under the Boost Software License, Version 1.0. # 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) # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
@ -32,7 +32,7 @@ jobs:
with: with:
clangFormatVersion: 10 clangFormatVersion: 10
Build: posix:
defaults: defaults:
run: run:
shell: bash shell: bash
@ -42,7 +42,7 @@ jobs:
matrix: matrix:
include: include:
# Linux, gcc # Linux, gcc
- { compiler: gcc-7, cxxstd: '14,17', boostBranch: boost-1.86.0, os: ubuntu-latest, container: 'ubuntu:20.04' } - { compiler: gcc-7, cxxstd: '14,17', boostBranch: boost-1.86.0, os: ubuntu-20.04 }
- { compiler: gcc-10, cxxstd: '14,17,20', boostBranch: boost-1.86.0, os: ubuntu-22.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-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 } - { compiler: gcc-14, cxxstd: '14,17,20', boostBranch: boost-1.86.0, os: ubuntu-24.04 }
@ -53,13 +53,8 @@ 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: boost-1.86.0, os: ubuntu-24.04 }
- { compiler: clang-18, cxxstd: '14,17,20', boostBranch: master, 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, - { name: Collect coverage, coverage: yes,
compiler: gcc-8, cxxstd: '14', boostBranch: boost-1.86.0, os: ubuntu-latest, container: 'ubuntu:20.04' } compiler: gcc-8, cxxstd: '14', boostBranch: boost-1.86.0, os: ubuntu-20.04 }
timeout-minutes: 120 timeout-minutes: 120
runs-on: ${{matrix.os}} runs-on: ${{matrix.os}}
@ -80,7 +75,6 @@ jobs:
apt-get -o Acquire::Retries=$NET_RETRY_COUNT update apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y g++ git cmake apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y g++ git cmake
git config --global pack.threads 0 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 - uses: actions/checkout@v4
with: with:
@ -89,7 +83,7 @@ jobs:
# Checking out Boost and all its submodules takes ages... # Checking out Boost and all its submodules takes ages...
- name: Cache Boost - name: Cache Boost
uses: actions/cache@v4 uses: actions/cache@v3
with: with:
path: boost-root path: boost-root
key: boost-${{matrix.boostBranch}} key: boost-${{matrix.boostBranch}}
@ -104,8 +98,6 @@ jobs:
- name: Install packages and setup env - name: Install packages and setup env
run: | run: |
B2_TOOLSET=${{matrix.toolset}}
if [[ ! "${{matrix.os}}" == "windows-"* ]]; then
sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
CXX=${{matrix.compiler}} CXX=${{matrix.compiler}}
CXX="${CXX/gcc-/g++-}" CXX="${CXX/gcc-/g++-}"
@ -115,30 +107,19 @@ jobs:
CXX="ccache ${CXX/clang-/clang++-}" CXX="ccache ${CXX/clang-/clang++-}"
echo "CXX=$CXX" >> $GITHUB_ENV echo "CXX=$CXX" >> $GITHUB_ENV
echo "CC=${{matrix.compiler}}" >> $GITHUB_ENV echo "CC=${{matrix.compiler}}" >> $GITHUB_ENV
if [[ -z $B2_TOOLSET ]]; then if [[ "$CXX" =~ clang ]]; then
if [[ "$CXX" =~ clang ]]; then B2_TOOLSET=clang
B2_TOOLSET=clang else
else B2_TOOLSET=gcc
B2_TOOLSET=gcc
fi
fi fi
[[ -z $CXX ]] || echo "using $B2_TOOLSET : : $CXX ;" > ~/user-config.jam echo "B2_TOOLSET=$B2_TOOLSET" >> $GITHUB_ENV
fi echo "using $B2_TOOLSET : : $CXX ;" > ~/user-config.jam
echo "B2_TOOLSET=$B2_TOOLSET" >> $GITHUB_ENV # Move the Boost root to a sibling folder
mv boost-root ..
B2_FLAGS+=" --toolset=$B2_TOOLSET cxxstd=${{matrix.cxxstd}}" echo "BOOST_ROOT=${{github.workspace}}/../boost-root" >> $GITHUB_ENV
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 - name: Cache ccache
uses: hendrikmuhs/ccache-action@v1 uses: hendrikmuhs/ccache-action@v1
if: startsWith(matrix.os, 'ubuntu')
with: with:
key: ${{matrix.os}}-${{matrix.compiler}}-${{matrix.boostBranch}} key: ${{matrix.os}}-${{matrix.compiler}}-${{matrix.boostBranch}}
@ -148,17 +129,11 @@ jobs:
- name: Boost build - name: Boost build
run: | run: |
./b2 "$GITHUB_WORKSPACE/test" -q $B2_FLAGS -j3 B2_FLAGS="cxxstd=${{matrix.cxxstd}}"
./b2 "$GITHUB_WORKSPACE/doc//mock_examples" -q $B2_FLAGS "$@" if [[ "${{matrix.coverage}}" == "yes" ]]; then
working-directory: ${{env.BOOST_ROOT}} B2_FLAGS="$B2_FLAGS cxxflags=--coverage linkflags=--coverage"
fi
- name: Run inspect check scripts/build.sh --toolset=$B2_TOOLSET $B2_FLAGS -j3
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 - name: Collect coverage
if: matrix.coverage if: matrix.coverage
@ -189,21 +164,9 @@ jobs:
run: | run: |
mkdir build && cd build mkdir build && cd build
CXX_STANDARD="${{matrix.cxxstd}}" CXX_STANDARD="${{matrix.cxxstd}}"
if [[ "${{matrix.os}}" == "windows-"* ]]; then cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-std=c++${CXX_STANDARD##*,}" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_VERBOSE_MAKEFILE=ON
extra_args=() cmake --build . --config Debug -- -j3
else ctest --output-on-failure --build-config Debug -j3
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 - name: Cleanup Boost folder to reduce cache usage
if: ${{ always() }} if: ${{ always() }}

View file

@ -1,4 +1,4 @@
# Copyright 2020-2025 Alexander Grund # Copyright 2020 Alexander Grund
# Distributed under the Boost Software License, Version 1.0. # 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) # (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 name: Create Release
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
BOOST_VERSION: 1.87.0 BOOST_VERSION: 1.71.0
BOOST_ROOT: ${{github.workspace}}/dependencies/boost BOOST_ROOT: ${{github.workspace}}/dependencies/boost
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

View file

@ -1,9 +1,9 @@
# Copyright 2019-2025 Alexander Grund # Copyright 2019 Alexander Grund
# Distributed under the Boost Software License, Version 1.0. # 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 # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.16..3.20) cmake_minimum_required(VERSION 3.8)
project(turtle VERSION 2.0.0 LANGUAGES CXX) project(turtle VERSION 1.3.2 LANGUAGES CXX)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(IS_ROOT_PROJECT ON) set(IS_ROOT_PROJECT ON)
@ -18,11 +18,7 @@ option(TURTLE_INSTALL "Enable to add install target" ${IS_ROOT_PROJECT})
if(WIN32 AND NOT DEFINED Boost_USE_STATIC_LIBS) if(WIN32 AND NOT DEFINED Boost_USE_STATIC_LIBS)
set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_LIBS ON)
endif() 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(MOCK_VERSION "\"${PROJECT_VERSION}\"")
set(_turtleVersionFile ${CMAKE_CURRENT_BINARY_DIR}/include/turtle/version.hpp) set(_turtleVersionFile ${CMAKE_CURRENT_BINARY_DIR}/include/turtle/version.hpp)
@ -71,7 +67,14 @@ if(TURTLE_INSTALL)
INSTALL_DESTINATION ${configInstallDestination} INSTALL_DESTINATION ${configInstallDestination}
) )
write_basic_package_version_file(${versionFile} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) 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()
install(FILES ${configFile} ${versionFile} DESTINATION ${configInstallDestination}) install(FILES ${configFile} ${versionFile} DESTINATION ${configInstallDestination})

View file

@ -2,8 +2,8 @@
# subject to the Boost Software License, Version 1.0. (See accompanying # 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) # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# #
# Copyright 2015 Mathieu Champlon # Copyright Mathieu Champlon 2015.
# Copyright 2020-2025 Alexander Grund # Copyright Alexander Grund 2020.
skip_branch_with_pr: true skip_branch_with_pr: true
@ -12,10 +12,6 @@ branches:
- main - main
environment: environment:
global:
ADDRESS_MODEL: 32,64
VARIANT: debug,release
matrix: matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
BOOST: 1_65_1 BOOST: 1_65_1
@ -23,38 +19,17 @@ environment:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
BOOST: 1_65_1 BOOST: 1_65_1
TOOLSET: msvc-14.1 TOOLSET: msvc-14.1
CXX_STANDARD: 14
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
BOOST: 1_69_0 BOOST: 1_67_0
TOOLSET: msvc-14.1 TOOLSET: msvc-14.1
CXX_STANDARD: 14,17 CXX_STANDARD: 14
ADDRESS_MODEL: 64 # CXX_STANDARD: 17
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 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
BOOST: 1_65_1 BOOST: 1_65_1
CMAKE: true CMAKE: true
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
BOOST: 1_83_0 BOOST: 1_77_0
CMAKE: true
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
BOOST: 1_86_0
CMAKE: true CMAKE: true
install: install:
@ -80,9 +55,8 @@ build_script:
- cd %BOOST_ROOT% - cd %BOOST_ROOT%
- call bootstrap.bat - call bootstrap.bat
- cd %APPVEYOR_BUILD_FOLDER% - cd %APPVEYOR_BUILD_FOLDER%
- if NOT "%CXX_STANDARD%"=="" set CXX_FLAGS=cxxstd=%CXX_STANDARD% - if NOT "%CXX_STANDARD%"=="" set CXX_FLAGS=cxxflags=/std:c++%CXX_STANDARD%
- set BUILD_ARGS=address-model=%ADDRESS_MODEL% variant=%VARIANT% - set BUILD_ARGS=address-model=32,64 variant=debug,release
- set BOOST_TEST_LOG_LEVEL=all
- call scripts\build.bat --toolset=%TOOLSET% %CXX_FLAGS% -j3 - call scripts\build.bat --toolset=%TOOLSET% %CXX_FLAGS% -j3
for: for:

View file

@ -544,7 +544,6 @@ bool custom_constraint(int expected, int actual)
return expected == actual; return expected == actual;
} }
#if MOCK_CXX_VERSION < 201703L
BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_standard_library_functor) BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_standard_library_functor)
{ {
mock_class c; mock_class c;
@ -552,7 +551,6 @@ 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 std::bind1st(std::ptr_fun(&custom_constraint), 42)); // std::ptr_fun creates an std::unary_function
c.method(42); c.method(42);
} }
#endif
//] //]
} // namespace constraints_example_3 } // namespace constraints_example_3

View file

@ -1,7 +1,6 @@
// http://turtle.sourceforge.net // http://turtle.sourceforge.net
// //
// Copyright Mathieu Champlon 2009 // Copyright Mathieu Champlon 2009
// Copyright 2020-2025 Alexander Grund
// //
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at // (See accompanying file LICENSE_1_0.txt or copy at
@ -25,24 +24,10 @@
# endif # endif
#endif #endif
#ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS #if defined(__cpp_lib_uncaught_exceptions) || defined(_MSC_VER) && (_MSC_VER >= 1900)
# if(defined(__cpp_lib_uncaught_exceptions) && __cpp_lib_uncaught_exceptions >= 201411) || \ # ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS
(defined(_MSC_VER) && _MSC_VER >= 1900)
# define MOCK_UNCAUGHT_EXCEPTIONS # define MOCK_UNCAUGHT_EXCEPTIONS
# endif # endif
#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 #endif // MOCK_CONFIG_HPP_INCLUDED

View file

@ -1,7 +1,6 @@
// http://turtle.sourceforge.net // http://turtle.sourceforge.net
// //
// Copyright Mathieu Champlon 2008 // Copyright Mathieu Champlon 2008
// Copyright 2020-2025 Alexander Grund
// //
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at // (See accompanying file LICENSE_1_0.txt or copy at
@ -18,7 +17,6 @@
#include <boost/preprocessor/repetition/enum.hpp> #include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp> #include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/variadic/size.hpp> #include <boost/preprocessor/variadic/size.hpp>
#include <functional> #include <functional>

View file

@ -1,7 +1,6 @@
// http://turtle.sourceforge.net // http://turtle.sourceforge.net
// //
// Copyright 2012 Mathieu Champlon // Copyright Mathieu Champlon 2012
// Copyright 2025 Alexander Grund
// //
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at // (See accompanying file LICENSE_1_0.txt or copy at
@ -81,7 +80,7 @@ namespace mock { namespace detail {
typedef safe_error<R, MOCK_ERROR_POLICY<R>> error_type; typedef safe_error<R, MOCK_ERROR_POLICY<R>> error_type;
public: public:
function_impl() : exceptions_(exceptions()), mutex_(std::make_shared<mutex>()) {} function_impl() : context_(0), valid_(true), exceptions_(exceptions()), mutex_(std::make_shared<mutex>()) {}
virtual ~function_impl() virtual ~function_impl()
{ {
if(valid_ && exceptions_ >= exceptions()) if(valid_ && exceptions_ >= exceptions())
@ -315,8 +314,8 @@ namespace mock { namespace detail {
}; };
std::list<expectation_type> expectations_; std::list<expectation_type> expectations_;
context* context_ = nullptr; context* context_;
mutable bool valid_ = true; mutable bool valid_;
const int exceptions_; const int exceptions_;
const std::shared_ptr<mutex> mutex_; const std::shared_ptr<mutex> mutex_;
}; };

View file

@ -1,7 +1,6 @@
// http://turtle.sourceforge.net // http://turtle.sourceforge.net
// //
// Copyright Mathieu Champlon 2008 // Copyright Mathieu Champlon 2008
// Copyright 2022-2025 Alexander Grund
// //
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at // (See accompanying file LICENSE_1_0.txt or copy at
@ -15,7 +14,7 @@
#include "signature.hpp" #include "signature.hpp"
#include "signature_traits.hpp" #include "signature_traits.hpp"
#include "type_name.hpp" #include "type_name.hpp"
#include <boost/preprocessor/repetition/enum.hpp> #include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp> #include <boost/preprocessor/stringize.hpp>
#include <type_traits> #include <type_traits>
@ -50,47 +49,47 @@ namespace mock { namespace detail {
return t##_mock_; \ return t##_mock_; \
} }
#define MOCK_PARAM(S, n) mock::detail::parameter_t<S, n> #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<S> M(MOCK_DECL_PARAMS(n, S)) c
#define MOCK_DECL_PARAM(z, n, S) MOCK_PARAM(S, n) p##n #define MOCK_FORWARD_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n >> (p##n)
#define MOCK_DECL_PARAMS(n, S) BOOST_PP_ENUM(n, MOCK_DECL_PARAM, S) #define MOCK_FORWARD_PARAMS(n, S) BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, std::forward < MOCK_PARAM(S))
#define MOCK_DECL(name, arity, signature, qualifier) \ #define MOCK_METHOD_AUX(M, n, S, t, c) \
mock::detail::result_type_t<signature> name(MOCK_DECL_PARAMS(arity, signature)) qualifier static_assert(n == mock::detail::function_arity_t<S>::value, "Arity mismatch"); \
MOCK_DECL(M, n, S, c) { return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); }
#define MOCK_FORWARD_PARAM(z, n, S) std::forward<MOCK_PARAM(S, n)>(p##n) #define MOCK_METHOD_EXT(M, n, S, t) \
#define MOCK_FORWARD_PARAMS(n, S) BOOST_PP_ENUM(n, MOCK_FORWARD_PARAM, S) MOCK_METHOD_AUX(M, n, S, t, ) \
#define MOCK_METHOD_AUX(name, arity, signature, identifier, qualifier) \ MOCK_METHOD_AUX(M, n, S, t, const) \
MOCK_DECL(name, arity, signature, qualifier) \ MOCK_METHOD_HELPER(S, t)
{ \ #define MOCK_CONST_METHOD_EXT(M, n, S, t) \
return MOCK_ANONYMOUS_HELPER(identifier)(MOCK_FORWARD_PARAMS(arity, signature)); \ 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<S>& t##_mock(mock::detail::context& context, boost::unit_test::const_string instance) \
{ \
static mock::detail::function<S> f; \
return f(context, instance); \
} }
#define MOCK_METHOD_EXT(name, arity, signature, identifier) \ #define MOCK_CONSTRUCTOR_AUX(T, n, A, t) \
MOCK_METHOD_AUX(name, arity, signature, identifier, ) \ T(MOCK_DECL_PARAMS(n, void A)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A)); } \
MOCK_METHOD_AUX(name, arity, signature, identifier, const) \ MOCK_FUNCTION_HELPER(void A, t, static)
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_HELPER(signature, identifier, prefix) \ #define MOCK_FUNCTION_AUX(F, n, S, t, s) \
prefix mock::detail::function<signature>& identifier##_mock(mock::detail::context& context, \ MOCK_FUNCTION_HELPER(S, t, s) \
boost::unit_test::const_string instance) \ static_assert(n == mock::detail::function_arity_t<S>::value, "Arity mismatch"); \
{ \ s MOCK_DECL(F, n, S, ) { return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); }
static mock::detail::function<signature> f; \
return f(context, instance); \
}
#define MOCK_FUNCTION_AUX(name, arity, signature, identifier, prefix) \ #define MOCK_VARIADIC_ELEM_0(e0, ...) e0
MOCK_FUNCTION_HELPER(signature, identifier, prefix) \ #define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1
static_assert(arity == mock::detail::function_arity_t<signature>::value, "Arity mismatch"); \ #define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
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) #define MOCK_REPLACED_MACRO_ERROR(oldName, newName) static_assert(false, #oldName " has been replaced by " #newName)
// Replaced macros // Replaced macros

View file

@ -1,7 +1,6 @@
// http://turtle.sourceforge.net // http://turtle.sourceforge.net
// //
// Copyright Mathieu Champlon 2008 // Copyright Mathieu Champlon 2008
// Copyright 2022-2025 Alexander Grund
// //
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at // (See accompanying file LICENSE_1_0.txt or copy at
@ -16,7 +15,6 @@
#include "object.hpp" #include "object.hpp"
#include "reset.hpp" #include "reset.hpp"
#include "verify.hpp" #include "verify.hpp"
#include <boost/preprocessor/variadic/elem.hpp>
/// MOCK_CLASS( name ) /// MOCK_CLASS( name )
/// Define a class /// Define a class
@ -53,12 +51,7 @@
/// MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier ) /// 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. /// 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) \ #define MOCK_CONSTRUCTOR(T, arity, parameters, identifier) MOCK_CONSTRUCTOR_AUX(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 ) /// MOCK_DESTRUCTOR( [calling convention] ~name, identifier )
#define MOCK_DESTRUCTOR(T, identifier) \ #define MOCK_DESTRUCTOR(T, identifier) \
@ -76,41 +69,39 @@
/// generates both const and non-const methods /// generates both const and non-const methods
/// The 'signature' can be omitted if it can be uniquely identified from the base class /// The 'signature' can be omitted if it can be uniquely identified from the base class
/// if 'identifier' is omitted it will default to 'name' /// if 'identifier' is omitted it will default to 'name'
#define MOCK_METHOD(M, ...) \ #define MOCK_METHOD(M, ...) \
MOCK_METHOD_EXT(M, \ MOCK_METHOD_EXT(M, \
BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), \ MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, MOCK_SIGNATURE(M), ), \ MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__, M, M, )) MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
/// MOCK_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) /// MOCK_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] )
/// generates only the const version of the method /// generates only the const version of the method
/// The 'signature' can be omitted if it can be uniquely identified from the base class /// The 'signature' can be omitted if it can be uniquely identified from the base class
/// if 'identifier' is omitted it will default to 'name' /// if 'identifier' is omitted it will default to 'name'
#define MOCK_CONST_METHOD(M, ...) \ #define MOCK_CONST_METHOD(M, ...) \
MOCK_CONST_METHOD_EXT(M, \ MOCK_CONST_METHOD_EXT(M, \
BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), \ MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, MOCK_SIGNATURE(M), ), \ MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__, M, M, )) MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
/// MOCK_NON_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) /// MOCK_NON_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] )
/// generates only the non-const version of the method /// generates only the non-const version of the method
/// The 'signature' can be omitted if it can be uniquely identified from the base class /// The 'signature' can be omitted if it can be uniquely identified from the base class
/// if 'identifier' is omitted it will default to 'name' /// if 'identifier' is omitted it will default to 'name'
#define MOCK_NON_CONST_METHOD(M, ...) \ #define MOCK_NON_CONST_METHOD(M, ...) \
MOCK_NON_CONST_METHOD_EXT(M, \ MOCK_NON_CONST_METHOD_EXT(M, \
BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), \ MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, MOCK_SIGNATURE(M), ), \ MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__, M, M, )) MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
/// MOCK_FUNCTION( [calling convention] name, arity, signature[, identifier] ) /// MOCK_FUNCTION( [calling convention] name, arity, signature[, identifier] )
/// if 'identifier' is omitted it will default to 'name' /// if 'identifier' is omitted it will default to 'name'
#define MOCK_FUNCTION(F, arity, ...) \ #define MOCK_FUNCTION(F, arity, ...) \
MOCK_FUNCTION_AUX( \ MOCK_FUNCTION_AUX(F, arity, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), inline)
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] ) /// MOCK_STATIC_METHOD( [calling convention] name, arity, signature[, identifier] )
/// if 'identifier' is omitted it will default to 'name' /// if 'identifier' is omitted it will default to 'name'
#define MOCK_STATIC_METHOD(F, arity, ...) \ #define MOCK_STATIC_METHOD(F, arity, ...) \
MOCK_FUNCTION_AUX( \ MOCK_FUNCTION_AUX(F, arity, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static)
F, arity, BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__, ), BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__, F, ), static)
/// MOCK_EXPECT( identifier ) /// MOCK_EXPECT( identifier )
/// Begin setting up expectation for the identifier /// Begin setting up expectation for the identifier

View file

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/sh
# Copyright (C) 2015 Mathieu Champlon # Copyright (C) 2015 Mathieu Champlon
# Copyright (C) 2025 Alexander Grund
# #
# Distributed under the Boost Software License, Version 1.0. # 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) # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
@ -19,6 +18,3 @@ scripts/build_doc.sh "$@"
cd "$BOOST_ROOT" cd "$BOOST_ROOT"
./b2 "$PROJECT_DIR/doc//mock_examples" -q "$@" ./b2 "$PROJECT_DIR/doc//mock_examples" -q "$@"
cd "$BOOST_ROOT"
./b2 "$PROJECT_DIR/test//inspect" -q "$@"

View file

@ -1,5 +1,4 @@
# Copyright 2012 Mathieu Champlon # Copyright Mathieu Champlon 2012
# Copyright 2025 Alexander Grund
# #
# Distributed under the Boost Software License version 1.0. (See # Distributed under the Boost Software License version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at # accompanying file LICENSE_1_0.txt or copy at
@ -16,27 +15,22 @@ project
path-constant parent : .. ; path-constant parent : .. ;
run /boost/tools/inspect//inspect/<variant>release : $(parent) -text -brief : : <test-info>always_show_run_output : inspect ; alias mock_inspect :
explicit inspect ; [ run /boost/tools/inspect//inspect/<variant>release
: $(parent) -text -brief : : : inspect
]
;
rule run-test ( name : options * ) rule run-test ( name )
{ {
run $(name) defined_1.cpp defined_2.cpp undefined.cpp /boost//unit_test_framework : : : $(options) : $(name)_ ; run $(name) defined_1.cpp defined_2.cpp undefined.cpp /boost//unit_test_framework : : : : $(name)_ ;
run $(name) undefined.cpp /boost//unit_test_framework : : : $(options) <define>MOCK_USE_CONVERSIONS : $(name)_use_conversions ; run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_USE_CONVERSIONS : $(name)_use_conversions ;
run $(name) undefined.cpp /boost//unit_test_framework /boost//thread : : : $(options) <define>MOCK_THREAD_SAFE <define>BOOST_THREAD_USES_MOVE <threading>multi : $(name)_thread_safe ; run $(name) undefined.cpp /boost//unit_test_framework /boost//thread : : : <define>MOCK_THREAD_SAFE <define>BOOST_THREAD_USES_MOVE <threading>multi : $(name)_thread_safe ;
} }
rule run-tests rule run-tests
{ {
for name in [ glob test_*.cpp ] { run-test $(name) ; } for name in [ glob test_*.cpp detail/test_*.cpp ] { run-test $(name) ; }
# Avoid object file getting to big on MinGW
run-test detail/test_function.cpp :
<toolset>gcc,<target-os>windows:<inlining>on
<toolset>gcc,<target-os>windows:<optimization>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 ] ; alias mock_tests : [ run-tests ] ;

View file

@ -67,8 +67,6 @@ BOOST_AUTO_TEST_CASE(function_pointer_is_functor)
is_not_functor(&f2); 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) BOOST_AUTO_TEST_CASE(std_ptr_fun_is_functor)
{ {
is_functor(std::ptr_fun(&f1)); is_functor(std::ptr_fun(&f1));
@ -79,7 +77,6 @@ BOOST_AUTO_TEST_CASE(std_bind_first_is_functor)
{ {
is_functor(std::bind1st(std::ptr_fun(&f2), "")); is_functor(std::bind1st(std::ptr_fun(&f2), ""));
} }
#endif
BOOST_AUTO_TEST_CASE(bind_is_functor) BOOST_AUTO_TEST_CASE(bind_is_functor)
{ {