mirror of
https://github.com/GothenburgBitFactory/taskshell.git
synced 2025-08-18 15:33:12 +02:00
Tests: Updated test harness
This commit is contained in:
parent
6e8050bd3d
commit
726a1630bf
2 changed files with 83 additions and 24 deletions
102
test/test.cpp
102
test/test.cpp
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -115,7 +117,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 +127,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 +144,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 +154,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 +170,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 +180,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 +200,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 +210,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 +230,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 +240,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 +260,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 +270,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 +290,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 +300,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 +320,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 +330,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 +353,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 +363,8 @@ void UnitTest::is (
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
|
@ -367,7 +387,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 +397,8 @@ void UnitTest::is (
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
std::cout << "not ok "
|
std::cout << red ("not ok")
|
||||||
|
<< " "
|
||||||
<< _counter
|
<< _counter
|
||||||
<< " - "
|
<< " - "
|
||||||
<< name
|
<< name
|
||||||
|
@ -394,7 +416,9 @@ void UnitTest::diag (const std::string& text)
|
||||||
{
|
{
|
||||||
auto start = text.find_first_not_of (" \t\n\r\f");
|
auto start = text.find_first_not_of (" \t\n\r\f");
|
||||||
auto end = text.find_last_not_of (" \t\n\r\f");
|
auto end = text.find_last_not_of (" \t\n\r\f");
|
||||||
std::cout << "# " << text.substr (start, end - start + 1) << "\n";
|
if (start != std::string::npos &&
|
||||||
|
end != std::string::npos)
|
||||||
|
std::cout << "# " << text.substr (start, end - start + 1) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -402,7 +426,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 +439,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 +452,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 +461,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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue