Further code cleanups and documentation.
- Coverity defects. - Documentation.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
///
|
||||
/// \file Test.cc
|
||||
/// \file src/sctest/Assert.cc
|
||||
/// \author K. Isom <kyle@imap.cc>
|
||||
/// \date 2023-10-09
|
||||
/// \brief Tooling to assist in building test programs..
|
||||
/// \brief Assertion tooling useful in building test programs.
|
||||
///
|
||||
/// Copyright 2023 K. Isom <kyle@imap.cc>
|
||||
///
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
///
|
||||
/// \file Exceptions.cc
|
||||
/// \file src/test/Exceptions.cc
|
||||
/// \author K. Isom <kyle@imap.cc>
|
||||
/// \date 2023-10-10
|
||||
/// \brief Custom exceptions used in writing test programs.
|
||||
@@ -26,7 +26,7 @@
|
||||
namespace sctest {
|
||||
|
||||
|
||||
AssertionFailed::AssertionFailed(std::string message) : msg(message) {}
|
||||
AssertionFailed::AssertionFailed(std::string message) : msg(std::move(message)) {}
|
||||
|
||||
|
||||
const char *
|
||||
|
||||
@@ -45,6 +45,13 @@ Report::Failing() const
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
Report::Passing() const
|
||||
{
|
||||
return this->passed;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
Report::Total() const
|
||||
{
|
||||
@@ -59,6 +66,13 @@ Report::Failed()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Report::Passed()
|
||||
{
|
||||
this->passed++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Report::AddTest(size_t testCount)
|
||||
{
|
||||
@@ -71,6 +85,7 @@ Report::Reset(size_t testCount)
|
||||
{
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
this->total = testCount;
|
||||
this->passed = 0;
|
||||
this->failing = 0;
|
||||
|
||||
this->Start();
|
||||
@@ -105,13 +120,18 @@ operator<<(std::ostream &os, const Report &report)
|
||||
{
|
||||
auto elapsed = report.Elapsed();
|
||||
|
||||
os << report.Total() - report.Failing() << "/"
|
||||
os << report.Passing() << "/"
|
||||
<< report.Total() << " tests passed in "
|
||||
<< std::setw(3) << elapsed.count() << "ms";
|
||||
|
||||
auto failed = report.Failing();
|
||||
if (failed > 0) {
|
||||
os << " (" << failed << " tests failed)";
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end namespace sctest
|
||||
} // end namespace sctest
|
||||
|
||||
@@ -53,7 +53,7 @@ SimpleSuite::Silence()
|
||||
void
|
||||
SimpleSuite::AddTest(std::string name, std::function<bool()> test)
|
||||
{
|
||||
const UnitTest test_case = {std::move(name), test};
|
||||
const UnitTest test_case = {std::move(name), std::move(test), true};
|
||||
tests.push_back(test_case);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ SimpleSuite::AddTest(std::string name, std::function<bool()> test)
|
||||
void
|
||||
SimpleSuite::AddFailingTest(std::string name, std::function<bool()> test)
|
||||
{
|
||||
// auto ntest = [&test]() { return !test(); };
|
||||
const UnitTest test_case = {std::move(name), [&test]() { return !test(); }};
|
||||
const UnitTest test_case = {std::move(name), test, false};
|
||||
tests.push_back(test_case);
|
||||
}
|
||||
|
||||
@@ -87,14 +86,19 @@ SimpleSuite::Run()
|
||||
<< testCase.name << ": ";
|
||||
}
|
||||
|
||||
this->hasPassed = testCase.test();
|
||||
this->hasPassed = (testCase.test() == testCase.expect);
|
||||
if (this->hasPassed) {
|
||||
report.Passed();
|
||||
} else {
|
||||
report.Failed();
|
||||
}
|
||||
|
||||
if (quiet) { continue; }
|
||||
|
||||
if (this->hasPassed) {
|
||||
std::cout << "[PASS]";
|
||||
} else {
|
||||
std::cout << "[FAIL]";
|
||||
report.Failed();
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
@@ -142,4 +146,4 @@ operator<<(std::ostream &os, SimpleSuite &suite)
|
||||
}
|
||||
|
||||
|
||||
} // end namespace sctest
|
||||
} // end namespace sctest
|
||||
|
||||
Reference in New Issue
Block a user