tests: Log exceptions thrown inside of unit tests
authorkwolekr <kwolekr@minetest.net>
Sat, 1 Aug 2015 03:29:51 +0000 (23:29 -0400)
committerkwolekr <kwolekr@minetest.net>
Sat, 1 Aug 2015 03:30:25 +0000 (23:30 -0400)
src/unittest/test.h

index e1f1721f951127943f788bd012afcdf0478b6fb1..47a441e025766dafb41714faa28165d7753bdb8e 100644 (file)
@@ -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