Last active
August 19, 2016 02:23
-
-
Save mathewmariani/43a7ad2826d6020f65210c73f4c191ea to your computer and use it in GitHub Desktop.
A simple macro for quick unit testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#define TEST(__condition) \ | |
if ((__condition)) { \ | |
printf("[PASSED]\t%s\n", #__condition); \ | |
} else { \ | |
printf("[FAILED]\t%s\n", #__condition); \ | |
} | |
#define TEST_THROW(__condition, __exception) \ | |
try { \ | |
printf("[FAILED]\t%s\n", #__condition); \ | |
} catch (const __exception &e) { \ | |
printf("[PASSED]\t%s\n", #__condition); \ | |
} | |
#define TEST_NO_THROW(__condition) \ | |
try { \ | |
printf("[PASSED]\t%s\n", #__condition); \ | |
} catch (...) { \ | |
printf("[FAILED]\t%s\n", #__condition); \ | |
} | |
// example | |
int main() { | |
TEST(true == true); | |
TEST(123 != 124); | |
TEST(true == false); | |
return 0; | |
} | |
// output | |
// [PASSED] true == true | |
// [PASSED] 123 != 124 | |
// [FAILED] true == false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment