Skip to content

Instantly share code, notes, and snippets.

@mathewmariani
Last active August 19, 2016 02:23
Show Gist options
  • Save mathewmariani/43a7ad2826d6020f65210c73f4c191ea to your computer and use it in GitHub Desktop.
Save mathewmariani/43a7ad2826d6020f65210c73f4c191ea to your computer and use it in GitHub Desktop.
A simple macro for quick unit testing.
#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