Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 preparation #51

Merged
merged 87 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
5aa1765
use reduced matrix, if not on main branch
DNKpp Oct 6, 2024
232b2c5
disable the combination std + unicode
DNKpp Oct 6, 2024
3771760
feat: switch to uni-algo case-folding backends
DNKpp Oct 6, 2024
6a478dc
docs: mark the "this is an experimental feature..." with \attention
DNKpp Oct 6, 2024
3556394
fix: make clang-build working
DNKpp Oct 6, 2024
5c2d214
feat: make std::optional and std::nullopt_t printable
DNKpp Oct 6, 2024
f3da973
feat: make tuple-like printable
DNKpp Oct 6, 2024
a8817a0
fix: in-place matchers use matches::str::eq for string arguments
DNKpp Oct 6, 2024
89ed985
refactor: make the internals of make_arg_policy less DRY
DNKpp Oct 6, 2024
e753ef7
feat: add LifetimeWatcher sketch-up
DNKpp Oct 6, 2024
824e25a
feat: limit expect_destruction calls to 1
DNKpp Oct 6, 2024
b17b668
feat: make LifetimeWatcher movable
DNKpp Oct 6, 2024
cfc581d
refactor: restructure LifetimeWatcher destructor
DNKpp Oct 7, 2024
4842628
fix: add missing functional include
DNKpp Oct 7, 2024
58614f8
fix: do not use std::invoke for mocks
DNKpp Oct 7, 2024
2d7a507
feat: add LifetimeWatcher test with finally::throws policy
DNKpp Oct 7, 2024
719abcd
feat: slightly simplify previous test
DNKpp Oct 7, 2024
82d012f
fix: workaround compiler inconsistencies
DNKpp Oct 7, 2024
d84fa31
slightly adjust LifetimeWatcher with finally::throws test
DNKpp Oct 7, 2024
0bfd71c
feat: make LifetimeWatcher copyable
DNKpp Oct 7, 2024
7a94f2d
feat: add Watched sketchup
DNKpp Oct 7, 2024
4352977
fix: explicitly ignore returned value from std::exchange
DNKpp Oct 7, 2024
d2674d6
feat: make Watched work with interfaces
DNKpp Oct 7, 2024
d560022
feat: add violation tests for Watched
DNKpp Oct 7, 2024
ee4ff07
fix: add missing nodiscard on copy-ctor
DNKpp Oct 7, 2024
4ce4ef9
fix: prevent double violation reports from LifetimeWatcher copy-assig…
DNKpp Oct 7, 2024
a933794
feat: add LifetimeWatcher examples
DNKpp Oct 7, 2024
7d3a6bb
feat: add LifetimeWatcher documentation
DNKpp Oct 7, 2024
4efbabc
feat: extend LifetimeWatcher.hpp documentation
DNKpp Oct 7, 2024
7da4b12
fix: Watched applies the same noexcept spec to its dtor as Base
DNKpp Oct 7, 2024
d17c920
ci: enable full matrix for PRs from development
DNKpp Oct 7, 2024
43ec68a
fix: attempt to fix the previous
DNKpp Oct 7, 2024
c2b2d5a
fix: try with another syntax
DNKpp Oct 7, 2024
d74ae6a
fix: merge condition into one line
DNKpp Oct 7, 2024
9815387
fix: actually use correct variable (head_ref)
DNKpp Oct 7, 2024
d00eea1
fix: explicitly install plain llvm on macos runner
DNKpp Oct 7, 2024
886f04f
fix: mirror latest change to second job
DNKpp Oct 7, 2024
c479810
fix: brew install command
DNKpp Oct 7, 2024
da6221b
docs: collaps some readme content
DNKpp Oct 7, 2024
5011f0f
env: enable heavy warning flags for test targets
DNKpp Oct 8, 2024
8994fc9
fix: do not shadow mimicpp::SequenceT inside tests
DNKpp Oct 8, 2024
ac16337
fix: move assert statement to top of unreachable()
DNKpp Oct 8, 2024
3232f3e
fix: suppress unreachable-code warnings in Reporter.cpp
DNKpp Oct 8, 2024
7f66eb2
fix: reolve several warning C4459: declaration of '_' hides global de…
DNKpp Oct 8, 2024
814ea68
fix: resolve several unused variable warning false-positive warnings …
DNKpp Oct 8, 2024
446a18a
fix: suppress several self-move warnings
DNKpp Oct 8, 2024
c2981fa
fix: invalid param/tparam documentation
DNKpp Oct 8, 2024
eabf33b
fix: use different name for value captures
DNKpp Oct 8, 2024
4b416c7
fix: treat warning flags for clang-cl special
DNKpp Oct 8, 2024
75fc7df
docs: update README.md
DNKpp Oct 8, 2024
64a97a2
fix: disable -Wself-move suppression on gcc-12
DNKpp Oct 8, 2024
be65272
fix: correct gcc-12 detection
DNKpp Oct 8, 2024
93edeb5
fix: remove ldflags_workaround from AppleClang-18 config
DNKpp Oct 8, 2024
a47c002
fix: re-enable ldflags_workaround for AppleClang-18
DNKpp Oct 8, 2024
2d53bf5
fix: resolve several release-only warnings
DNKpp Oct 8, 2024
bc915d8
fix: resolve nonsense maybe-uninitialized warning from gcc
DNKpp Oct 8, 2024
8033aef
chore: split warnings from setup function
5cript Oct 8, 2024
c44be27
feat: add mimicpp::internal::warnings alias target
DNKpp Oct 9, 2024
c807091
fix: include EnableWarnings.cmake only when necessary
DNKpp Oct 9, 2024
ed75c53
refactor: rename mimic++-configuration-options.cmake to EnableConfigO…
DNKpp Oct 9, 2024
0afa8f1
refactor: make config options an actual interface target
DNKpp Oct 9, 2024
50bb1c4
fix: add license header to cmake files
DNKpp Oct 9, 2024
10a5fc7
cleanup: remove unnecessary add_package sanitizers-cmake
DNKpp Oct 9, 2024
6c48036
ci: adjust ldflags_workaround for AppleClang-18
DNKpp Oct 10, 2024
d80fcb0
ci: enable adapter-tests for AppleClang-16
DNKpp Oct 10, 2024
30a78c7
docs: update README.md
DNKpp Oct 10, 2024
a2514be
chore: rename LifetimeWatcher files to ObjectWatcher
DNKpp Oct 10, 2024
574445b
refactor: apply "[object-watcher][object-watcher::lifetime]" tags to …
DNKpp Oct 10, 2024
1777c49
feat: RelocationWatcher
DNKpp Oct 10, 2024
6491274
feat: make RelocationWatcher copyable
DNKpp Oct 10, 2024
aee29c6
fix: please gcc
DNKpp Oct 10, 2024
a6d7a69
fix: correct SUPPRESS_SELF_ASSIGN definition on clang
DNKpp Oct 10, 2024
91c3a42
feat: make Watched adapting nothrow spec for move-ctor and -assignment
DNKpp Oct 10, 2024
65d9865
refactor: simplify Watcher internals
DNKpp Oct 10, 2024
8836981
docs: add RelocationWatcher documentation
DNKpp Oct 10, 2024
f057f00
feat: add RelocationWatcher example
DNKpp Oct 11, 2024
84c8449
docs: add type-trait documentation
DNKpp Oct 11, 2024
4129fdc
chore: bump mimic++ version to 3
DNKpp Oct 11, 2024
cbe5b29
fix: please gcc
DNKpp Oct 11, 2024
4c18840
chore: add missing license header to SuppressionMacros.hpp
DNKpp Oct 11, 2024
012fbce
feat: slightly adjust watcher example
DNKpp Oct 11, 2024
51ca5c4
chore: include get_cpm only if necessary
DNKpp Oct 11, 2024
8431fd6
fix: stabilize sanitizer cmake inclusion
DNKpp Oct 11, 2024
0f74d84
fix: add missing get_cpm include
DNKpp Oct 11, 2024
2cd9a2a
fix: correct mimic++.hpp
DNKpp Oct 11, 2024
7e6744d
docs: update godbolt link
DNKpp Oct 11, 2024
290900c
docs: extend README.md example
DNKpp Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 56 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ jobs:
# Defines the compiler configurations for the other jobs.
#
#####
define-config:
define-matrix:
runs-on: ubuntu-latest
outputs:
config: ${{ steps.output-config.outputs.config }}
env:
config: |
[
Expand Down Expand Up @@ -138,7 +136,7 @@ jobs:
"os": "macos-latest",
"compiler_name": "AppleClang",
"compiler_version": 18,
"ldflags_workaround": "-L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib -lunwind",
"ldflags_workaround": "-L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib/unwind -lunwind",
"asan": true
},
{
Expand All @@ -159,15 +157,45 @@ jobs:
}
]

