| 1 |
# |
| 2 |
# subunit C++ bindings. |
| 3 |
# Copyright (C) 2006 Robert Collins <[email protected]> |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 2 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
# |
| 19 |
|
| 20 |
Currently there are no native C++ bindings for subunit. However the C library |
| 21 |
can be used from C++ safely. A CPPUnit listener is built as part of Subunit to |
| 22 |
allow CPPUnit users to simply get Subunit output. |
| 23 |
|
| 24 |
To use the listener, use pkg-config (or your preferred replacement) to get the |
| 25 |
cflags and link settings from libcppunit_subunit.pc. |
| 26 |
|
| 27 |
In your test driver main, use SubunitTestProgressListener, as shown in this |
| 28 |
example main:: |
| 29 |
|
| 30 |
{ |
| 31 |
// Create the event manager and test controller |
| 32 |
CPPUNIT_NS::TestResult controller; |
| 33 |
|
| 34 |
// Add a listener that collects test result |
| 35 |
// so we can get the overall status. |
| 36 |
// note this isn't needed for subunit... |
| 37 |
CPPUNIT_NS::TestResultCollector result; |
| 38 |
controller.addListener( &result ); |
| 39 |
|
| 40 |
// Add a listener that print test activity in subunit format. |
| 41 |
CPPUNIT_NS::SubunitTestProgressListener progress; |
| 42 |
controller.addListener( &progress ); |
| 43 |
|
| 44 |
// Add the top suite to the test runner |
| 45 |
CPPUNIT_NS::TestRunner runner; |
| 46 |
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); |
| 47 |
runner.run( controller ); |
| 48 |
|
| 49 |
return result.wasSuccessful() ? 0 : 1; |
| 50 |
} |