userver: userver/utest/death_tests.hpp Source File
Loading...
Searching...
No Matches
death_tests.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <gtest/gtest.h>
8
10#include <userver/utils/impl/disable_core_dumps.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace utest::impl {
15
16class DeathTestScope final {
17public:
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
24private:
25 utils::impl::DisableCoreDumps disable_core_dumps_;
26 bool keep_iterating_{true};
27};
28
29} // namespace utest::impl
30
31USERVER_NAMESPACE_END
32
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
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)