summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-09-28 17:48:33 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-09-28 17:48:33 +0200
commit6df54459f540fa258824658ecd68602c83ccd348 (patch)
tree0318a3278d195f5426412d83d12f99834fc4923c
parentbc078da645412c6b36ef59e635d6c35d11088c96 (diff)
Experiment for testing if exit() is called without terminating the test program.exit_test
-rw-r--r--examples/ExampleTest.cc2
-rw-r--r--examples/getbaud.cc7
-rw-r--r--uunit.h14
3 files changed, 23 insertions, 0 deletions
diff --git a/examples/ExampleTest.cc b/examples/ExampleTest.cc
index aebe712..5b6d788 100644
--- a/examples/ExampleTest.cc
+++ b/examples/ExampleTest.cc
@@ -116,6 +116,8 @@ public:
uASSERT_EQUAL(Speed::B230400, getBaud(230400));
uASSERT_EQUAL(Speed::B230400, getBaud(230401));
+
+ uASSERT_THROWS(exit_called, getBaud(42));
}
void exceptionTests()
diff --git a/examples/getbaud.cc b/examples/getbaud.cc
index 2488fc1..24178fd 100644
--- a/examples/getbaud.cc
+++ b/examples/getbaud.cc
@@ -1,7 +1,14 @@
#include "getbaud.h"
+#include <cstdlib>
+
Speed getBaud(int speed)
{
+ if(speed == 42)
+ {
+ exit(42);
+ }
+
struct
{
int value;
diff --git a/uunit.h b/uunit.h
index 92feb8d..9ee6e5d 100644
--- a/uunit.h
+++ b/uunit.h
@@ -53,6 +53,11 @@ public:
std::size_t id;
};
+ struct exit_called
+ {
+ int exit_value;
+ };
+
//! Run test
//! \param test_suite the name of a test suite or null for all.
//! \param test_name the name of a test name inside a test suite. Only valid
@@ -323,4 +328,13 @@ void report_result(const char* name, const char* file, bool success)
std::function<void(const char*, const char*, bool)> uUnit::status_cb{report_result};
+extern "C"
+{
+void exit(int i)
+{
+ throw uUnit::exit_called{i};
+ while(1){}
+}
+}
+
#endif