FOSSology  4.7.1
Open Source License Compliance by Open Source Software
run_tests.cc
Go to the documentation of this file.
1 /*
2  SPDX-License-Identifier: GPL-2.0-only
3  Author: Dietmar Helmut Leher <helmut.leher.ext@vaillant-group.com>
4  SPDX-FileCopyrightText: © 2026 Vaillant GmbH
5 */
10 #include <cppunit/CompilerOutputter.h>
11 #include <cppunit/TestResult.h>
12 #include <cppunit/TestResultCollector.h>
13 #include <cppunit/TestRunner.h>
14 #include <cppunit/XmlOutputter.h>
15 #include <cppunit/extensions/TestFactoryRegistry.h>
16 
17 #ifdef WIN32
18 #include <cppunit/TextTestProgressListener.h>
19 #else
20 #include <cppunit/BriefTestProgressListener.h>
21 #endif
22 #include <fstream>
23 #include <stdexcept>
24 
25 
26 int
27 main( int argc, char* argv[] )
28 {
29  std::string testPath = (argc > 1) ? std::string(argv[1]) : std::string("");
30 
31  CPPUNIT_NS::TestResult controller;
32 
33  CPPUNIT_NS::TestResultCollector result;
34  controller.addListener( &result );
35 
36 #ifdef WIN32
37  CPPUNIT_NS::TextTestProgressListener progress;
38 #else
39  CPPUNIT_NS::BriefTestProgressListener progress;
40 #endif
41  controller.addListener( &progress );
42 
43  CPPUNIT_NS::TestRunner runner;
44  runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
45  try
46  {
47  CPPUNIT_NS::stdCOut() << "Running " << testPath;
48  runner.run( controller, testPath );
49 
50  CPPUNIT_NS::stdCOut() << "\n";
51 
52  CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
53  outputter.write();
54  }
55  catch ( std::invalid_argument &e )
56  {
57  CPPUNIT_NS::stdCOut() << "\n" << "ERROR: " << e.what() << "\n";
58  return 1;
59  }
60 
61  return result.wasSuccessful() ? 0 : 1;
62 }
int main(int argc, char *argv[])
Definition: run_tests.cc:29