1#ifndef YAZE_TEST_CORE_TESTING_H
2#define YAZE_TEST_CORE_TESTING_H
4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
7#include "absl/status/status.h"
8#include "absl/status/statusor.h"
10#define EXPECT_OK(expr) EXPECT_EQ((expr), absl::OkStatus())
12#define ASSERT_OK(expr) ASSERT_EQ((expr), absl::OkStatus())
14#define ASSERT_OK_AND_ASSIGN(lhs, rexpr) \
15 if (auto rexpr_value = (rexpr); rexpr_value.ok()) { \
16 lhs = std::move(rexpr_value).value(); \
18 FAIL() << "error: " << rexpr_value.status(); \
26MATCHER_P(StatusIs, status,
"") {
return arg.code() == status; }
30::testing::AssertionResult
IsOkAndHolds(
const absl::StatusOr<T>& status_or,
32 if (!status_or.ok()) {
33 return ::testing::AssertionFailure()
34 <<
"Expected status to be OK, but got: " << status_or.status();
36 if (status_or.value() != value) {
37 return ::testing::AssertionFailure() <<
"Expected value to be " << value
38 <<
", but got: " << status_or.value();
40 return ::testing::AssertionSuccess();
47 return !arg.ok() && arg.status().message() == message;
52 return !arg.ok() && arg.status().code() == code;
57template <
typename T,
typename Matcher>
59 const Matcher& matcher) {
60 if (!status_or.ok()) {
61 return ::testing::AssertionFailure()
62 <<
"Expected status to be OK, but got: " << status_or.status();
64 if (!::testing::Matches(matcher)(status_or.value())) {
65 return ::testing::AssertionFailure()
66 <<
"Value does not match expected matcher";
68 return ::testing::AssertionSuccess();
74 const absl::StatusOr<T>& b) {
75 if (a.ok() != b.ok()) {
76 return ::testing::AssertionFailure()
77 <<
"One status is OK while the other is not";
80 return ::testing::AssertionSuccess();
82 if (a.value() != b.value()) {
83 return ::testing::AssertionFailure()
84 <<
"Values are not equal: " << a.value() <<
" vs " << b.value();
86 return ::testing::AssertionSuccess();
MATCHER_P(StatusIs, status, "")
::testing::AssertionResult IsOkAndMatches(const absl::StatusOr< T > &status_or, const Matcher &matcher)
::testing::AssertionResult IsOkAndHolds(const absl::StatusOr< T > &status_or, const T &value)
::testing::AssertionResult StatusOrEqual(const absl::StatusOr< T > &a, const absl::StatusOr< T > &b)
Main namespace for the application.