Last active
August 29, 2015 14:16
-
-
Save pathawks/ade858d24b3b82c3f058 to your computer and use it in GitHub Desktop.
Test Framework
This file contains hidden or 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
/** | |
* @author: Pat Hawks | |
* Created on: Feb 26, 2015 | |
* Source File: Test.cpp | |
*/ | |
#include <iomanip> | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
#ifdef _WIN32 | |
#include <windows.h> | |
HANDLE hConsole; | |
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); | |
#define PASS_COLOR() SetConsoleTextAttribute(hConsole, 10); | |
#define FAIL_COLOR() SetConsoleTextAttribute(hConsole, 12); | |
#define DFLT_COLOR() SetConsoleTextAttribute(hConsole, 7); | |
#else | |
#define PASS_COLOR() cout << "\033[1;32m"; | |
#define FAIL_COLOR() cout << "\033[1;91m"; | |
#define DFLT_COLOR() cout << "\033[0m"; | |
#endif | |
bool test( string message, const bool condition, const bool showPass=true ) { | |
if (showPass || !condition) { | |
message.resize(70, ' '); | |
cout << message << "["; | |
if (condition) { | |
PASS_COLOR(); | |
cout << " ok "; | |
} else { | |
FAIL_COLOR(); | |
cout << " FAIL "; | |
} | |
DFLT_COLOR(); | |
cout << "]" << endl; | |
} | |
return condition; | |
} | |
int main( void ) { | |
test("This test is true", true); | |
test("This test will fail", false); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment