@@ -76,9 +76,9 @@ DeathCause assertion_death_cause = DeathCause::Trap;
76
76
#endif
77
77
78
78
int main (int , char **) {
79
- auto fail_assert = [] { _LIBCPP_ASSERT (false , " Some message" ); };
80
- Matcher good_matcher = MakeAssertionMessageMatcher (" Some message" );
81
- Matcher bad_matcher = MakeAssertionMessageMatcher (" Bad expected message" );
79
+ [[maybe_unused]] auto fail_assert = [] { _LIBCPP_ASSERT (false , " Some message" ); };
80
+ Matcher good_matcher = MakeAssertionMessageMatcher (" Some message" );
81
+ Matcher bad_matcher = MakeAssertionMessageMatcher (" Bad expected message" );
82
82
83
83
// Test the implementation of death tests. We're bypassing the assertions added by the actual `EXPECT_DEATH` macros
84
84
// which allows us to test failure cases (where the assertion would fail) as well.
@@ -89,16 +89,22 @@ int main(int, char**) {
89
89
// Success -- trapping.
90
90
TEST_DEATH_TEST (Outcome::Success, DeathCause::Trap, __builtin_trap ());
91
91
92
+ // `_LIBCPP_ASSERT` does not terminate the program if the `observe` semantic is used, so these tests would fail with
93
+ // `DidNotDie` cause.
94
+ #if _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_OBSERVE
95
+
92
96
// Success -- assertion failure with any matcher.
93
97
TEST_DEATH_TEST_MATCHES (Outcome::Success, assertion_death_cause, MakeAnyMatcher (), fail_assert ());
94
98
95
99
// Success -- assertion failure with a specific matcher.
96
100
TEST_DEATH_TEST_MATCHES (Outcome::Success, assertion_death_cause, good_matcher, fail_assert ());
97
101
98
- #if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
102
+ # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
99
103
// Failure -- error message doesn't match.
100
104
TEST_DEATH_TEST_MATCHES (Outcome::UnexpectedErrorMessage, assertion_death_cause, bad_matcher, fail_assert ());
101
- #endif
105
+ # endif
106
+
107
+ #endif // _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_OBSERVE
102
108
103
109
// Invalid cause -- child did not die.
104
110
TEST_DEATH_TEST (Outcome::InvalidCause, DeathCause::DidNotDie, ((void )0 ));
@@ -125,7 +131,9 @@ int main(int, char**) {
125
131
EXPECT_DEATH_MATCHES (simple_matcher, invoke_verbose_abort ());
126
132
EXPECT_STD_ABORT (invoke_abort ());
127
133
EXPECT_STD_TERMINATE ([] { std::terminate (); });
134
+ #if _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_OBSERVE
128
135
TEST_LIBCPP_ASSERT_FAILURE (fail_assert (), " Some message" );
136
+ #endif
129
137
}
130
138
131
139
return 0 ;
0 commit comments