1
0
Fork 0

TestSuite: Added a debugging command line option.

This is to enable full output from passing tests to help with debugging.
This commit is contained in:
Edward d'Auvergne 2018-03-12 16:43:24 +01:00
parent f8e6295272
commit 0030f655e0
7 changed files with 63 additions and 29 deletions

View file

@ -54,6 +54,10 @@ void fgCompilerOutputter::printFailureDetail(CppUnit::TestFailure *failure)
fg_stream << (failure->isError() ? "Error" : "Assertion") << ": ";
printFailureLocation(failure->sourceLine());
printFailureMessage(failure);
fg_stream.flush();
if (debug)
return;
// The captured IO for this test.
test_iter = find_if(io_capt->begin(), io_capt->end(), matchTestName(failure->failedTestName()));

View file

@ -38,6 +38,7 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
const clock_t *clock,
CppUnit::OStream &stream,
bool ctest = false,
bool debug = false,
const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT)
: CppUnit::CompilerOutputter(result, stream, locationFormat)
, io_capt(capt)
@ -45,6 +46,7 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
, fg_stream(stream)
, suite_timer(clock)
, ctest_output(ctest)
, debug(debug)
{
}
@ -76,6 +78,7 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
// Output control.
bool ctest_output;
bool debug;
// Simgear logstream IO printout.
void printIOStreamMessages(const char *heading, std::string messages, bool empty);

View file

@ -44,8 +44,14 @@ void fgTestListener::endTest(CppUnit::Test *test)
sum_time += clock() - m_time;
// Restore the IO streams.
if (!debug) {
cout.rdbuf(orig_cout);
cerr.rdbuf(orig_cerr);
}
// Debugging output.
if (debug)
cerr << string(WIDTH_DIVIDER, '-') << endl;
// Per-test single character status feedback.
if (m_failure)
@ -54,7 +60,7 @@ void fgTestListener::endTest(CppUnit::Test *test)
cerr << '.';
// Verbose output.
if (verbose || ctest_output) {
if (verbose || ctest_output || debug) {
// Test timing.
float time = ((float)(clock()-m_time))/CLOCKS_PER_SEC;
char buffer[100];
@ -72,7 +78,7 @@ void fgTestListener::endTest(CppUnit::Test *test)
cerr.flush();
// Store the captured IO for any failed tests.
if (m_failure) {
if (m_failure && !debug) {
// Set up the data structure.
TestIOCapt test_io;
test_io.name = test->getName();
@ -98,6 +104,8 @@ void fgTestListener::endTest(CppUnit::Test *test)
// Override the base class function to capture IO streams.
void fgTestListener::startTest(CppUnit::Test *test)
{
// IO capture.
if (!debug) {
// Clear the simgear logstream buffers.
capturedIO &obj = getIOstreams();
obj.sg_bulk.str("");
@ -116,6 +124,12 @@ void fgTestListener::startTest(CppUnit::Test *test)
cout.rdbuf(capt.rdbuf());
cerr.rdbuf(capt.rdbuf());
// Debugging output.
} else {
cerr << string(WIDTH_DIVIDER, '=') << endl;
cerr << "Starting test: " << test->getName() << endl;
cerr << string(WIDTH_DIVIDER, '-') << endl;
}
// Reset the test status.
m_failure = false;
m_error = false;

View file

@ -25,6 +25,8 @@
#include <time.h>
#include <vector>
#include "formatting.hxx"
// Data structure for holding the captured IO for a failed test.
struct TestIOCapt {
@ -78,6 +80,7 @@ class fgTestListener : public CppUnit::TestListener
// Output settings.
bool verbose;
bool ctest_output;
bool debug;
protected:
// The original IO streams.

View file

@ -29,7 +29,7 @@
// Execute all test suites for the given test category.
int testRunner(const std::string& title, char *subset, bool verbose, bool ctest_output)
int testRunner(const std::string& title, char *subset, bool verbose, bool ctest_output, bool debug)
{
// Declarations.
CppUnit::TextTestRunner runner;
@ -47,9 +47,10 @@ int testRunner(const std::string& title, char *subset, bool verbose, bool ctest_
runner.eventManager().addListener(testListener);
testListener->verbose = verbose;
testListener->ctest_output = ctest_output;
testListener->debug = debug;
// Set the test suite output IO stream.
runner.setOutputter(new fgCompilerOutputter(&runner.result(), &testListener->io_capt, &testListener->sum_time, std::cerr, ctest_output));
runner.setOutputter(new fgCompilerOutputter(&runner.result(), &testListener->io_capt, &testListener->sum_time, std::cerr, ctest_output, debug));
// Execute the tests.
if (subset == NULL)

View file

@ -23,7 +23,7 @@
// Execute all test suites for the given test category.
int testRunner(const std::string&, char*, bool, bool);
int testRunner(const std::string&, char*, bool, bool, bool);
#endif // _FG_TEST_RUNNER_HXX

View file

@ -82,7 +82,7 @@ int main(int argc, char **argv)
// Declarations.
int status_gui=-1, status_simgear=-1, status_system=-1, status_unit=-1;
bool run_system=false, run_unit=false, run_gui=false, run_simgear=false;
bool verbose=false, ctest_output=false, help=false;
bool verbose=false, ctest_output=false, debug=false, help=false;
char *subset_system=NULL, *subset_unit=NULL, *subset_gui=NULL, *subset_simgear=NULL;
char firstchar;
@ -124,6 +124,10 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--ctest") == 0) {
ctest_output = true;
// Debug output.
} else if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--debug") == 0) {
debug = true;
// Help.
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
help = true;
@ -154,6 +158,7 @@ int main(int argc, char **argv)
std::cout << " -v, --verbose verbose output including names and timings for all" << std::endl;
std::cout << " tests." << std::endl;
std::cout << " -c, --ctest simplified output suitable for running via CTest." << std::endl;
std::cout << " -d, --debug disable IO capture for debugging (super verbose output)." << std::endl;
std::cout.flush();
return 0;
}
@ -168,23 +173,27 @@ int main(int argc, char **argv)
// Set up logging.
sglog().setDeveloperMode(true);
if (debug)
sglog().setLogLevels(SG_ALL, SG_BULK);
else
setupLogging();
// Execute each of the test suite categories.
if (run_system)
status_system = testRunner("System tests", subset_system, verbose, ctest_output);
status_system = testRunner("System tests", subset_system, verbose, ctest_output, debug);
if (run_unit)
status_unit = testRunner("Unit tests", subset_unit, verbose, ctest_output);
status_unit = testRunner("Unit tests", subset_unit, verbose, ctest_output, debug);
if (run_gui)
status_gui = testRunner("GUI tests", subset_gui, verbose, ctest_output);
status_gui = testRunner("GUI tests", subset_gui, verbose, ctest_output, debug);
if (run_simgear)
status_simgear = testRunner("Simgear unit tests", subset_simgear, verbose, ctest_output);
status_simgear = testRunner("Simgear unit tests", subset_simgear, verbose, ctest_output, debug);
// Summary printout.
if (!ctest_output)
summary(cerr, status_system, status_unit, status_gui, status_simgear);
// Deactivate the logging.
if (!debug)
stopLogging();
// Failure.