Skip to content

Commit

Permalink
tests: Log exceptions thrown inside of unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Aug 1, 2015
1 parent cfed682 commit 7919318
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/unittest/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7919318

Please sign in to comment.