diff options
author | Håvard Pettersen <havardpe@oath.com> | 2021-03-19 15:26:41 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2021-03-19 15:26:41 +0000 |
commit | 9a36eda856266bcdd5986ac4ca93fc9240abeb07 (patch) | |
tree | 71c4507c3cb1ac33c08dd297e816a19614dad4e6 /vespalib/src/tests/unwind_message | |
parent | 028c4e6a1414a4180b198ae9b2bbfeb8f877f69f (diff) |
added UnwindMessage/unwind_msg
Diffstat (limited to 'vespalib/src/tests/unwind_message')
-rw-r--r-- | vespalib/src/tests/unwind_message/CMakeLists.txt | 9 | ||||
-rw-r--r-- | vespalib/src/tests/unwind_message/unwind_message_test.cpp | 37 |
2 files changed, 46 insertions, 0 deletions
diff --git a/vespalib/src/tests/unwind_message/CMakeLists.txt b/vespalib/src/tests/unwind_message/CMakeLists.txt new file mode 100644 index 00000000000..92295ada035 --- /dev/null +++ b/vespalib/src/tests/unwind_message/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespalib_unwind_message_test_app TEST + SOURCES + unwind_message_test.cpp + DEPENDS + vespalib + GTest::GTest +) +vespa_add_test(NAME vespalib_unwind_message_test_app COMMAND vespalib_unwind_message_test_app) 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() |