Skip to content

Instantly share code, notes, and snippets.

@pathawks
Last active August 29, 2015 14:16
Show Gist options
  • Save pathawks/ade858d24b3b82c3f058 to your computer and use it in GitHub Desktop.
Save pathawks/ade858d24b3b82c3f058 to your computer and use it in GitHub Desktop.

Revisions

  1. pathawks revised this gist Feb 28, 2015. 1 changed file with 27 additions and 5 deletions.
    32 changes: 27 additions & 5 deletions Test.cpp
    Original file line number Diff line number Diff line change
    @@ -9,11 +9,33 @@
    #include <string>
    using namespace std;

    bool test( string message, const bool condition ) {
    const string PASS = "\033[90m[\033[1;32m ok \033[90m]\033[0m";
    const string FAIL = "\033[90m[\033[1;91m FAIL \033[90m]\033[0m";
    message.resize(71, ' ');
    cout << message << (condition?PASS:FAIL) << endl;
    #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;
    }

  2. pathawks revised this gist Feb 26, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Test.cpp
    Original file line number Diff line number Diff line change
    @@ -10,10 +10,10 @@
    using namespace std;

    bool test( string message, const bool condition ) {
    const string PASS = "\033[90m[ \033[32mok\033[90m ]";
    const string FAIL = "\033[90m[ \033[1;91mFAIL\033[90m ]";
    message.resize(60, ' ');
    cout << "\033[37m" << message << (condition?PASS:FAIL) << "\033[0m" << endl;
    const string PASS = "\033[90m[\033[1;32m ok \033[90m]\033[0m";
    const string FAIL = "\033[90m[\033[1;91m FAIL \033[90m]\033[0m";
    message.resize(71, ' ');
    cout << message << (condition?PASS:FAIL) << endl;
    return condition;
    }

  3. pathawks created this gist Feb 26, 2015.
    24 changes: 24 additions & 0 deletions Test.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /**
    * @author: Pat Hawks
    * Created on: Feb 26, 2015
    * Source File: Test.cpp
    */

    #include <iomanip>
    #include <iostream>
    #include <string>
    using namespace std;

    bool test( string message, const bool condition ) {
    const string PASS = "\033[90m[ \033[32mok\033[90m ]";
    const string FAIL = "\033[90m[ \033[1;91mFAIL\033[90m ]";
    message.resize(60, ' ');
    cout << "\033[37m" << message << (condition?PASS:FAIL) << "\033[0m" << endl;
    return condition;
    }

    int main( void ) {
    test("This test is true", true);
    test("This test will fail", false);
    return 0;
    }