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") << ": "; fg_stream << (failure->isError() ? "Error" : "Assertion") << ": ";
printFailureLocation(failure->sourceLine()); printFailureLocation(failure->sourceLine());
printFailureMessage(failure); printFailureMessage(failure);
fg_stream.flush();
if (debug)
return;
// The captured IO for this test. // The captured IO for this test.
test_iter = find_if(io_capt->begin(), io_capt->end(), matchTestName(failure->failedTestName())); 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, const clock_t *clock,
CppUnit::OStream &stream, CppUnit::OStream &stream,
bool ctest = false, bool ctest = false,
bool debug = false,
const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT) const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT)
: CppUnit::CompilerOutputter(result, stream, locationFormat) : CppUnit::CompilerOutputter(result, stream, locationFormat)
, io_capt(capt) , io_capt(capt)
@ -45,6 +46,7 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
, fg_stream(stream) , fg_stream(stream)
, suite_timer(clock) , suite_timer(clock)
, ctest_output(ctest) , ctest_output(ctest)
, debug(debug)
{ {
} }
@ -76,6 +78,7 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
// Output control. // Output control.
bool ctest_output; bool ctest_output;
bool debug;
// Simgear logstream IO printout. // Simgear logstream IO printout.
void printIOStreamMessages(const char *heading, std::string messages, bool empty); 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; sum_time += clock() - m_time;
// Restore the IO streams. // Restore the IO streams.
if (!debug) {
cout.rdbuf(orig_cout); cout.rdbuf(orig_cout);
cerr.rdbuf(orig_cerr); cerr.rdbuf(orig_cerr);
}
// Debugging output.
if (debug)
cerr << string(WIDTH_DIVIDER, '-') << endl;
// Per-test single character status feedback. // Per-test single character status feedback.
if (m_failure) if (m_failure)
@ -54,7 +60,7 @@ void fgTestListener::endTest(CppUnit::Test *test)
cerr << '.'; cerr << '.';
// Verbose output. // Verbose output.
if (verbose || ctest_output) { if (verbose || ctest_output || debug) {
// Test timing. // Test timing.
float time = ((float)(clock()-m_time))/CLOCKS_PER_SEC; float time = ((float)(clock()-m_time))/CLOCKS_PER_SEC;
char buffer[100]; char buffer[100];
@ -72,7 +78,7 @@ void fgTestListener::endTest(CppUnit::Test *test)
cerr.flush(); cerr.flush();
// Store the captured IO for any failed tests. // Store the captured IO for any failed tests.
if (m_failure) { if (m_failure && !debug) {
// Set up the data structure. // Set up the data structure.
TestIOCapt test_io; TestIOCapt test_io;
test_io.name = test->getName(); test_io.name = test->getName();
@ -98,6 +104,8 @@ void fgTestListener::endTest(CppUnit::Test *test)
// Override the base class function to capture IO streams. // Override the base class function to capture IO streams.
void fgTestListener::startTest(CppUnit::Test *test) void fgTestListener::startTest(CppUnit::Test *test)
{ {
// IO capture.
if (!debug) {
// Clear the simgear logstream buffers. // Clear the simgear logstream buffers.
capturedIO &obj = getIOstreams(); capturedIO &obj = getIOstreams();
obj.sg_bulk.str(""); obj.sg_bulk.str("");
@ -116,6 +124,12 @@ void fgTestListener::startTest(CppUnit::Test *test)
cout.rdbuf(capt.rdbuf()); cout.rdbuf(capt.rdbuf());
cerr.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. // Reset the test status.
m_failure = false; m_failure = false;
m_error = false; m_error = false;

View file

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

View file

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

View file

@ -23,7 +23,7 @@
// Execute all test suites for the given test category. // 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 #endif // _FG_TEST_RUNNER_HXX

View file

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