aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-07-31 23:29:51 -0400
committerkwolekr <kwolekr@minetest.net>2015-07-31 23:30:25 -0400
commit7919318be715e3bf60f01b7c63816a3e5802176d (patch)
tree231db834f80c1ea4e04d8367caebd2dca2bf3242
parentcfed682d04a5345763b82344435199fcf95faa78 (diff)
downloadminetest-7919318be715e3bf60f01b7c63816a3e5802176d.tar.gz
minetest-7919318be715e3bf60f01b7c63816a3e5802176d.tar.bz2
minetest-7919318be715e3bf60f01b7c63816a3e5802176d.zip
tests: Log exceptions thrown inside of unit tests
-rw-r--r--src/unittest/test.h28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/unittest/test.h b/src/unittest/test.h
index e1f1721f9..47a441e02 100644
--- a/src/unittest/test.h
+++ b/src/unittest/test.h
@@ -32,18 +32,22 @@ class TestFailedException : public std::exception {
};
// Runs a unit test and reports results
-#define TEST(fxn, ...) do { \
- u32 t1 = porting::getTime(PRECISION_MILLI); \
- try { \
- fxn(__VA_ARGS__); \
- dstream << "[PASS] "; \
- } catch (...) { \
- dstream << "[FAIL] "; \
- num_tests_failed++; \
- } \
- num_tests_run++; \
- u32 tdiff = porting::getTime(PRECISION_MILLI) - t1; \
- dstream << #fxn << " - " << tdiff << "ms" << std::endl; \
+#define TEST(fxn, ...) do { \
+ u32 t1 = porting::getTime(PRECISION_MILLI); \
+ try { \
+ fxn(__VA_ARGS__); \
+ dstream << "[PASS] "; \
+ } catch (TestFailedException &e) { \
+ dstream << "[FAIL] "; \
+ num_tests_failed++; \
+ } catch (std::exception &e) { \
+ dstream << "Caught unhandled exception: " << e.what() << std::endl; \
+ dstream << "[FAIL] "; \
+ num_tests_failed++; \
+ } \
+ num_tests_run++; \
+ u32 tdiff = porting::getTime(PRECISION_MILLI) - t1; \
+ dstream << #fxn << " - " << tdiff << "ms" << std::endl; \
} while (0)
// Asserts the specified condition is true, or fails the current unit test