510
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2012 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
507
|
12 |
"{ Package: 'stx:goodies/sunit' }"
|
|
13 |
|
|
14 |
Object subclass:#TestCoverageReporter
|
|
15 |
instanceVariableNames:'packages stream'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'SUnit-Report'
|
|
19 |
!
|
|
20 |
|
|
21 |
!TestCoverageReporter class methodsFor:'documentation'!
|
|
22 |
|
510
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2012 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
507
|
38 |
documentation
|
|
39 |
"
|
510
|
40 |
this is used as a last step in jenkins automated builds.
|
|
41 |
|
507
|
42 |
Currently supported formats are:
|
|
43 |
#xml_cobertura - a cobertura compatible format
|
|
44 |
|
|
45 |
public API entry:
|
|
46 |
|aTestResult|
|
|
47 |
|
|
48 |
InstrumentingCompiler compilePackage:'mypackageID'.
|
|
49 |
InstrumentationContext new run:[
|
|
50 |
aTestResult := aUnitTest suite run.
|
|
51 |
].
|
|
52 |
'testResult.xml' asFilename writingFileDo:[:stream |
|
|
53 |
TestResultReporter report:aTestResult format:#xml_jUnit on:stream.
|
|
54 |
].
|
|
55 |
'testCoverage.xml' asFilename writingFileDo:[:stream |
|
|
56 |
TestCoverageReporter reportPackages:{ 'mypackageID' } format:#xml_cobertura on:stream.
|
|
57 |
].
|
|
58 |
|
|
59 |
[author:]
|
|
60 |
Claus Gittinger
|
|
61 |
|
|
62 |
[see also:]
|
|
63 |
cobertura
|
|
64 |
http://wiki.hudson-ci.org/display/HUDSON/PerfPublisher+Plugin
|
|
65 |
https://raw.github.com/jenkinsci/cobertura-plugin/master/src/test/resources/hudson/plugins/cobertura/coverage-with-data.xml
|
|
66 |
"
|
|
67 |
!
|
|
68 |
|
|
69 |
examples
|
|
70 |
"
|
|
71 |
Smalltalk loadPackage:'exept:regression'
|
|
72 |
|
|
73 |
[exBegin]
|
|
74 |
|suite result testResult|
|
|
75 |
|
|
76 |
InstrumentingCompiler compilePackage:'stx:libjavascript'.
|
|
77 |
InstrumentationContext new run:[
|
|
78 |
testResult := RegressionTests::JavaScriptTests suite run.
|
|
79 |
].
|
|
80 |
'testResult.xml' asFilename writingFileDo:[:stream |
|
|
81 |
TestResultReporter report:testResult format:#xml_jUnit on:stream.
|
|
82 |
].
|
|
83 |
'testCoverage.xml' asFilename writingFileDo:[:stream |
|
|
84 |
TestCoverageReporter reportPackages:{ 'stx:libjavascript' } format:#xml_cobertura on:stream.
|
|
85 |
].
|
|
86 |
|
|
87 |
[exEnd]
|
510
|
88 |
|
|
89 |
[exBegin]
|
|
90 |
|suite result testResult|
|
|
91 |
|
|
92 |
InstrumentingCompiler compilePackage:'stx:libjavascript'.
|
|
93 |
InstrumentationContext new run:[
|
|
94 |
testResult := RegressionTests::JavaScriptTests suite run.
|
|
95 |
].
|
|
96 |
'
|
|
97 |
TestResultReporter report:testResult format:#xml_jUnit on:Transcript.
|
|
98 |
'.
|
|
99 |
TestCoverageReporter reportPackages:{ 'stx:libjavascript' } format:#xml_cobertura on:Transcript.
|
|
100 |
|
|
101 |
[exEnd]
|
|
102 |
"
|
|
103 |
!
|
|
104 |
|
|
105 |
format_cobertura_dtd04
|
|
106 |
"
|
|
107 |
<!!ELEMENT coverage (sources?,packages)>
|
|
108 |
<!!ATTLIST coverage line-rate CDATA #REQUIRED>
|
|
109 |
<!!ATTLIST coverage branch-rate CDATA #REQUIRED>
|
|
110 |
<!!ATTLIST coverage lines-covered CDATA #REQUIRED>
|
|
111 |
<!!ATTLIST coverage lines-valid CDATA #REQUIRED>
|
|
112 |
<!!ATTLIST coverage branches-covered CDATA #REQUIRED>
|
|
113 |
<!!ATTLIST coverage branches-valid CDATA #REQUIRED>
|
|
114 |
<!!ATTLIST coverage complexity CDATA #REQUIRED>
|
|
115 |
<!!ATTLIST coverage version CDATA #REQUIRED>
|
|
116 |
<!!ATTLIST coverage timestamp CDATA #REQUIRED>
|
|
117 |
|
|
118 |
<!!ELEMENT sources (source*)>
|
|
119 |
|
|
120 |
<!!ELEMENT source (#PCDATA)>
|
|
121 |
|
|
122 |
<!!ELEMENT packages (package*)>
|
|
123 |
|
|
124 |
<!!ELEMENT package (classes)>
|
|
125 |
<!!ATTLIST package name CDATA #REQUIRED>
|
|
126 |
<!!ATTLIST package line-rate CDATA #REQUIRED>
|
|
127 |
<!!ATTLIST package branch-rate CDATA #REQUIRED>
|
|
128 |
<!!ATTLIST package complexity CDATA #REQUIRED>
|
|
129 |
|
|
130 |
<!!ELEMENT classes (class*)>
|
|
131 |
|
|
132 |
<!!ELEMENT class (methods,lines)>
|
|
133 |
<!!ATTLIST class name CDATA #REQUIRED>
|
|
134 |
<!!ATTLIST class filename CDATA #REQUIRED>
|
|
135 |
<!!ATTLIST class line-rate CDATA #REQUIRED>
|
|
136 |
<!!ATTLIST class branch-rate CDATA #REQUIRED>
|
|
137 |
<!!ATTLIST class complexity CDATA #REQUIRED>
|
|
138 |
|
|
139 |
<!!ELEMENT methods (method*)>
|
|
140 |
|
|
141 |
<!!ELEMENT method (lines)>
|
|
142 |
<!!ATTLIST method name CDATA #REQUIRED>
|
|
143 |
<!!ATTLIST method signature CDATA #REQUIRED>
|
|
144 |
<!!ATTLIST method line-rate CDATA #REQUIRED>
|
|
145 |
<!!ATTLIST method branch-rate CDATA #REQUIRED>
|
|
146 |
|
|
147 |
<!!ELEMENT lines (line*)>
|
|
148 |
|
|
149 |
<!!ELEMENT line (conditions*)>
|
|
150 |
<!!ATTLIST line number CDATA #REQUIRED>
|
|
151 |
<!!ATTLIST line hits CDATA #REQUIRED>
|
|
152 |
<!!ATTLIST line branch CDATA ""false"">
|
|
153 |
<!!ATTLIST line condition-coverage CDATA ""100%"">
|
|
154 |
|
|
155 |
<!!ELEMENT conditions (condition*)>
|
|
156 |
|
|
157 |
<!!ELEMENT condition EMPTY>
|
|
158 |
<!!ATTLIST condition number CDATA #REQUIRED>
|
|
159 |
<!!ATTLIST condition type CDATA #REQUIRED>
|
|
160 |
<!!ATTLIST condition coverage CDATA #REQUIRED>
|
507
|
161 |
"
|
|
162 |
! !
|
|
163 |
|
|
164 |
!TestCoverageReporter class methodsFor:'queries'!
|
|
165 |
|
|
166 |
supportedFormats
|
|
167 |
"return a list of formats and short-info-string, as per supported format symbol"
|
|
168 |
|
|
169 |
^ #(
|
|
170 |
(#'xml_cobertura' 'a cobertura-like xml format')
|
|
171 |
)
|
|
172 |
|
|
173 |
"Created: / 30-07-2011 / 10:18:18 / cg"
|
|
174 |
! !
|
|
175 |
|
|
176 |
!TestCoverageReporter class methodsFor:'reporting'!
|
|
177 |
|
|
178 |
reportPackages: aCollectionOfPackages format: format on: stream
|
|
179 |
self new
|
|
180 |
reportPackages: aCollectionOfPackages format: format on: stream
|
|
181 |
! !
|
|
182 |
|
|
183 |
!TestCoverageReporter methodsFor:'reporting'!
|
|
184 |
|
|
185 |
reportPackages: aCollectionOfPackages format: aSymbol on: aStream
|
|
186 |
|
|
187 |
packages := aCollectionOfPackages.
|
|
188 |
stream := aStream.
|
|
189 |
self report: aSymbol
|
|
190 |
! !
|
|
191 |
|
|
192 |
!TestCoverageReporter methodsFor:'reporting - xml-cobertura'!
|
|
193 |
|
510
|
194 |
reportXml_cobertura
|
507
|
195 |
"
|
|
196 |
self new
|
|
197 |
stream:Transcipt;
|
|
198 |
reportXml_coberturaForPackage:'stx:libbasic'
|
|
199 |
"
|
|
200 |
"generate cobertura compatible XML coverage report format"
|
|
201 |
|
510
|
202 |
|instrumentedClasses uninstrumentedClasses
|
|
203 |
version lineRate branchRate
|
|
204 |
linesCovered linesValid branchesCovered branchesValid complexity|
|
|
205 |
|
|
206 |
lineRate := 50.
|
|
207 |
branchRate := 61.
|
|
208 |
version := '0.4'.
|
|
209 |
linesCovered := 1000.
|
|
210 |
linesValid := 1000.
|
|
211 |
branchesCovered := 1000.
|
|
212 |
branchesValid := 1000.
|
|
213 |
complexity := 1.5.
|
507
|
214 |
|
|
215 |
instrumentedClasses := OrderedCollection new.
|
|
216 |
uninstrumentedClasses := OrderedCollection new.
|
|
217 |
|
510
|
218 |
packages do:[:eachPackageID |
|
|
219 |
Smalltalk allClassesInPackage:eachPackageID do:[:eachClass |
|
|
220 |
((eachClass methodDictionary values contains:[:someMethod | someMethod isInstrumented])
|
|
221 |
or:[ (eachClass class methodDictionary values contains:[:someMethod | someMethod isInstrumented]) ])
|
|
222 |
ifTrue:[
|
|
223 |
instrumentedClasses add:eachClass
|
|
224 |
] ifFalse:[
|
|
225 |
uninstrumentedClasses add:eachClass
|
|
226 |
].
|
507
|
227 |
].
|
|
228 |
].
|
|
229 |
|
|
230 |
stream
|
|
231 |
nextPutLine: '<?xml version="1.0"?>';
|
|
232 |
nextPutLine: '<!!--DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-03.dtd"-->';
|
|
233 |
nextPutAll: '<coverage';
|
|
234 |
nextPutAll:(' line-rate="%1"' bindWith:lineRate);
|
|
235 |
nextPutAll:(' branch-rate="%1"' bindWith:branchRate);
|
510
|
236 |
nextPutAll:(' version="%1"' bindWith:version);
|
|
237 |
nextPutAll:(' lines-covered="%1"' bindWith:linesCovered);
|
|
238 |
nextPutAll:(' lines-valid="%1"' bindWith:linesValid);
|
|
239 |
nextPutAll:(' branches-covered="%1"' bindWith:branchesCovered);
|
|
240 |
nextPutAll:(' branches-valid="%1"' bindWith:branchesValid);
|
|
241 |
nextPutAll:(' complexity="%1"' bindWith:complexity);
|
507
|
242 |
nextPutAll:(' timestamp="%1>"' bindWith:Timestamp now utcSecondsSince1970 * 1000 "millis").
|
510
|
243 |
|
|
244 |
packages do:[:eachPackageID |
|
|
245 |
].
|
|
246 |
|
|
247 |
stream
|
|
248 |
nextPutAll: '</coverage'.
|
507
|
249 |
! !
|
|
250 |
|
|
251 |
!TestCoverageReporter methodsFor:'reporting-private'!
|
|
252 |
|
|
253 |
report:formatSymbol
|
|
254 |
"currently supported formatSymbols:
|
|
255 |
xml_cobertura"
|
|
256 |
|
|
257 |
|reportFormatSelector|
|
|
258 |
|
|
259 |
reportFormatSelector := self reportFormatSelector:formatSymbol.
|
|
260 |
(self respondsTo: reportFormatSelector)
|
|
261 |
ifTrue:[self perform: reportFormatSelector]
|
|
262 |
ifFalse:[self error:'Unsupported format: ', formatSymbol].
|
|
263 |
|
|
264 |
"Modified (comment): / 03-08-2011 / 12:57:54 / cg"
|
|
265 |
!
|
|
266 |
|
|
267 |
reportFormatSelector:format
|
|
268 |
^ ('report' , format asString capitalized) asSymbol
|
|
269 |
! !
|
|
270 |
|
|
271 |
!TestCoverageReporter class methodsFor:'documentation'!
|
|
272 |
|
|
273 |
version
|
510
|
274 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestCoverageReporter.st,v 1.2 2012-11-07 18:40:46 cg Exp $'
|
507
|
275 |
!
|
|
276 |
|
|
277 |
version_CVS
|
510
|
278 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestCoverageReporter.st,v 1.2 2012-11-07 18:40:46 cg Exp $'
|
507
|
279 |
! !
|