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