outputs:
config: ${{ steps.output-config.outputs.config }}
build_modes: ${{ steps.output-options.outputs.build_modes }}
cxx_versions: ${{ steps.output-options.outputs.cxx_versions }}

steps:
- name: Output configs
id: output-config
shell: bash
run: |
# seems to convert that to a single-line json and thus please the output step
# wrap in single '!
OUTPUT='${{ env.config }}'
echo "config=$(echo $OUTPUT)" >> "$GITHUB_OUTPUT"
# seems to convert that to a single-line json and thus please the output step
# wrap in single '!
OUTPUT='${{ env.config }}'
echo "config=$(echo $OUTPUT)" >> "$GITHUB_OUTPUT"

# enables debug-mode and c++20 for all cases
- name: Enable base matrix
shell: bash
run: |
echo "BUILD_MODES=\"Debug\"" >> $GITHUB_ENV
echo "CXX_VERSIONS=20" >> $GITHUB_ENV

# if its a PR from development or the main branch in general, add release-mode and c++23
- name: Enable extended matrix
if: ${{
(github.event_name == 'pull_request' && github.head_ref == 'development')
|| github.ref_name == 'main'
}}
shell: bash
run: |
echo "BUILD_MODES=$(echo $BUILD_MODES, \"Release\")" >> $GITHUB_ENV
echo "CXX_VERSIONS=$(echo $CXX_VERSIONS, 23)" >> $GITHUB_ENV

