summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-05 10:19:42 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-09-05 10:19:42 +0000
commit1be7e8b0848377f52622fc8306640e6325a40c52 (patch)
treec9b4f78e6146b92c5627def813570169c15eb0ab /vespalib/src/tests
parentffe0351586b3d50f477e59d6a9947cd1d1dedc44 (diff)
It was not as easy as it should have been.
Diffstat (limited to 'vespalib/src/tests')
-rw-r--r--vespalib/src/tests/exception_classes/caught_uncaught.cpp37
-rw-r--r--vespalib/src/tests/exception_classes/silenceuncaught_test.cpp6
2 files changed, 33 insertions, 10 deletions
diff --git a/vespalib/src/tests/exception_classes/caught_uncaught.cpp b/vespalib/src/tests/exception_classes/caught_uncaught.cpp
index 5e550b4bf77..c742b2e28e1 100644
--- a/vespalib/src/tests/exception_classes/caught_uncaught.cpp
+++ b/vespalib/src/tests/exception_classes/caught_uncaught.cpp
@@ -1,24 +1,41 @@
#include <vespa/vespalib/util/exception.h>
using vespalib::SilenceUncaughtException;
+using vespalib::GuardTheTerminationHandler;
+
+void throwE() {
+ std::runtime_error e("caught or not");
+ throw e;
+}
+
+void silenceE() {
+ std::runtime_error e("caught or not");
+ SilenceUncaughtException silenced(e);
+ throw e;
+}
+
+void throwAndCatch() {
+ GuardTheTerminationHandler terminationHandlerGuard;
+ try {
+ silenceE();
+ } catch (const std::exception & e) {
+ printf("caught it\n");
+ }
+}
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;
+ throwE();
} else if (strcmp("silenced_and_caught", argv[1]) == 0) {
- try {
- SilenceUncaughtException silenced(e);
- throw e;
- } catch (const std::runtime_error & ) {
- printf("caught it\n");
- }
+ throwAndCatch();
+ } else if (strcmp("uncaught_after_silenced_and_caught", argv[1]) == 0) {
+ throwAndCatch();
+ throwE();
} else if (strcmp("silenced_and_uncaught", argv[1]) == 0) {
- SilenceUncaughtException silenced(e);
- throw e;
+ silenceE();
} else {
return 55;
}
diff --git a/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
index 3b1ba49de5c..3e13e1d8606 100644
--- a/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
+++ b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
@@ -17,6 +17,12 @@ TEST("that uncaught silenced exception causes exitcode 66") {
EXPECT_EQUAL(proc.getExitCode(), 66);
}
+TEST("that caught silenced exception followed by an uncaught causes exitcode 0") {
+ SlaveProc proc("./vespalib_caught_uncaught_app uncaught_after_silenced_and_caught");
+ proc.wait();
+ EXPECT_LESS(proc.getExitCode(), 0);
+}
+
TEST("that caught silenced exception causes exitcode 0") {
SlaveProc proc("./vespalib_caught_uncaught_app silenced_and_caught");
proc.wait();