Skip to content

Commit 6f6c518

Browse files
committed
✨ enable support for logical expressions in EXPECT and ASSERT
Problem: - logical expressions fail in EXPECT() and ASSERT() because of operator precedence Solution: - wrap __VA_ARGS__ use in macros with an extra set of parens
1 parent 0d52387 commit 6f6c518

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

include/GUnit/GAssert.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void prevent_commas(T&&) {}
213213
(::testing::detail::op<std::true_type>{ \
214214
::testing::detail::info{__FILE__, __LINE__, #__VA_ARGS__, \
215215
::testing::TestPartResult::kNonFatalFailure}} \
216-
<< __VA_ARGS__)
216+
<< (__VA_ARGS__))
217217

218218
#define EXPECT(...) \
219219
GUNIT_PREVENT_COMMAS(__VA_ARGS__); \
@@ -223,14 +223,14 @@ void prevent_commas(T&&) {}
223223
if (::testing::detail::op<std::false_type>{ \
224224
::testing::detail::info{__FILE__, __LINE__, #__VA_ARGS__, \
225225
::testing::TestPartResult::kFatalFailure}} \
226-
<< __VA_ARGS__) \
226+
<< (__VA_ARGS__)) \
227227
void(::testing::detail::drop{}); \
228228
else \
229229
return ::testing::detail::ret_void{} == \
230230
(::testing::detail::op<std::true_type>{::testing::detail::info{ \
231231
__FILE__, __LINE__, #__VA_ARGS__, \
232232
::testing::TestPartResult::kFatalFailure}} \
233-
<< __VA_ARGS__)
233+
<< (__VA_ARGS__))
234234

235235
#define ASSERT(...) \
236236
GUNIT_PREVENT_COMMAS(__VA_ARGS__); \

test/GAssert.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ TEST(GAssert, ShouldSupportExpect) {
3737

3838
EXPECT(not convertible{});
3939
EXPECT(false == convertible{});
40+
41+
EXPECT(false or true);
4042
}
4143

4244
TEST(GAssert, ShouldSupportASSERT) {
@@ -69,4 +71,6 @@ TEST(GAssert, ShouldSupportASSERT) {
6971

7072
ASSERT(convertible{});
7173
ASSERT(false == not convertible{});
74+
75+
ASSERT(false or true);
7276
}

0 commit comments

Comments
 (0)