yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
testing.h
Go to the documentation of this file.
1#ifndef YAZE_TEST_CORE_TESTING_H
2#define YAZE_TEST_CORE_TESTING_H
3
4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
6
7#include "absl/status/status.h"
8#include "absl/status/statusor.h"
9
10#define EXPECT_OK(expr) EXPECT_EQ((expr), absl::OkStatus())
11
12#define ASSERT_OK(expr) ASSERT_EQ((expr), absl::OkStatus())
13
14#define ASSERT_OK_AND_ASSIGN(lhs, rexpr) \
15 if (auto rexpr_value = (rexpr); rexpr_value.ok()) { \
16 lhs = std::move(rexpr_value).value(); \
17 } else { \
18 FAIL() << "error: " << rexpr_value.status(); \
19 }
20
21namespace yaze {
22namespace test {
23
24// StatusIs is a matcher that matches a status that has the same code and
25// message as the expected status.
26MATCHER_P(StatusIs, status, "") { return arg.code() == status; }
27
28// Support for testing absl::StatusOr.
29template <typename T>
30::testing::AssertionResult IsOkAndHolds(const absl::StatusOr<T>& status_or,
31 const T& value) {
32 if (!status_or.ok()) {
33 return ::testing::AssertionFailure()
34 << "Expected status to be OK, but got: " << status_or.status();
35 }
36 if (status_or.value() != value) {
37 return ::testing::AssertionFailure() << "Expected value to be " << value
38 << ", but got: " << status_or.value();
39 }
40 return ::testing::AssertionSuccess();
41}
42
43MATCHER_P(IsOkAndHolds, value, "") { return IsOkAndHolds(arg, value); }
44
45} // namespace test
46} // namespace yaze
47
48#endif // YAZE_TEST_CORE_TESTING_H
MATCHER_P(StatusIs, status, "")
Definition testing.h:26
::testing::AssertionResult IsOkAndHolds(const absl::StatusOr< T > &status_or, const T &value)
Definition testing.h:30
Definition common.cc:21