- name: Output build-modes and c++-versions
id: output-options
shell: bash
run: |
echo "build_modes=$(echo [ $BUILD_MODES ])" >> "$GITHUB_OUTPUT"
echo "cxx_versions=$(echo [ $CXX_VERSIONS ])" >> "$GITHUB_OUTPUT"

############
#
Expand All @@ -182,7 +210,7 @@ jobs:
#
#####
run-unit-tests:
needs: define-config
needs: define-matrix
name: |
[UT]
${{ matrix.config.prefix }}
Expand All @@ -195,11 +223,11 @@ jobs:
strategy:
fail-fast: false
matrix:
build_mode: [Debug, Release]
cxx_standard: [20, 23]
format_backend: [std, fmt]
str_matcher: [char, unicode]
config: ${{ fromJSON(needs.define-config.outputs.config) }}
build_mode: ${{ fromJSON(needs.define-matrix.outputs.build_modes) }}
cxx_standard: ${{ fromJSON(needs.define-matrix.outputs.cxx_versions) }}
config: ${{ fromJSON(needs.define-matrix.outputs.config) }}

exclude:
# all listed compilers do not support std's format header
Expand All @@ -216,18 +244,27 @@ jobs:
compiler_name: "AppleClang"
compiler_version: 16

# The format_backend and str_matcher options are rather orthogonal.
# To see, whether support both str_matcher variants, let's use the fmt backend,
# as this is supported by all compilers.
- format_backend: "std"
str_matcher: "unicode"

steps:
- uses: actions/checkout@v4

