userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
death_tests.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utest/death_tests.hpp
4
/// @brief Contains facilities for testing service crashes
5
/// @ingroup userver_universal
6
7
#
include
<
gtest
/
gtest
.
h
>
8
9
#
include
<
userver
/
utils
/
assert
.
hpp
>
10
#
include
<
userver
/
utils
/
impl
/
disable_core_dumps
.
hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
utest
::impl {
15
16
class
DeathTestScope
final
{
17
public
:
18
DeathTestScope() {
utils
::impl::dump_stacktrace_on_assert_failure =
false
; }
19
~DeathTestScope() {
utils
::impl::dump_stacktrace_on_assert_failure =
true
; }
20
21
bool
ShouldKeepIterating()
const
noexcept
{
return
keep_iterating_; }
22
void
StopIterating()
noexcept
{ keep_iterating_ =
false
; }
23
24
private
:
25
utils
::impl::DisableCoreDumps disable_core_dumps_;
26
bool
keep_iterating_{
true
};
27
};
28
29
}
// namespace utest::impl
30
31
USERVER_NAMESPACE_END
32
33
/// @ingroup userver_utest
34
///
35
/// @brief An optimized equivalent of EXPECT_DEATH.
36
///
37
/// @hideinitializer
38
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
39
#
define
UEXPECT_DEATH
(
statement
,
regex_or_matcher
)
40
for
(
USERVER_NAMESPACE
::
utest
::
impl
::
DeathTestScope
utest_impl_death_test_scope
;
41
utest_impl_death_test_scope
.
ShouldKeepIterating
(
)
;
42
utest_impl_death_test_scope
.
StopIterating
(
)
)
43
EXPECT_DEATH
(
statement
,
regex_or_matcher
)
44
45
/// @ingroup userver_utest
46
///
47
/// @brief An optimized equivalent of EXPECT_DEBUG_DEATH.
48
///
49
/// @hideinitializer
50
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
51
#
define
UEXPECT_DEBUG_DEATH
(
statement
,
regex_or_matcher
)
52
for
(
USERVER_NAMESPACE
::
utest
::
impl
::
DeathTestScope
utest_impl_death_test_scope
;
53
utest_impl_death_test_scope
.
ShouldKeepIterating
(
)
;
54
utest_impl_death_test_scope
.
StopIterating
(
)
)
55
EXPECT_DEBUG_DEATH
(
statement
,
regex_or_matcher
)
userver
utest
death_tests.hpp
Generated on
for userver by
Doxygen
1.17.0