summaryrefslogtreecommitdiff
path: root/c++/cppunit-subunit-1.10.2.patch
blob: b3c353b4878a74f2455379de33a79a1e99104472 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
diff -u cppunit-1.10.2/src/cppunit/Makefile.am cppunit-1.10.2/src/cppunit/Makefile.am
--- cppunit-1.10.2/src/cppunit/Makefile.am
+++ cppunit-1.10.2/src/cppunit/Makefile.am
@@ -28,6 +28,7 @@
   ProtectorChain.cpp \
   SourceLine.cpp \
   StringTools.cpp \
+  SubunitTestProgressListener.cpp \
   SynchronizedObject.cpp \
   Test.cpp \
   TestAssert.cpp \
@@ -74,0 +76,2 @@
+
+LIBRARY_LIBADD = $(LIBS)
--- cppunit-1.10.2.orig/src/cppunit/SubunitTestProgressListener.cpp
+++ cppunit-1.10.2/src/cppunit/SubunitTestProgressListener.cpp
@@ -0,0 +1,50 @@
+#include <cppunit/Exception.h>
+#include <cppunit/Test.h>
+#include <cppunit/TestFailure.h>
+#include <cppunit/SubunitTestProgressListener.h>
+#include <cppunit/TextOutputter.h>
+#include <iostream>
+
+#include "config.h"
+#ifdef HAVE_LIBSUBUNIT
+#include <subunit/child.h>
+
+
+CPPUNIT_NS_BEGIN
+
+
+void 
+SubunitTestProgressListener::startTest( Test *test )
+{
+  subunit_test_start(test->getName().c_str());
+  last_test_failed = false;
+}
+
+void 
+SubunitTestProgressListener::addFailure( const TestFailure &failure )
+{
+  std::ostringstream capture_stream;
+  TextOutputter outputter(NULL, capture_stream);
+  outputter.printFailureLocation(failure.sourceLine());
+  outputter.printFailureDetail(failure.thrownException());
+
+  if (failure.isError())
+      subunit_test_error(failure.failedTestName().c_str(),
+        		 capture_stream.str().c_str());
+  else
+      subunit_test_fail(failure.failedTestName().c_str(),
+                        capture_stream.str().c_str());
+  last_test_failed = true;
+}
+
+void 
+SubunitTestProgressListener::endTest( Test *test)
+{
+  if (!last_test_failed)
+      subunit_test_pass(test->getName().c_str());
+}
+
+
+CPPUNIT_NS_END
+
+#endif
--- cppunit-1.10.2.orig/configure.in
+++ cppunit-1.10.2/configure.in
@@ -65,6 +65,8 @@
 # check for doxygen
 BB_ENABLE_DOXYGEN
 
+# check for subunit
+AC_CHECK_LIB(subunit, subunit_test_start)
 
 # Check for headers
 # Note that the fourth argument to AC_CHECK_HEADERS is non-empty to force
--- cppunit-1.10.2.orig/include/cppunit/Makefile.am
+++ cppunit-1.10.2/include/cppunit/Makefile.am
@@ -15,6 +15,7 @@
 	Portability.h \
 	Protector.h \
 	SourceLine.h \
+	SubunitTestProgressListener.h \
 	SynchronizedObject.h \
 	Test.h \
 	TestAssert.h \
only in patch2:
unchanged:
--- cppunit-1.10.2.orig/include/cppunit/SubunitTestProgressListener.h
+++ cppunit-1.10.2/include/cppunit/SubunitTestProgressListener.h
@@ -0,0 +1,41 @@
+#ifndef CPPUNIT_SUBUNITTESTPROGRESSLISTENER_H
+#define CPPUNIT_SUBUNITTESTPROGRESSLISTENER_H
+
+#include <cppunit/TestListener.h>
+
+
+CPPUNIT_NS_BEGIN
+
+
+/*! 
+ * \brief TestListener that outputs subunit
+ * (http://www.robertcollins.net/unittest/subunit) compatible output.
+ * \ingroup TrackingTestExecution
+ */
+class CPPUNIT_API SubunitTestProgressListener : public TestListener
+{
+public:
+ 
+  SubunitTestProgressListener() {}
+  
+  void startTest( Test *test );
+
+  void addFailure( const TestFailure &failure );
+
+  void endTest( Test *test );
+
+private:
+  /// Prevents the use of the copy constructor.
+  SubunitTestProgressListener( const SubunitTestProgressListener &copy );
+
+  /// Prevents the use of the copy operator.
+  void operator =( const SubunitTestProgressListener &copy );
+
+private:
+  int last_test_failed;
+};
+
+
+CPPUNIT_NS_END
+
+#endif  // CPPUNIT_SUBUNITTESTPROGRESSLISTENER_H