summaryrefslogtreecommitdiff
path: root/examples/cppunittest/CppUnitTestMain.cpp
blob: db44c6a3f7d22aa90f4b4ed08cc985f751158200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunitui/text/TestRunner.h>
#include "CppUnitTestSuite.h"


int 
main( int argc, char* argv[] )
{
  // if command line contains "-selftest" then this is the post build check
  // => the output must be in the compiler error format.
  bool selfTest = (argc > 1)  &&  
                  (std::string("-selftest") == argv[1]);

  CppUnit::TextUi::TestRunner runner;
  runner.addTest( CppUnitTest::suite() );   // Add the top suite to the test runner

  if ( selfTest )
  { // Change the default outputter to a compiler error format outputter
    // The test runner owns the new outputter.
    runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter( 
                                                        &runner.result(),
                                                        std::cerr ) );
  }

  // Run the test and don't wait a key if post build check.
  bool wasSucessful = runner.run( "", !selfTest );

  // Return error code 1 if the one of test failed.
  return wasSucessful ? 0 : 1;
}