- name: Setup macOS
if: startsWith(matrix.config.os, 'macOS')
shell: bash
run: |
env brew install ninja llvm
LLVM_NAME=llvm@${{ matrix.config.compiler_version }}
env brew install ninja $LLVM_NAME
env brew install $LLVM_NAME
LLVM_PATH="$(brew --prefix $LLVM_NAME)"
echo "CC=$(echo $LLVM_PATH/bin/clang)" >> $GITHUB_ENV
echo "CXX=$(echo $LLVM_PATH/bin/clang++)" >> $GITHUB_ENV

# solves this issue: https://github.com/Homebrew/homebrew-core/issues/178435
echo "LDFLAGS=$(echo $LDFLAGS ${{ matrix.config.ldflags_workaround }})" >> $GITHUB_ENV

echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DCMAKE_BUILD_TYPE=${{ matrix.build_mode }})" >> $GITHUB_ENV
Expand Down Expand Up @@ -320,7 +357,7 @@ jobs:
#
#####
run-adapter-tests:
needs: define-config
needs: define-matrix
name: |
[AT]
${{ matrix.config.prefix }}
Expand All @@ -333,17 +370,9 @@ jobs:
strategy:
fail-fast: false
matrix:
build_mode: [Debug, Release]
cxx_standard: [20, 23]
config: ${{ fromJSON(needs.define-config.outputs.config) }}

exclude:
# This compiler does work, but fails compiling something from boost::filesystem, which is indirectly required
# by the BoostAdapter-Test.
# Maybe, we can find a workaround for this in the future.
- config:
compiler_name: "AppleClang"
compiler_version: 16
build_mode: ${{ fromJSON(needs.define-matrix.outputs.build_modes) }}
cxx_standard: ${{ fromJSON(needs.define-matrix.outputs.cxx_versions) }}
config: ${{ fromJSON(needs.define-matrix.outputs.config) }}

steps:
- uses: actions/checkout@v4
Expand All @@ -352,8 +381,9 @@ jobs:
if: startsWith(matrix.config.os, 'macOS')
shell: bash
run: |
env brew install ninja llvm
LLVM_NAME=llvm@${{ matrix.config.compiler_version }}
env brew install ninja $LLVM_NAME
env brew install $LLVM_NAME
LLVM_PATH="$(brew --prefix $LLVM_NAME)"
echo "CC=$(echo $LLVM_PATH/bin/clang)" >> $GITHUB_ENV
echo "CXX=$(echo $LLVM_PATH/bin/clang++)" >> $GITHUB_ENV
Expand Down
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Copyright Dominic (DNKpp) Koepke 2024 - 2024.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# https://www.boost.org/LICENSE_1_0.txt)

cmake_minimum_required(VERSION 3.15)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(get_cpm)

project(
mimicpp
LANGUAGES CXX
VERSION 2
VERSION 3
DESCRIPTION "A modern and (mostly) macro free mocking-framework"
HOMEPAGE_URL "https://github.com/DNKpp/mimicpp"
)
Expand Down Expand Up @@ -40,7 +44,12 @@ target_compile_features(
cxx_std_${CMAKE_CXX_STANDARD}
)

include(mimic++-configuration-options)
include(EnableConfigOptions)
target_link_libraries(
mimicpp
INTERFACE
mimicpp::internal::config-options
)

if (CMAKE_SOURCE_DIR STREQUAL mimicpp_SOURCE_DIR)
set(IS_TOP_LEVEL_PROJECT ON)
Expand Down
62 changes: 55 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ As I'm mainly working on template or functional-style code, I wanted something s
So, ``mimicpp::Mock`` objects can directly be used as functional objects, but they can also be used as member objects and thus serve as actual member functions.

