Tests: Added color to the C++ tests
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -115,7 +116,8 @@ void UnitTest::ok (bool expression, const std::string& name)
|
|||||||
if (expression)
|
if (expression)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -124,7 +126,8 @@ void UnitTest::ok (bool expression, const std::string& name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -140,7 +143,8 @@ void UnitTest::notok (bool expression, const std::string& name)
|
|||||||
if (!expression)
|
if (!expression)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -149,7 +153,8 @@ void UnitTest::notok (bool expression, const std::string& name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -164,7 +169,8 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
|
|||||||
if (actual == expected)
|
if (actual == expected)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -173,7 +179,8 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -192,7 +199,8 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
|
|||||||
if (actual == expected)
|
if (actual == expected)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -201,7 +209,8 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -220,7 +229,8 @@ void UnitTest::is (int actual, int expected, const std::string& name)
|
|||||||
if (actual == expected)
|
if (actual == expected)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -229,7 +239,8 @@ void UnitTest::is (int actual, int expected, const std::string& name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -248,7 +259,8 @@ void UnitTest::is (double actual, double expected, const std::string& name)
|
|||||||
if (actual == expected)
|
if (actual == expected)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -257,7 +269,8 @@ void UnitTest::is (double actual, double expected, const std::string& name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -276,7 +289,8 @@ void UnitTest::is (double actual, double expected, double tolerance, const std::
|
|||||||
if (fabs (actual - expected) <= tolerance)
|
if (fabs (actual - expected) <= tolerance)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -285,7 +299,8 @@ void UnitTest::is (double actual, double expected, double tolerance, const std::
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -304,7 +319,8 @@ void UnitTest::is (unsigned char actual, unsigned char expected, const std::stri
|
|||||||
if (actual == expected)
|
if (actual == expected)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -313,7 +329,8 @@ void UnitTest::is (unsigned char actual, unsigned char expected, const std::stri
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -335,7 +352,8 @@ void UnitTest::is (
|
|||||||
if (actual == expected)
|
if (actual == expected)
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -344,7 +362,8 @@ void UnitTest::is (
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -367,7 +386,8 @@ void UnitTest::is (
|
|||||||
if (! strcmp (actual, expected))
|
if (! strcmp (actual, expected))
|
||||||
{
|
{
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -376,7 +396,8 @@ void UnitTest::is (
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
@@ -402,7 +423,8 @@ void UnitTest::pass (const std::string& text)
|
|||||||
{
|
{
|
||||||
++_counter;
|
++_counter;
|
||||||
++_passed;
|
++_passed;
|
||||||
std::cout << "ok "
|
std::cout << green ("ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< text
|
<< text
|
||||||
@@ -414,7 +436,8 @@ void UnitTest::fail (const std::string& text)
|
|||||||
{
|
{
|
||||||
++_counter;
|
++_counter;
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< text
|
<< text
|
||||||
@@ -426,7 +449,8 @@ void UnitTest::skip (const std::string& text)
|
|||||||
{
|
{
|
||||||
++_counter;
|
++_counter;
|
||||||
++_skipped;
|
++_skipped;
|
||||||
std::cout << "skip "
|
std::cout << yellow ("skip")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< text
|
<< 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ public:
|
|||||||
void fail (const std::string&);
|
void fail (const std::string&);
|
||||||
void skip (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:
|
private:
|
||||||
int _planned;
|
int _planned;
|
||||||
int _counter;
|
int _counter;
|
||||||
|
|||||||
Reference in New Issue
Block a user