13 #ifndef __STOUT_GTEST_HPP__
14 #define __STOUT_GTEST_HPP__
18 #include <gtest/gtest.h>
25 #include <sys/types.h>
39 return ::testing::AssertionFailure()
40 << expr <<
" is NONE";
43 return ::testing::AssertionSuccess();
53 return ::testing::AssertionFailure()
54 << expr <<
": " << actual.
error();
57 return ::testing::AssertionSuccess();
67 return ::testing::AssertionFailure()
68 << expr <<
" is NONE";
70 return ::testing::AssertionFailure()
71 << expr <<
": " << actual.
error();
74 return ::testing::AssertionSuccess();
78 template <
typename T1,
typename T2>
80 const char* expectedExpr,
81 const char* actualExpr,
85 const ::testing::AssertionResult result =
AssertSome(actualExpr, actual);
88 if (expected == actual.get()) {
89 return ::testing::AssertionSuccess();
91 return ::testing::AssertionFailure()
92 <<
"Value of: (" << actualExpr <<
").get()\n"
93 <<
" Actual: " << ::testing::PrintToString(actual.get()) <<
"\n"
94 <<
"Expected: " << expectedExpr <<
"\n"
95 <<
"Which is: " << ::testing::PrintToString(expected);
103 template <
typename T1,
typename T2>
105 const char* notExpectedExpr,
106 const char* actualExpr,
107 const T1& notExpected,
110 const ::testing::AssertionResult result =
AssertSome(actualExpr, actual);
113 if (notExpected == actual.get()) {
114 return ::testing::AssertionFailure()
115 <<
" Value of: (" << actualExpr <<
").get()\n"
116 <<
" Actual: " << ::testing::PrintToString(actual.get()) <<
"\n"
117 <<
"Not expected: " << notExpectedExpr <<
"\n"
118 <<
" Which is: " << ::testing::PrintToString(notExpected);
120 return ::testing::AssertionSuccess();
128 #define ASSERT_SOME(actual) \
129 ASSERT_PRED_FORMAT1(AssertSome, actual)
132 #define EXPECT_SOME(actual) \
133 EXPECT_PRED_FORMAT1(AssertSome, actual)
136 #define ASSERT_SOME_EQ(expected, actual) \
137 ASSERT_PRED_FORMAT2(AssertSomeEq, expected, actual)
140 #define EXPECT_SOME_EQ(expected, actual) \
141 EXPECT_PRED_FORMAT2(AssertSomeEq, expected, actual)
144 #define ASSERT_SOME_NE(notExpected, actual) \
145 ASSERT_PRED_FORMAT2(AssertSomeNe, notExpected, actual)
148 #define EXPECT_SOME_NE(notExpected, actual) \
149 EXPECT_PRED_FORMAT2(AssertSomeNe, notExpected, actual)
152 #define ASSERT_SOME_TRUE(actual) \
153 ASSERT_PRED_FORMAT2(AssertSomeEq, true, actual)
156 #define EXPECT_SOME_TRUE(actual) \
157 EXPECT_PRED_FORMAT2(AssertSomeEq, true, actual)
160 #define ASSERT_SOME_FALSE(actual) \
161 ASSERT_PRED_FORMAT2(AssertSomeEq, false, actual)
164 #define EXPECT_SOME_FALSE(actual) \
165 EXPECT_PRED_FORMAT2(AssertSomeEq, false, actual)
168 #define ASSERT_ERROR(actual) \
169 ASSERT_TRUE(actual.isError())
172 #define EXPECT_ERROR(actual) \
173 EXPECT_TRUE(actual.isError())
176 #define ASSERT_NONE(actual) \
177 ASSERT_TRUE(actual.isNone())
180 #define EXPECT_NONE(actual) \
181 EXPECT_TRUE(actual.isNone())
188 #define TEST_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
189 TEST(test_case_name, test_name)
191 #define TEST_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
192 TEST(test_case_name, DISABLED_##test_name)
193 #endif // __WINDOWS__
200 #define TEST_F_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
201 TEST_F(test_case_name, test_name)
203 #define TEST_F_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
204 TEST_F(test_case_name, DISABLED_##test_name)
205 #endif // __WINDOWS__
212 #define TEST_P_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
213 TEST_P(test_case_name, test_name)
215 #define TEST_P_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \
216 TEST_P(test_case_name, DISABLED_##test_name)
217 #endif // __WINDOWS__
227 #define SLEEP_COMMAND(x) "sleep " #x
229 #define SLEEP_COMMAND(x) \
230 "powershell -NoProfile -Command Start-Sleep -Seconds " #x
231 #endif // __WINDOWS__
235 const char* actualExpr,
239 return ::testing::AssertionSuccess();
241 return ::testing::AssertionFailure()
242 <<
"Expecting WIFEXITED(" << actualExpr <<
") but "
243 <<
" WIFSIGNALED(" << actualExpr <<
") is true and "
246 return ::testing::AssertionFailure()
247 <<
"Expecting WIFEXITED(" << actualExpr <<
") but"
248 <<
" WIFSTOPPED(" << actualExpr <<
") is true and "
252 return ::testing::AssertionFailure()
253 <<
"Expecting WIFEXITED(" << actualExpr <<
") but got"
254 <<
" unknown value: " << ::testing::PrintToString(actual);
258 #define ASSERT_EXITED(expected, actual) \
259 ASSERT_PRED_FORMAT2(AssertExited, expected, actual)
262 #define EXPECT_EXITED(expected, actual) \
263 EXPECT_PRED_FORMAT2(AssertExited, expected, actual)
267 const char* expectedExpr,
268 const char* actualExpr,
272 const ::testing::AssertionResult result =
AssertExited(actualExpr, actual);
276 return ::testing::AssertionSuccess();
278 return ::testing::AssertionFailure()
279 <<
"Value of: WEXITSTATUS(" << actualExpr <<
")\n"
280 <<
" Actual: " << ::testing::PrintToString(
WEXITSTATUS(actual)) <<
"\n"
281 <<
"Expected: " << expectedExpr <<
"\n"
282 <<
"Which is: " << ::testing::PrintToString(expected);
290 #define ASSERT_WEXITSTATUS_EQ(expected, actual) \
291 ASSERT_PRED_FORMAT2(AssertExitStatusEq, expected, actual)
294 #define EXPECT_WEXITSTATUS_EQ(expected, actual) \
295 EXPECT_PRED_FORMAT2(AssertExitStatusEq, expected, actual)
300 const char* expectedExpr,
301 const char* actualExpr,
305 const ::testing::AssertionResult result =
AssertExited(actualExpr, actual);
309 return ::testing::AssertionSuccess();
311 return ::testing::AssertionFailure()
312 <<
"Value of: WEXITSTATUS(" << actualExpr <<
")\n"
313 <<
" Actual: " << ::testing::PrintToString(
WEXITSTATUS(actual)) <<
"\n"
314 <<
"Expected: " << expectedExpr <<
"\n"
315 <<
"Which is: " << ::testing::PrintToString(expected);
323 #define ASSERT_WEXITSTATUS_NE(expected, actual) \
324 ASSERT_PRED_FORMAT2(AssertExitStatusNe, expected, actual)
327 #define EXPECT_WEXITSTATUS_NE(expected, actual) \
328 EXPECT_PRED_FORMAT2(AssertExitStatusNe, expected, actual)
332 const char* actualExpr,
336 return ::testing::AssertionFailure()
337 <<
"Expecting WIFSIGNALED(" << actualExpr <<
") but "
338 <<
" WIFEXITED(" << actualExpr <<
") is true and "
339 <<
"WEXITSTATUS(" << actualExpr <<
") is " <<
WEXITSTATUS(actual);
341 return ::testing::AssertionSuccess();
343 return ::testing::AssertionFailure()
344 <<
"Expecting WIFSIGNALED(" << actualExpr <<
") but"
345 <<
" WIFSTOPPED(" << actualExpr <<
") is true and "
349 return ::testing::AssertionFailure()
350 <<
"Expecting WIFSIGNALED(" << actualExpr <<
") but got"
351 <<
" unknown value: " << ::testing::PrintToString(actual);
355 #define ASSERT_SIGNALED(expected, actual) \
356 ASSERT_PRED_FORMAT2(AssertSignaled, expected, actual)
359 #define EXPECT_SIGNALED(expected, actual) \
360 EXPECT_PRED_FORMAT2(AssertSignaled, expected, actual)
364 const char* expectedExpr,
365 const char* actualExpr,
369 const ::testing::AssertionResult result =
AssertSignaled(actualExpr, actual);
373 return ::testing::AssertionSuccess();
375 return ::testing::AssertionFailure()
376 <<
"Value of: WTERMSIG(" << actualExpr <<
")\n"
378 <<
"Expected: " << expectedExpr <<
"\n"
387 #define ASSERT_WTERMSIG_EQ(expected, actual) \
388 ASSERT_PRED_FORMAT2(AssertTermSigEq, expected, actual)
391 #define EXPECT_WTERMSIG_EQ(expected, actual) \
392 EXPECT_PRED_FORMAT2(AssertTermSigEq, expected, actual)
396 const char* expectedExpr,
397 const char* actualExpr,
401 const ::testing::AssertionResult result =
AssertSignaled(actualExpr, actual);
405 return ::testing::AssertionSuccess();
407 return ::testing::AssertionFailure()
408 <<
"Value of: WTERMSIG(" << actualExpr <<
")\n"
410 <<
"Expected: " << expectedExpr <<
"\n"
419 #define ASSERT_WTERMSIG_NE(expected, actual) \
420 ASSERT_PRED_FORMAT2(AssertTermSigNe, expected, actual)
423 #define EXPECT_WTERMSIG_NE(expected, actual) \
424 EXPECT_PRED_FORMAT2(AssertTermSigNe, expected, actual)
426 #endif // __STOUT_GTEST_HPP__
inline::testing::AssertionResult AssertExitStatusNe(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:299
bool isNone() const
Definition: result.hpp:112
Definition: option.hpp:28
::testing::AssertionResult AssertSomeEq(const char *expectedExpr, const char *actualExpr, const T1 &expected, const T2 &actual)
Definition: gtest.hpp:79
static Result< T > error(const std::string &message)
Definition: result.hpp:53
const char * strsignal(int signum)
Definition: windows.hpp:358
Definition: result.hpp:40
::testing::AssertionResult AssertSome(const char *expr, const Option< T > &actual)
Definition: gtest.hpp:34
#define WSTOPSIG(x)
Definition: windows.hpp:401
inline::testing::AssertionResult AssertExitStatusEq(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:266
#define WIFSIGNALED(x)
Definition: windows.hpp:380
#define WIFSTOPPED(x)
Definition: windows.hpp:396
#define WEXITSTATUS(x)
Definition: windows.hpp:376
inline::testing::AssertionResult AssertTermSigNe(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:395
static Try error(const E &e)
Definition: try.hpp:42
#define WIFEXITED(x)
Definition: windows.hpp:370
bool isError() const
Definition: try.hpp:71
inline::testing::AssertionResult AssertTermSigEq(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:363
inline::testing::AssertionResult AssertSignaled(const char *actualExpr, const int actual)
Definition: gtest.hpp:331
bool isNone() const
Definition: option.hpp:116
#define WTERMSIG(x)
Definition: windows.hpp:386
bool isError() const
Definition: result.hpp:113
inline::testing::AssertionResult AssertExited(const char *actualExpr, const int actual)
Definition: gtest.hpp:234
::testing::AssertionResult AssertSomeNe(const char *notExpectedExpr, const char *actualExpr, const T1 ¬Expected, const T2 &actual)
Definition: gtest.hpp:104