Skip to content

Instantly share code, notes, and snippets.

@pathawks
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathawks/ade858d24b3b82c3f058 to your computer and use it in GitHub Desktop.
Save pathawks/ade858d24b3b82c3f058 to your computer and use it in GitHub Desktop.
Test Framework
/**
* @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