| 1 | /* |
| 2 | * Copyright (C) 2016-2018 Edward d'Auvergne |
| 3 | * |
| 4 | * This file is part of the program FlightGear. |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <cppunit/TestResult.h> |
| 22 | #include <cppunit/TestResultCollector.h> |
| 23 | #include <cppunit/TextTestRunner.h> |
| 24 | #include <cppunit/extensions/TestFactoryRegistry.h> |
| 25 | |
| 26 | #include "fgCompilerOutputter.hxx" |
| 27 | #include "fgTestListener.hxx" |
| 28 | #include "formatting.hxx" |
| 29 | |
| 30 | |
| 31 | // Execute all test suites for the given test category. |
| 32 | int testRunner(const std::string& type, const std::string& title, char *subset, bool timings, bool ctest_output, bool debug) |
| 33 | { |
| 34 | // Declarations. |
| 35 | CppUnit::TextTestRunner runner; |
| 36 | |
| 37 | // Print out a title. |
| 38 | if (!ctest_output) |
| 39 | printTitle(std::cerr, title); |
| 40 | |
| 41 | // Get all tests. |
| 42 | runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(type).makeTest()); |
| 43 | |
| 44 | // Set up the test listener. |
| 45 | fgTestListener *testListener; |
| 46 | testListener = new fgTestListener; |
| 47 | runner.eventManager().addListener(testListener); |
| 48 | testListener->timings = timings; |
| 49 | testListener->ctest_output = ctest_output; |
| 50 | testListener->debug = debug; |
| 51 | |
| 52 | // Set the test suite output IO stream. |
| 53 | runner.setOutputter(new fgCompilerOutputter(&runner.result(), &testListener->io_capt, &testListener->sum_time, std::cerr, ctest_output, debug)); |
| 54 | |
| 55 | // Execute the tests. |
| 56 | if (subset == NULL) |
| 57 | runner.run("", false, true, false); |
| 58 | else { |
| 59 | std::stringstream testStream(subset); |
| 60 | std::string testName; |
| 61 | while( testStream.good() ) { |
| 62 | getline( testStream, testName, ',' ); |
| 63 | runner.run(testName, false, true, false); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Clean up. |
| 68 | delete testListener; |
| 69 | |
| 70 | // Return the status of the tests. |
| 71 | CppUnit::TestResultCollector &status = runner.result(); |
| 72 | return status.testFailuresTotal(); |
| 73 | } |