Tests: Added color to the C++ tests

This commit is contained in:
Paul Beckingham 2015-07-01 16:12:48 -04:00
parent 535fc1c465
commit 8e8b2f9f38
2 changed files with 79 additions and 23 deletions

View file

@ -26,6 +26,7 @@
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
@ -115,7 +116,8 @@ void UnitTest::ok (bool expression, const std::string& name)
if (expression)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -124,7 +126,8 @@ void UnitTest::ok (bool expression, const std::string& name)
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -140,7 +143,8 @@ void UnitTest::notok (bool expression, const std::string& name)
if (!expression)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -149,7 +153,8 @@ void UnitTest::notok (bool expression, const std::string& name)
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -164,7 +169,8 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
if (actual == expected)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -173,7 +179,8 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -192,7 +199,8 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
if (actual == expected)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -201,7 +209,8 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -220,7 +229,8 @@ void UnitTest::is (int actual, int expected, const std::string& name)
if (actual == expected)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -229,7 +239,8 @@ void UnitTest::is (int actual, int expected, const std::string& name)
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -248,7 +259,8 @@ void UnitTest::is (double actual, double expected, const std::string& name)
if (actual == expected)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -257,7 +269,8 @@ void UnitTest::is (double actual, double expected, const std::string& name)
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -276,7 +289,8 @@ void UnitTest::is (double actual, double expected, double tolerance, const std::
if (fabs (actual - expected) <= tolerance)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -285,7 +299,8 @@ void UnitTest::is (double actual, double expected, double tolerance, const std::
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -304,7 +319,8 @@ void UnitTest::is (unsigned char actual, unsigned char expected, const std::stri
if (actual == expected)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -313,7 +329,8 @@ void UnitTest::is (unsigned char actual, unsigned char expected, const std::stri
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -335,7 +352,8 @@ void UnitTest::is (
if (actual == expected)
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -344,7 +362,8 @@ void UnitTest::is (
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -367,7 +386,8 @@ void UnitTest::is (
if (! strcmp (actual, expected))
{
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
@ -376,7 +396,8 @@ void UnitTest::is (
else
{
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
@ -402,7 +423,8 @@ void UnitTest::pass (const std::string& text)
{
++_counter;
++_passed;
std::cout << "ok "
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< text
@ -414,7 +436,8 @@ void UnitTest::fail (const std::string& text)
{
++_counter;
++_failed;
std::cout << "not ok "
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< text
@ -426,7 +449,8 @@ void UnitTest::skip (const std::string& text)
{
++_counter;
++_skipped;
std::cout << "skip "
std::cout << yellow ("skip")
<< " "
<< _counter
<< " - "
<< text
@ -434,3 +458,30 @@ void UnitTest::skip (const std::string& text)
}
///////////////////////////////////////////////////////////////////////////////
std::string UnitTest::red (const std::string& input)
{
if (isatty (fileno (stdout)))
return std::string ("\033[31m" + input + "\033[0m");
return input;
}
///////////////////////////////////////////////////////////////////////////////
std::string UnitTest::green (const std::string& input)
{
if (isatty (fileno (stdout)))
return std::string ("\033[32m" + input + "\033[0m");
return input;
}
///////////////////////////////////////////////////////////////////////////////
std::string UnitTest::yellow (const std::string& input)
{
if (isatty (fileno (stdout)))
return std::string ("\033[33m" + input + "\033[0m");
return input;
}
///////////////////////////////////////////////////////////////////////////////

View file

@ -53,6 +53,11 @@ public:
void fail (const std::string&);
void skip (const std::string&);
private:
std::string red (const std::string&);
std::string green (const std::string&);
std::string yellow (const std::string&);
private:
int _planned;
int _counter;