Skip to content

Commit

Permalink
Merge pull request #341 from rollbear/trailing_return_mock
Browse files Browse the repository at this point in the history
trailing_return_mock
  • Loading branch information
rollbear authored Oct 7, 2024
2 parents a56cee5 + fb4f732 commit e67dd74
Show file tree
Hide file tree
Showing 9 changed files with 799 additions and 210 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: false,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}
- {
name: "Linux Clang 10 C++11 / libc++",
Expand Down Expand Up @@ -940,6 +941,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: true,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}

# Clang-11
Expand Down Expand Up @@ -978,6 +980,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: false,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}
- {
name: "Linux Clang 11 C++11 / libc++",
Expand Down Expand Up @@ -1014,6 +1017,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: true,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}

# Clang-12
Expand Down Expand Up @@ -1052,6 +1056,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: false,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}
- {
name: "Linux Clang 12 C++11 / libc++",
Expand Down Expand Up @@ -1088,6 +1093,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: true,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}

# Clang-13
Expand Down Expand Up @@ -1126,6 +1132,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: false,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}
- {
name: "Linux Clang 13 C++11 / libc++",
Expand Down Expand Up @@ -1162,6 +1169,7 @@ jobs:
cxx_standard: 20,
cxx_asan: true,
libcxx: true,
cxx_flags: "-Wno-gnu-zero-variadic-macro-arguments"
}

# Clang-14
Expand Down Expand Up @@ -1628,24 +1636,52 @@ jobs:
cc: "cl", cxx: "cl",
cxx_standard: 11,
}
- {
name: "Windows MSVC 2022 C++11 preprocessor",
os: windows-2022,
cc: "cl", cxx: "cl",
cxx_standard: 11,
cxx_flags: "/Zc:preprocessor"
}
- {
name: "Windows MSVC 2022 C++14",
os: windows-2022,
cc: "cl", cxx: "cl",
cxx_standard: 14,
}
- {
name: "Windows MSVC 2022 C++14 preprocessor",
os: windows-2022,
cc: "cl", cxx: "cl",
cxx_standard: 14,
cxx_flags: "/Zc:preprocessor"
}
- {
name: "Windows MSVC 2022 C++17",
os: windows-2022,
cc: "cl", cxx: "cl",
cxx_standard: 17,
}
- {
name: "Windows MSVC 2022 C++17 preprocessor",
os: windows-2022,
cc: "cl", cxx: "cl",
cxx_standard: 17,
cxx_flags: "/Zc:preprocessor"
}
- {
name: "Windows MSVC 2022 C++20",
os: windows-2022,
cc: "cl", cxx: "cl",
cxx_standard: 20,
}
- {
name: "Windows MSVC 2022 C++20 preprocessor",
os: windows-2022,
cc: "cl", cxx: "cl",
cxx_standard: 20,
cxx_flags: "/Zc:preprocessor"
}

# MSVC 2019
- {
Expand All @@ -1654,24 +1690,52 @@ jobs:
cc: "cl", cxx: "cl",
cxx_standard: 11,
}
- {
name: "Windows MSVC 2019 C++11 preprocessor",
os: windows-2019,
cc: "cl", cxx: "cl",
cxx_standard: 11,
cxx_flags: "/Zc:preprocessor"
}
- {
name: "Windows MSVC 2019 C++14",
os: windows-2019,
cc: "cl", cxx: "cl",
cxx_standard: 14,
}
- {
name: "Windows MSVC 2019 C++14 preprocessor",
os: windows-2019,
cc: "cl", cxx: "cl",
cxx_standard: 14,
cxx_flags: "/Zc:preprocessor"
}
- {
name: "Windows MSVC 2019 C++17",
os: windows-2019,
cc: "cl", cxx: "cl",
cxx_standard: 17,
}
- {
name: "Windows MSVC 2019 C++17 preprocessor",
os: windows-2019,
cc: "cl", cxx: "cl",
cxx_standard: 17,
cxx_flags: "/Zc:preprocessor"
}
- {
name: "Windows MSVC 2019 C++20",
os: windows-2019,
cc: "cl", cxx: "cl",
cxx_standard: 20,
}
- {
name: "Windows MSVC 2019 C++20 preprocessor",
os: windows-2019,
cc: "cl", cxx: "cl",
cxx_standard: 20,
cxx_flags: "/Zc:preprocessor"
}
steps:
- uses: actions/checkout@v4

Expand All @@ -1698,6 +1762,10 @@ jobs:
shell: bash
run: |
STD=${{ matrix.config.cxx_standard }}
if [ -n "${{ matrix.config.cxx_flags }}" ]
then
cxx_flags="${{matrix.config.cxx_flags }}"
fi
if [ "x${{ matrix.config.libcxx }}" == "xtrue" ]
then
cxx_flags="${cxx_flags} -stdlib=libc++ -Wno-unused-command-line-argument"
Expand Down
22 changes: 22 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
* Added mocking macros that infers function arity from a trailing return
type syntax signature.

MAKE_MOCK(name, signature {, specifiers})
MAKE_CONST_MOCK(name, signature {, specifiers})
MAKE_STDMETHOD_MOCK(name, signature {, specifiers})

Note that these only work with trailing return type syntax. Examples
of specifiers are 'override', 'final' and 'noexcept'

The preprocessor is limited and can only handle nullary functions,
i.e. functions that do not accept any arguments, in some cases.

MSVC handles nullary functions when compiling with /Zc:preprocessor
with MSVC 19.40 (VS 17.10) or later.

Gcc and Clang always handles nullary functions when compiling with
C++20 or later, and when enabling a gcc extension by compiling with
-std=gnu++11/14/17 and defining the macro TROMPELOEIL_HAS_GCC_PP before
#include:ing the trompeloeil headers.


* Added .RT_TIMES() to exceptations, which works like .TIMES()
but where the limits are only known at runtime. Thank you
Dominic Koepke for submitting the implementation.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void interface_func(Interface*); // function to test
class Mock : public Interface
{
public:
MAKE_MOCK2(foo, bool(int, std::string&),override);
MAKE_MOCK1(bar, bool(int),override);
MAKE_MOCK1(bar, bool(std::string),override);
MAKE_MOCK(foo, auto (int, std::string&) -> bool, override);
MAKE_MOCK(bar, auto (int) -> bool, override);
MAKE_MOCK(bar, auto (std::string) -> bool, override);
MAKE_MOCK0(baz, void()); // not from Interface
};

Expand Down
Loading

0 comments on commit e67dd74

Please sign in to comment.