Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Unit test for CResult matcher #712

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions test/unittests/test_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,53 @@ TEST(test_utils, result_value_matcher)
EXPECT_THAT(TypedExecutionResult(Value{1_u64}, ValType::i64), Not(Result(uint8_t{1})));
}

TEST(test_utils, cresult_value_matcher)
{
using testing::Not;

FizzyExecutionResult trap{true, false, FizzyValue{}};
EXPECT_THAT(trap, CTraps());
EXPECT_THAT(trap, Not(CResult()));

FizzyExecutionResult result_void{false, false, FizzyValue{}};
EXPECT_THAT(result_void, CResult());
EXPECT_THAT(result_void, Not(CTraps()));

// Each result type is checked only against values with equal type, because for other types
// CResult matcher would access non-active union members of result's value, which presents UB.

EXPECT_THAT(trap, Not(CResult(0_u32)));
EXPECT_THAT(result_void, Not(CResult(0_u32)));
FizzyValue value_i32{-1_u32};
FizzyExecutionResult result_i32{false, true, value_i32};
EXPECT_THAT(result_i32, CResult(-1_u32));
EXPECT_THAT(result_i32, Not(CResult(-2_u32)));

EXPECT_THAT(trap, Not(CResult(0_u64)));
EXPECT_THAT(result_void, Not(CResult(0_u64)));
FizzyValue value_i64;
value_i64.i64 = -1_u64;
FizzyExecutionResult result_i64{false, true, value_i64};
EXPECT_THAT(result_i64, CResult(-1_u64));
EXPECT_THAT(result_i64, Not(CResult(-2_u64)));

EXPECT_THAT(trap, Not(CResult(0.0f)));
EXPECT_THAT(result_void, Not(CResult(0.0f)));
FizzyValue value_f32;
value_f32.f32 = 1.1f;
FizzyExecutionResult result_f32{false, true, value_f32};
EXPECT_THAT(result_f32, CResult(1.1f));
EXPECT_THAT(result_f32, Not(CResult(1.0f)));

EXPECT_THAT(trap, Not(CResult(0.0)));
EXPECT_THAT(result_void, Not(CResult(0.0)));
FizzyValue value_f64;
value_f64.f64 = 2.2;
FizzyExecutionResult result_f64{false, true, value_f64};
EXPECT_THAT(result_f64, CResult(2.2));
EXPECT_THAT(result_f64, Not(CResult(2.0)));
}

TEST(test_utils, result_value_matcher_explain_missing_result_type)
{
const auto result = testing::internal::MakePredicateFormatterFromMatcher(Result(1_u64))(
Expand Down