diff options
author | HÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com> | 2021-03-22 10:40:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-22 10:40:29 +0100 |
commit | 65faa8da798a0aba103c8cbd1c5617f213651f9a (patch) | |
tree | 9edb1af7af8bdf8a3000390e7bc701351e23f2fc /vespalib/src/tests/unwind_message/unwind_message_test.cpp | |
parent | d3ed6feb94eb5fcab0a9b6a663203f921f9953d4 (diff) | |
parent | 9a36eda856266bcdd5986ac4ca93fc9240abeb07 (diff) |
Merge pull request #17079 from vespa-engine/havardpe/unwind-message
added UnwindMessage/unwind_msg
Diffstat (limited to 'vespalib/src/tests/unwind_message/unwind_message_test.cpp')
-rw-r--r-- | vespalib/src/tests/unwind_message/unwind_message_test.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/vespalib/src/tests/unwind_message/unwind_message_test.cpp b/vespalib/src/tests/unwind_message/unwind_message_test.cpp new file mode 100644 index 00000000000..53a7bf26c90 --- /dev/null +++ b/vespalib/src/tests/unwind_message/unwind_message_test.cpp @@ -0,0 +1,37 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/vespalib/util/unwind_message.h> +#include <vespa/vespalib/gtest/gtest.h> +#include <stdexcept> + +using vespalib::unwind_msg; +using vespalib::UnwindMessage; + +//----------------------------------------------------------------------------- + +struct MyObj { + UnwindMessage msg1 = UnwindMessage("this SHOULD be printed (1/2)"); + UnwindMessage msg2 = UnwindMessage("this should NOT be printed (1)"); + ~MyObj() { + EXPECT_EQ(std::uncaught_exceptions(), 1); + auto not_printed_1 = std::move(msg2); + auto not_printed_2 = unwind_msg("this should NOT be printed (2)"); + } +}; + +TEST(UnwindMessageTest, unwind_messages_are_printed_when_appropriate) { + using E = std::invalid_argument; + auto not_printed_3 = unwind_msg("this should NOT be printed (3)"); + EXPECT_THROW( + { + EXPECT_EQ(std::uncaught_exceptions(), 0); + auto printed = unwind_msg("this SHOULD be printed (2/2)"); + { auto not_printed_4 = unwind_msg("this should NOT be printed (4)"); } + MyObj my_obj; + throw E("just testing"); + }, E); +} + +//----------------------------------------------------------------------------- + +GTEST_MAIN_RUN_ALL_TESTS() |