diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-04 23:51:30 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-04 23:51:30 +0000 |
commit | fe146fa123a8965b8d8f0f3f2d89f8e9fad8e677 (patch) | |
tree | 94403c7b917a4ae6c593dae0f518b4499be4b853 /vespalib/src/tests/exception_classes | |
parent | a34c6e774c8cd4365fbbe093e5d0d8c71904a9e1 (diff) |
Add test proving that this did not work. Must set/unset terminate_handler. But that will be tomorrow.
Diffstat (limited to 'vespalib/src/tests/exception_classes')
4 files changed, 67 insertions, 0 deletions
diff --git a/vespalib/src/tests/exception_classes/.gitignore b/vespalib/src/tests/exception_classes/.gitignore index bed545b71f8..fe7001def80 100644 --- a/vespalib/src/tests/exception_classes/.gitignore +++ b/vespalib/src/tests/exception_classes/.gitignore @@ -1 +1,2 @@ vespalib_exception_classes_test_app +vespalib_caught_uncaught_app diff --git a/vespalib/src/tests/exception_classes/CMakeLists.txt b/vespalib/src/tests/exception_classes/CMakeLists.txt index 691ebc1daea..134634252ff 100644 --- a/vespalib/src/tests/exception_classes/CMakeLists.txt +++ b/vespalib/src/tests/exception_classes/CMakeLists.txt @@ -6,3 +6,16 @@ vespa_add_executable(vespalib_exception_classes_test_app TEST vespalib ) vespa_add_test(NAME vespalib_exception_classes_test_app COMMAND vespalib_exception_classes_test_app) +vespa_add_executable(vespalib_silenceuncaught_test_app TEST + SOURCES + silenceuncaught_test.cpp + DEPENDS + vespalib +) +vespa_add_test(NAME vespalib_silenceuncaught_test_app COMMAND vespalib_silenceuncaught_test_app) +vespa_add_executable(vespalib_caught_uncaught_app TEST + SOURCES + caught_uncaught.cpp + DEPENDS + vespalib +) diff --git a/vespalib/src/tests/exception_classes/caught_uncaught.cpp b/vespalib/src/tests/exception_classes/caught_uncaught.cpp new file mode 100644 index 00000000000..5e550b4bf77 --- /dev/null +++ b/vespalib/src/tests/exception_classes/caught_uncaught.cpp @@ -0,0 +1,27 @@ +#include <vespa/vespalib/util/exception.h> + +using vespalib::SilenceUncaughtException; + +int main(int argc, char *argv[]) { + if (argc != 2) { + return 77; + } + std::runtime_error e("caught or not"); + if (strcmp("uncaught", argv[1]) == 0) { + throw e; + } else if (strcmp("silenced_and_caught", argv[1]) == 0) { + try { + SilenceUncaughtException silenced(e); + throw e; + } catch (const std::runtime_error & ) { + printf("caught it\n"); + } + } else if (strcmp("silenced_and_uncaught", argv[1]) == 0) { + SilenceUncaughtException silenced(e); + throw e; + } else { + return 55; + } + + return 0; +} diff --git a/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp new file mode 100644 index 00000000000..7f6ae20ded9 --- /dev/null +++ b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp @@ -0,0 +1,26 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/util/exception.h> +#include <vespa/vespalib/util/slaveproc.h> + +using namespace vespalib; + +TEST("that uncaught exception causes exitcode 1") { + SlaveProc proc("./vespalib_caught_uncaught_app uncaught"); + proc.wait(); + EXPECT_LESS(proc.getExitCode(), 0); +} + +TEST("that uncaught silenced exception causes exitcode 66") { + SlaveProc proc("./vespalib_caught_uncaught_app silenced_and_uncaught"); + proc.wait(); + EXPECT_EQUAL(proc.getExitCode(), 66); +} + +TEST("that caught silenced exception causes exitcode 0") { + SlaveProc proc("./vespalib_caught_uncaught_app silenced_and_caught"); + proc.wait(); + EXPECT_EQUAL(proc.getExitCode(), 0); +} + +TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); } |