1
0
Fork 0

TestSuite: CTest support for running each test suite as a separate ctest.

The --ctest command line option has also been added to allow for a simplified
output from the test suite more suitable for the ctest verbose output.
This commit is contained in:
Edward d'Auvergne 2018-03-12 11:43:24 +01:00
parent d63211409c
commit f8e6295272
8 changed files with 49 additions and 11 deletions

View file

@ -46,6 +46,22 @@ else()
message(STATUS "CppUnit: Linking to the system supplied CppUnit library")
endif()
#-----------------------------------------------------------------------------
# Set up all test suites as CTests.
# System test suites.
# Unit test suites.
add_test(FlightplanUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u FlightplanTests)
add_test(MktimeUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u MktimeTests)
add_test(NasalSysUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u NasalSysTests)
# GUI test suites.
# Simgear unit test suites.
add_test(MathGeodesySimgearUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -m MathGeodesyTests)
add_test(SimgearPropsSimgearUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -m SimgearPropsTests)
#-----------------------------------------------------------------------------
# From here on, this is a modified copy of src/Main/CMakeLists.txt. This is
# designed to have a minimal diff so that this can be updated together with the

View file

@ -79,6 +79,10 @@ void fgCompilerOutputter::printFailureReport()
// Custom printouts for each failed test.
printFailuresList();
// CTest output (nothing).
if (ctest_output)
return;
// A summary with timing info.
printSuiteStats();
@ -134,6 +138,10 @@ void fgCompilerOutputter::printSuiteStats()
// Print a summary after a successful run of the test suite.
void fgCompilerOutputter::printSuccess()
{
// CTest output (nothing).
if (ctest_output)
return;
// A summary with timing info.
printSuiteStats();

View file

@ -37,12 +37,14 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
std::vector<TestIOCapt> *capt,
const clock_t *clock,
CppUnit::OStream &stream,
bool ctest = false,
const std::string &locationFormat = CPPUNIT_COMPILER_LOCATION_FORMAT)
: CppUnit::CompilerOutputter(result, stream, locationFormat)
, io_capt(capt)
, fg_result(result)
, fg_stream(stream)
, suite_timer(clock)
, ctest_output(ctest)
{
}
@ -72,6 +74,9 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
// The test suite time, in clock ticks.
const clock_t *suite_timer;
// Output control.
bool ctest_output;
// Simgear logstream IO printout.
void printIOStreamMessages(const char *heading, std::string messages, bool empty);
void printIOStreamMessages(const char *heading, std::string messages) {printIOStreamMessages(heading, messages, false);}

View file

@ -54,7 +54,7 @@ void fgTestListener::endTest(CppUnit::Test *test)
cerr << '.';
// Verbose output.
if (verbose) {
if (verbose || ctest_output) {
// Test timing.
float time = ((float)(clock()-m_time))/CLOCKS_PER_SEC;
char buffer[100];

View file

@ -77,6 +77,7 @@ class fgTestListener : public CppUnit::TestListener
// Output settings.
bool verbose;
bool ctest_output;
protected:
// The original IO streams.

View file

@ -29,13 +29,14 @@
// Execute all test suites for the given test category.
int testRunner(const std::string& title, char *subset, bool verbose)
int testRunner(const std::string& title, char *subset, bool verbose, bool ctest_output)
{
// Declarations.
CppUnit::TextTestRunner runner;
// Print out a title.
printTitle(std::cerr, title);
if (!ctest_output)
printTitle(std::cerr, title);
// Get all tests.
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(title).makeTest());
@ -45,9 +46,10 @@ int testRunner(const std::string& title, char *subset, bool verbose)
testListener = new fgTestListener;
runner.eventManager().addListener(testListener);
testListener->verbose = verbose;
testListener->ctest_output = ctest_output;
// Set the test suite output IO stream.
runner.setOutputter(new fgCompilerOutputter(&runner.result(), &testListener->io_capt, &testListener->sum_time, std::cerr));
runner.setOutputter(new fgCompilerOutputter(&runner.result(), &testListener->io_capt, &testListener->sum_time, std::cerr, ctest_output));
// 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);
int testRunner(const std::string&, char*, 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, help=false;
bool verbose=false, ctest_output=false, help=false;
char *subset_system=NULL, *subset_unit=NULL, *subset_gui=NULL, *subset_simgear=NULL;
char firstchar;
@ -120,6 +120,10 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
verbose = true;
// CTest suitable output.
} else if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--ctest") == 0) {
ctest_output = true;
// Help.
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
help = true;
@ -149,6 +153,7 @@ int main(int argc, char **argv)
std::cout << " Verbosity options:" << std::endl;
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.flush();
return 0;
}
@ -167,16 +172,17 @@ int main(int argc, char **argv)
// Execute each of the test suite categories.
if (run_system)
status_system = testRunner("System tests", subset_system, verbose);
status_system = testRunner("System tests", subset_system, verbose, ctest_output);
if (run_unit)
status_unit = testRunner("Unit tests", subset_unit, verbose);
status_unit = testRunner("Unit tests", subset_unit, verbose, ctest_output);
if (run_gui)
status_gui = testRunner("GUI tests", subset_gui, verbose);
status_gui = testRunner("GUI tests", subset_gui, verbose, ctest_output);
if (run_simgear)
status_simgear = testRunner("Simgear unit tests", subset_simgear, verbose);
status_simgear = testRunner("Simgear unit tests", subset_simgear, verbose, ctest_output);
// Summary printout.
summary(cerr, status_system, status_unit, status_gui, status_simgear);
if (!ctest_output)
summary(cerr, status_system, status_unit, status_gui, status_simgear);
// Deactivate the logging.
stopLogging();