If you are curious, have a look at the [documentation](https://dnkpp.github.io/mimicpp/), investigate the examples folder or play around online at
[godbolt.org](https://godbolt.org/z/nfhT9xa4E).
[godbolt.org](https://godbolt.org/z/o3Thdcr7T).

### Core Design

Expand All @@ -62,7 +62,8 @@ So, Mocks and Expectations are going together hand in hand.

### Examples

#### Mocks as function objects
<details>
<summary>Mocks as function objects</summary>

As already said, ``mimicpp::Mock``s are already function objects.

Expand Down Expand Up @@ -117,7 +118,10 @@ TEST_CASE("Mocks can be overloaded.")
}
```

#### Mocks as member functions
</details>

<details>
<summary>Mocks as member functions</summary>

``mimicpp::Mock``s can also serve as member functions. Sure, there are some limitations, but for the most cases it works well.

Expand Down Expand Up @@ -148,7 +152,10 @@ TEST_CASE("Mocks can be used as member functions.")
}
```

#### Mocking interfaces
</details>

<details>
<summary>Mocking interfaces</summary>

``mimic++`` also provides helpers for interface mocking.

Expand Down Expand Up @@ -235,6 +242,42 @@ TEST_CASE("Interface overload-sets are directly supported.")
}
```

</details>

<details>
<summary>Watching object-instances</summary>

``mimicpp::Watched`` helper can report destruction and relocations of object-instances.

```cpp
#include <mimic++/mimic++.hpp>

namespace expect = mimicpp::expect;
namespace then = mimicpp::then;

TEST_CASE("LifetimeWatcher and RelocationWatcher can trace object instances.")
{
mimicpp::Watched<
mimicpp::Mock<void()>,
mimicpp::LifetimeWatcher,
mimicpp::RelocationWatcher> watched{};

SCOPED_EXP watched.expect_destruct();
int relocationCounter{};
SCOPED_EXP watched.expect_relocate()
and then::invoke([&] { ++relocationCounter; })
and expect::at_least(1);

std::optional wrapped{std::move(watched)}; // satisfies one relocate-expectation
std::optional other{std::move(wrapped)}; // satisfies a second relocate-expectation
wrapped.reset(); // won't require a destruct-expectation, as moved-from objects are considered dead
other.reset(); // fulfills the destruct-expectation
REQUIRE(2 == relocationCounter); // let's see, how often the instance has been relocated
}
```

</details>

### Other Choices

#### Always Stay Within The Language Definition
Expand Down Expand Up @@ -365,6 +408,10 @@ Official adapters exist for the following frameworks:
``mimic++`` utilizes a strict testing policy, thus each official feature is well tested. The effect of those test-cases are always tracked by the extensive ci,
which checks the compilation success, test cases outcomes and coverage on dozens of different os, compiler and build configurations.

For the test builds the flags ``-Wall -Wextra -Wpedantic -Werror`` (on MSVC ``/W4 /WX``) are set.
This is done to make sure, that ``mimic++`` won't flood your build output with endless warnings (or even worse: break your builds),
if you enable these flags in your own projects.

The coverage is generated via ``gcov`` and evaluated by
[codacy](https://app.codacy.com/gh/DNKpp/mimicpp),
[codecov](https://codecov.io/gh/DNKpp/mimicpp) and
Expand All @@ -376,7 +423,8 @@ The goal is to be close to 100% as possible.
On the other hand-side, there is a whole range of code which doesn't even get investigated by these tools: templates (and macros).
``mimic++`` has **a lot** of templating code at the very heart, which is at least of equal effort to get right (and tested). So, treat the coverage percentage with a grain of salt.

### CI Tests
<details>
<summary>CI Tests</summary>

The listed configurations are explicitly tested, but other do probably work, too.
As new compilers become available, they will be added to the workflow, but older compilers will probably never be supported.
Expand Down Expand Up @@ -410,11 +458,11 @@ As new compilers become available, they will be added to the workflow, but older

| Compiler | libstdc++ | libc++ | c++-20 | c++-23 | std-format | fmt |
|-------------------|:---------:|:------:|:------:|:------:|:----------:|:---:|
| AppleClang-16.0.6^1^ | ? | x | x | x | x | x |
| AppleClang-16.0.6 | ? | x | x | x | x | x |
| AppleClang-17.0.6 | ? | x | x | x | x | x |
| AppleClang-18.1.6 | ? | x | x | x | x | x |

^1^ There is an issue with AppleClang-16 and ``boost::filesystem`` on the current ``macos-latest``, but this is just for the boost-test-adapter. Everything else works fine.
</details>

---

Expand Down
Loading
Loading