add initial bulk run from pre-commit over all files

This commit is contained in:
Felix Schurk
2024-07-29 22:34:51 +02:00
parent 665aeeef61
commit 93356b39c3
418 changed files with 21354 additions and 23858 deletions

View File

@@ -24,75 +24,46 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <test.h>
#include <unistd.h>
#include <iomanip>
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
UnitTest::UnitTest ()
: _planned (0)
, _counter (0)
, _passed (0)
, _failed (0)
, _skipped (0)
{
}
UnitTest::UnitTest() : _planned(0), _counter(0), _passed(0), _failed(0), _skipped(0) {}
///////////////////////////////////////////////////////////////////////////////
UnitTest::UnitTest (int planned)
: _planned (planned)
, _counter (0)
, _passed (0)
, _failed (0)
, _skipped (0)
{
UnitTest::UnitTest(int planned)
: _planned(planned), _counter(0), _passed(0), _failed(0), _skipped(0) {
std::cout << "1.." << _planned << '\n';
}
///////////////////////////////////////////////////////////////////////////////
UnitTest::~UnitTest ()
{
UnitTest::~UnitTest() {
float percentPassed = 0.0;
if (_planned > 0)
percentPassed = (100.0 * _passed) / std::max (_planned, _passed + _failed + _skipped);
percentPassed = (100.0 * _passed) / std::max(_planned, _passed + _failed + _skipped);
if (_counter < _planned)
{
std::cout << "# Only "
<< _counter
<< " tests, out of a planned "
<< _planned
<< " were run.\n";
if (_counter < _planned) {
std::cout << "# Only " << _counter << " tests, out of a planned " << _planned << " were run.\n";
_skipped += _planned - _counter;
}
else if (_counter > _planned)
std::cout << "# "
<< _counter
<< " tests were run, but only "
<< _planned
<< " were planned.\n";
std::cout << "# " << _counter << " tests were run, but only " << _planned << " were planned.\n";
std::cout << "# "
<< _passed
<< " passed, "
<< _failed
<< " failed, "
<< _skipped
<< " skipped. "
<< std::setprecision (3) << percentPassed
<< "% passed.\n";
exit (_failed > 0);
std::cout << "# " << _passed << " passed, " << _failed << " failed, " << _skipped << " skipped. "
<< std::setprecision(3) << percentPassed << "% passed.\n";
exit(_failed > 0);
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::plan (int planned)
{
void UnitTest::plan(int planned) {
_planned = planned;
_counter = 0;
_passed = 0;
@@ -103,429 +74,225 @@ void UnitTest::plan (int planned)
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::planMore (int extra)
{
void UnitTest::planMore(int extra) {
_planned += extra;
std::cout << "1.." << _planned << '\n';
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::ok (bool expression, const std::string& name, bool expfail /* = false */)
{
void UnitTest::ok(bool expression, const std::string& name, bool expfail /* = false */) {
++_counter;
bool success = expression;
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::notok (bool expression, const std::string& name, bool expfail /* = false */)
{
void UnitTest::notok(bool expression, const std::string& name, bool expfail /* = false */) {
++_counter;
bool success = not expression;
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (bool actual, bool expected, const std::string& name, bool expfail /* = false */)
{
void UnitTest::is(bool actual, bool expected, const std::string& name, bool expfail /* = false */) {
++_counter;
bool success = (actual == expected);
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: "
<< expected
<< "\n# got: "
<< actual
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: " << expected
<< "\n# got: " << actual << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (size_t actual, size_t expected, const std::string& name, bool expfail /* = false */)
{
void UnitTest::is(size_t actual, size_t expected, const std::string& name,
bool expfail /* = false */) {
++_counter;
bool success = (actual == expected);
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: "
<< expected
<< "\n# got: "
<< actual
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: " << expected
<< "\n# got: " << actual << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (int actual, int expected, const std::string& name, bool expfail /* = false */)
{
void UnitTest::is(int actual, int expected, const std::string& name, bool expfail /* = false */) {
++_counter;
bool success = (actual == expected);
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: "
<< expected
<< "\n# got: "
<< actual
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: " << expected
<< "\n# got: " << actual << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (double actual, double expected, const std::string& name, bool expfail /* = false */)
{
void UnitTest::is(double actual, double expected, const std::string& name,
bool expfail /* = false */) {
++_counter;
bool success = (actual == expected);
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: "
<< expected
<< "\n# got: "
<< actual
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: " << expected
<< "\n# got: " << actual << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (double actual, double expected, double tolerance, const std::string& name, bool expfail /* = false */)
{
void UnitTest::is(double actual, double expected, double tolerance, const std::string& name,
bool expfail /* = false */) {
++_counter;
bool success = (fabs (actual - expected) <= tolerance);
bool success = (fabs(actual - expected) <= tolerance);
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: "
<< expected
<< "\n# got: "
<< actual
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: " << expected
<< "\n# got: " << actual << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (unsigned char actual, unsigned char expected, const std::string& name, bool expfail /* = false */)
{
void UnitTest::is(unsigned char actual, unsigned char expected, const std::string& name,
bool expfail /* = false */) {
++_counter;
bool success = (actual == expected);
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: "
<< expected
<< "\n# got: "
<< actual
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: " << expected
<< "\n# got: " << actual << '\n';
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (
const std::string& actual,
const std::string& expected,
const std::string& name,
bool expfail /* = false */)
{
void UnitTest::is(const std::string& actual, const std::string& expected, const std::string& name,
bool expfail /* = false */) {
++_counter;
bool success = (actual == expected);
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: '"
<< expected
<< "'"
<< "\n# got: '"
<< actual
<< "'\n";
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: '"
<< expected << "'"
<< "\n# got: '" << actual << "'\n";
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (
const char* actual,
const char* expected,
const std::string& name,
bool expfail /* = false */)
{
void UnitTest::is(const char* actual, const char* expected, const std::string& name,
bool expfail /* = false */) {
++_counter;
bool success = (! strcmp (actual, expected));
bool success = (!strcmp(actual, expected));
if (success and ! expfail)
{
if (success and !expfail) {
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< name
<< '\n';
}
else
{
if (success == expfail)
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "")
<< "\n# expected: '"
<< expected
<< "'"
<< "\n# got: '"
<< actual
<< "'\n";
std::cout << green("ok") << " " << _counter << " - " << name << '\n';
} else {
if (success == expfail) ++_failed;
std::cout << red("not ok") << " " << _counter << " - " << name
<< (expfail ? (success ? " # FIXED" : " # TODO") : "") << "\n# expected: '"
<< expected << "'"
<< "\n# got: '" << actual << "'\n";
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::diag (const std::string& text)
{
auto start = text.find_first_not_of (" \t\n\r\f");
auto end = text.find_last_not_of (" \t\n\r\f");
if (start != std::string::npos &&
end != std::string::npos)
std::cout << "# " << text.substr (start, end - start + 1) << '\n';
void UnitTest::diag(const std::string& text) {
auto start = text.find_first_not_of(" \t\n\r\f");
auto end = text.find_last_not_of(" \t\n\r\f");
if (start != std::string::npos && end != std::string::npos)
std::cout << "# " << text.substr(start, end - start + 1) << '\n';
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::pass (const std::string& text)
{
void UnitTest::pass(const std::string& text) {
++_counter;
++_passed;
std::cout << green ("ok")
<< " "
<< _counter
<< " - "
<< text
<< '\n';
std::cout << green("ok") << " " << _counter << " - " << text << '\n';
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::fail (const std::string& text)
{
void UnitTest::fail(const std::string& text) {
++_counter;
++_failed;
std::cout << red ("not ok")
<< " "
<< _counter
<< " - "
<< text
<< '\n';
std::cout << red("not ok") << " " << _counter << " - " << text << '\n';
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::skip (const std::string& text)
{
void UnitTest::skip(const std::string& text) {
++_counter;
++_skipped;
std::cout << yellow ("ok")
<< " "
<< _counter
<< " - "
<< text
<< " # skip"
<< '\n';
std::cout << yellow("ok") << " " << _counter << " - " << text << " # skip" << '\n';
}
///////////////////////////////////////////////////////////////////////////////
std::string UnitTest::red (const std::string& input)
{
if (isatty (fileno (stdout)))
return std::string ("\033[31m" + input + "\033[0m");
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");
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");
std::string UnitTest::yellow(const std::string& input) {
if (isatty(fileno(stdout))) return std::string("\033[33m" + input + "\033[0m");
return input;
}