Skip to content

Commit be0934f

Browse files
mstazkris-jusiak
authored andcommitted
Remove sut member variable from named test cases.
Problem: Build issues when using `-Wshadow` and a variable `sut` is used in a named test case. Solution: Add a template specialization for `GTest` with name as type. Omit the sut variable here.
1 parent d02ec96 commit be0934f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/GUnit/GTest.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ class GTest : public std::conditional_t<std::is_same<TParamType, void>::value,
196196
SUT sut; // has to be after mocks
197197
};
198198

199+
template <char... Chars, class TParamType>
200+
class GTest<string<Chars...>, TParamType>
201+
: public std::conditional_t<std::is_same<TParamType, void>::value, Test,
202+
TestWithParam<TParamType>> {
203+
public:
204+
template <class TMock>
205+
decltype(auto) mock() {
206+
return mocks.mock<TMock>();
207+
}
208+
209+
mocks_t mocks;
210+
};
211+
199212
template <class T, class TParamType, class TAny>
200213
class GTest<T, TParamType, std::false_type, TAny> : public Test {
201214
public:

0 commit comments

Comments
 (0)