Skip to content

Commit

Permalink
Guard tests for methods that are not available with std::expected (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmoene committed Jun 5, 2024
1 parent 8fd610a commit 0cae5c3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/expected.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,18 +1200,26 @@ CASE( "expected: Allows to move its error" )

CASE( "expected: Allows to observe its error as unexpected" )
{
#if !nsel_USES_STD_EXPECTED
const auto v = 7;
expected<char, Implicit> e{ unexpect, v };

EXPECT( e.get_unexpected().error() == v );
#else
EXPECT( !!"expected::get_unexpected() is not available (using C++23 std::expected)" );
#endif
}

CASE( "expected: Allows to query if it contains an exception of a specific base type" )
{
#if !nsel_USES_STD_EXPECTED
expected<int, std::out_of_range> e{ unexpect, std::out_of_range( "oor" ) };

EXPECT( e.has_exception< std::logic_error >() );
EXPECT( !e.has_exception< std::runtime_error >() );
#else
EXPECT( !!"expected::has_exception() is not available (using C++23 std::expected)" );
#endif
}

CASE( "expected: Allows to observe its value if available, or obtain a specified value otherwise" )
Expand Down Expand Up @@ -1641,18 +1649,26 @@ CASE( "expected<void>: Allows to move its error" )

CASE( "expected<void>: Allows to observe its error as unexpected" )
{
#if !nsel_USES_STD_EXPECTED
const auto value = 7;
expected<void, int> e{ unexpect, value };

EXPECT( e.get_unexpected().error() == value );
#else
EXPECT( !!"expected::get_unexpected() is not available (using C++23 std::expected)" );
#endif
}

CASE( "expected<void>: Allows to query if it contains an exception of a specific base type" )
{
#if !nsel_USES_STD_EXPECTED
expected<void, std::out_of_range> e{ unexpect, std::out_of_range( "oor" ) };

EXPECT( e.has_exception< std::logic_error >() );
EXPECT( !e.has_exception< std::runtime_error >() );
#else
EXPECT( !!"expected::has_exception() is not available (using C++23 std::expected)" );
#endif
}

CASE( "expected<void>: Throws bad_expected_access on value access when disengaged" )
Expand Down

0 comments on commit 0cae5c3

Please sign in to comment.