diff options
author | peterbell10 <peterbell10@live.co.uk> | 2020-05-05 22:39:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 22:39:59 +0200 |
commit | 8e2dfce84bf5e3993a910e535a51d40ebe0803d0 (patch) | |
tree | 0f570f9f54d8afc8dac4db307d32a6fa057d15f3 /tests/TestHelpers.h | |
parent | Remove cRankManager migration code (#4714) (diff) | |
download | cuberite-8e2dfce84bf5e3993a910e535a51d40ebe0803d0.tar cuberite-8e2dfce84bf5e3993a910e535a51d40ebe0803d0.tar.gz cuberite-8e2dfce84bf5e3993a910e535a51d40ebe0803d0.tar.bz2 cuberite-8e2dfce84bf5e3993a910e535a51d40ebe0803d0.tar.lz cuberite-8e2dfce84bf5e3993a910e535a51d40ebe0803d0.tar.xz cuberite-8e2dfce84bf5e3993a910e535a51d40ebe0803d0.tar.zst cuberite-8e2dfce84bf5e3993a910e535a51d40ebe0803d0.zip |
Diffstat (limited to 'tests/TestHelpers.h')
-rw-r--r-- | tests/TestHelpers.h | 130 |
1 files changed, 74 insertions, 56 deletions
diff --git a/tests/TestHelpers.h b/tests/TestHelpers.h index b5c905f43..0ef4014ac 100644 --- a/tests/TestHelpers.h +++ b/tests/TestHelpers.h @@ -45,12 +45,14 @@ public: /** Checks that the two values are equal; if not, throws a TestException. */ #define TEST_EQUAL(VAL1, VAL2) \ - if (VAL1 != VAL2) \ - { \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Equality test failed: %s != %s", \ - #VAL1, #VAL2 \ - )); \ - } + do { \ + if (VAL1 != VAL2) \ + { \ + throw TestException( \ + __FILE__, __LINE__, __FUNCTION__, \ + Printf("Equality test failed: %s != %s", #VAL1, #VAL2)); \ + } \ + } while (false) @@ -58,12 +60,14 @@ public: /** Checks that the two values are equal; if not, throws a TestException, includes the specified message. */ #define TEST_EQUAL_MSG(VAL1, VAL2, MSG) \ - if (VAL1 != VAL2) \ - { \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Equality test failed: %s != %s (%s)", \ - #VAL1, #VAL2, MSG \ - )); \ - } + do { \ + if (VAL1 != VAL2) \ + { \ + throw TestException( \ + __FILE__, __LINE__, __FUNCTION__, \ + Printf("Equality test failed: %s != %s (%s)", #VAL1, #VAL2, MSG)); \ + } \ + } while (false) @@ -71,12 +75,15 @@ public: /** Checks that the two values are not equal; if they are, throws a TestException. */ #define TEST_NOTEQUAL(VAL1, VAL2) \ - if (VAL1 == VAL2) \ - { \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Inequality test failed: %s == %s", \ - #VAL1, #VAL2 \ - )); \ - } + do { \ + if (VAL1 == VAL2) \ + { \ + throw TestException( \ + __FILE__, __LINE__, __FUNCTION__, \ + Printf("Inequality test failed: %s == %s", #VAL1, #VAL2) \ + ); \ + } \ + } while(false) @@ -124,29 +131,36 @@ public: /** Checks that the statement throws an exception of the specified class. */ #define TEST_THROWS(Stmt, ExcClass) \ - try \ - { \ - Stmt; \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Failed to throw an exception of type %s", \ - #ExcClass \ - )); \ - } \ - catch (const ExcClass &) \ - { \ - /* This is the expected case. */ \ - } \ - catch (const std::exception & exc) \ - { \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("An unexpected std::exception descendant was thrown, was expecting type %s. Message is: %s", \ - #ExcClass, exc.what() \ - )); \ - } \ - catch (...) \ - { \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("An unexpected unknown exception object was thrown, was expecting type %s", \ - #ExcClass \ - )); \ - } + do { \ + try \ + { \ + Stmt; \ + throw TestException( \ + __FILE__, __LINE__, __FUNCTION__, \ + Printf("Failed to throw an exception of type %s", #ExcClass) \ + ); \ + } \ + catch (const ExcClass &) \ + { \ + /* This is the expected case. */ \ + } \ + catch (const std::exception & exc) \ + { \ + throw TestException( \ + __FILE__, __LINE__, __FUNCTION__, \ + Printf("An unexpected std::exception descendant was thrown, was expecting type %s. Message is: %s", \ + #ExcClass, exc.what() \ + )); \ + } \ + catch (...)\ + { \ + throw TestException( \ + __FILE__, __LINE__, __FUNCTION__, \ + Printf("An unexpected unknown exception object was thrown, was expecting type %s", \ + #ExcClass \ + )); \ + } \ + } while (false) @@ -154,19 +168,23 @@ public: /** Checks that the statement throws an exception of any type. */ #define TEST_THROWS_ANY(Stmt) \ - try \ - { \ - Stmt; \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, "Failed to throw an exception of any type"); \ - } \ - catch (const TestException & exc) \ - { \ - throw exc; \ - } \ - catch (...) \ - { \ - /* This is the expected case */ \ - } + do { \ + try \ + { \ + Stmt; \ + throw TestException( \ + __FILE__, __LINE__, __FUNCTION__, \ + "Failed to throw an exception of any type"); \ + } \ + catch (const TestException & exc) \ + { \ + throw exc; \ + } \ + catch (...)\ + { \ + /* This is the expected case */ \ + } \ + } while (false) @@ -174,7 +192,7 @@ public: /** Fails the test unconditionally, with the specified message. */ #define TEST_FAIL(MSG) \ - throw TestException(__FILE__, __LINE__, __FUNCTION__, MSG); + throw TestException(__FILE__, __LINE__, __FUNCTION__, MSG) @@ -184,7 +202,7 @@ public: #ifdef _DEBUG #define TEST_ASSERTS(Stmt) TEST_THROWS(Stmt, cAssertFailure) #else - #define TEST_ASSERTS(Stmt) LOG("Skipped, cannot test in Release mode: TEST_ASSERT(%s); (%s:%d)", #Stmt, __FILE__, __LINE__); + #define TEST_ASSERTS(Stmt) LOG("Skipped, cannot test in Release mode: TEST_ASSERT(%s); (%s:%d)", #Stmt, __FILE__, __LINE__) #endif // else _DEBUG |