Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions tests/cppunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@

#include <iostream>

using namespace std;
using namespace CppUtilities;
using namespace CPPUNIT_NS;

/*!
* \brief Prints the names of all child tests of the specified \a test.
*/
void printTestNames(Test *test, Indentation indentation)
void printTestNames(CPPUNIT_NS::Test *test, Indentation indentation)
{
for (int index = 0, count = test->getChildTestCount(); index != count; ++index) {
const auto childTest = test->getChildTestAt(index);
cerr << '\n' << indentation << " - " << childTest->getName();
std::cerr << '\n' << indentation << " - " << childTest->getName();
printTestNames(childTest, indentation + 4);
}
}
Expand All @@ -39,44 +37,44 @@ int main(int argc, char **argv)
}

// list tests
TestFactoryRegistry &registry = TestFactoryRegistry::getRegistry();
CPPUNIT_NS::TestFactoryRegistry &registry = CPPUNIT_NS::TestFactoryRegistry::getRegistry();
if (testApp.onlyListUnits()) {
cerr << "Available tests:";
std::cerr << "Available tests:";
printTestNames(registry.makeTest(), Indentation(0));
cerr << '\n';
std::cerr << '\n';
return 0;
}

// run tests
TextUi::TestRunner runner;
CPPUNIT_NS::TextUi::TestRunner runner;
if (!testApp.unitsSpecified() || testApp.units().empty()) {
// no units specified -> test all
runner.addTest(registry.makeTest());
} else {
// pick specified units from overall test
Test *overallTest = registry.makeTest();
vector<const char *> unavailableUnits;
CPPUNIT_NS::Test *overallTest = registry.makeTest();
std::vector<const char *> unavailableUnits;
for (const char *unit : testApp.units()) {
try {
runner.addTest(overallTest->findTest(unit));
} catch (const invalid_argument &) {
} catch (const std::invalid_argument &) {
unavailableUnits.emplace_back(unit);
}
}
if (!unavailableUnits.empty()) {
cerr << "The following tests specified via --unit are not available:";
std::cerr << "The following tests specified via --unit are not available:";
for (const char *unitName : unavailableUnits) {
cerr << "\n - " << unitName;
std::cerr << "\n - " << unitName;
}
cerr << "\nAvailable tests:";
std::cerr << "\nAvailable tests:";
printTestNames(overallTest, Indentation(0));
cerr << '\n';
std::cerr << '\n';
return -1;
}
}
cerr << EscapeCodes::TextAttribute::Bold << "Executing test cases ..." << EscapeCodes::Phrases::EndFlush;
const auto ok = runner.run(string(), false);
cerr << (ok ? "Tests successful\n" : "Tests failed\n");
std::cerr << EscapeCodes::TextAttribute::Bold << "Executing test cases ..." << EscapeCodes::Phrases::EndFlush;
const auto ok = runner.run(std::string(), false);
std::cerr << (ok ? "Tests successful\n" : "Tests failed\n");
return !ok;
}

Expand Down