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