TestCoverageReporter.st
changeset 510 df4b9666403b
parent 507 ec48d46dce83
child 582 788c7d7fcfc6
--- a/TestCoverageReporter.st	Wed Nov 07 19:40:22 2012 +0100
+++ b/TestCoverageReporter.st	Wed Nov 07 19:40:46 2012 +0100
@@ -1,3 +1,14 @@
+"
+ COPYRIGHT (c) 2012 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
 "{ Package: 'stx:goodies/sunit' }"
 
 Object subclass:#TestCoverageReporter
@@ -9,8 +20,25 @@
 
 !TestCoverageReporter class methodsFor:'documentation'!
 
+copyright
+"
+ COPYRIGHT (c) 2012 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+
+"
+!
+
 documentation
 "
+    this is used as a last step in jenkins automated builds.
+
     Currently supported formats are:
         #xml_cobertura      - a cobertura compatible format
 
@@ -57,6 +85,79 @@
     ].
 
                                                                                [exEnd]
+
+                                                                               [exBegin]
+    |suite result testResult|
+
+    InstrumentingCompiler compilePackage:'stx:libjavascript'.
+    InstrumentationContext new run:[
+        testResult := RegressionTests::JavaScriptTests suite run.
+    ].
+'
+    TestResultReporter report:testResult format:#xml_jUnit on:Transcript.
+'.
+    TestCoverageReporter reportPackages:{ 'stx:libjavascript' } format:#xml_cobertura on:Transcript.
+
+                                                                               [exEnd]
+"
+!
+
+format_cobertura_dtd04
+"
+<!!ELEMENT coverage (sources?,packages)>
+<!!ATTLIST coverage line-rate        CDATA #REQUIRED>
+<!!ATTLIST coverage branch-rate      CDATA #REQUIRED>
+<!!ATTLIST coverage lines-covered    CDATA #REQUIRED>
+<!!ATTLIST coverage lines-valid      CDATA #REQUIRED>
+<!!ATTLIST coverage branches-covered CDATA #REQUIRED>
+<!!ATTLIST coverage branches-valid   CDATA #REQUIRED>
+<!!ATTLIST coverage complexity       CDATA #REQUIRED>
+<!!ATTLIST coverage version          CDATA #REQUIRED>
+<!!ATTLIST coverage timestamp        CDATA #REQUIRED>
+
+<!!ELEMENT sources (source*)>
+
+<!!ELEMENT source (#PCDATA)>
+
+<!!ELEMENT packages (package*)>
+
+<!!ELEMENT package (classes)>
+<!!ATTLIST package name        CDATA #REQUIRED>
+<!!ATTLIST package line-rate   CDATA #REQUIRED>
+<!!ATTLIST package branch-rate CDATA #REQUIRED>
+<!!ATTLIST package complexity  CDATA #REQUIRED>
+
+<!!ELEMENT classes (class*)>
+
+<!!ELEMENT class (methods,lines)>
+<!!ATTLIST class name        CDATA #REQUIRED>
+<!!ATTLIST class filename    CDATA #REQUIRED>
+<!!ATTLIST class line-rate   CDATA #REQUIRED>
+<!!ATTLIST class branch-rate CDATA #REQUIRED>
+<!!ATTLIST class complexity  CDATA #REQUIRED>
+
+<!!ELEMENT methods (method*)>
+
+<!!ELEMENT method (lines)>
+<!!ATTLIST method name        CDATA #REQUIRED>
+<!!ATTLIST method signature   CDATA #REQUIRED>
+<!!ATTLIST method line-rate   CDATA #REQUIRED>
+<!!ATTLIST method branch-rate CDATA #REQUIRED>
+
+<!!ELEMENT lines (line*)>
+
+<!!ELEMENT line (conditions*)>
+<!!ATTLIST line number CDATA #REQUIRED>
+<!!ATTLIST line hits   CDATA #REQUIRED>
+<!!ATTLIST line branch CDATA ""false"">
+<!!ATTLIST line condition-coverage CDATA ""100%"">
+
+<!!ELEMENT conditions (condition*)>
+
+<!!ELEMENT condition EMPTY>
+<!!ATTLIST condition number CDATA #REQUIRED>
+<!!ATTLIST condition type CDATA #REQUIRED>
+<!!ATTLIST condition coverage CDATA #REQUIRED>
 "
 ! !
 
@@ -90,7 +191,7 @@
 
 !TestCoverageReporter methodsFor:'reporting - xml-cobertura'!
 
-reportXml_coberturaForPackage:aPackageID
+reportXml_cobertura
 "
  self new 
         stream:Transcipt;
@@ -98,18 +199,31 @@
 "
     "generate cobertura compatible XML coverage report format"
 
-    |classes instrumentedClasses uninstrumentedClasses lineRate branchRate|
+    |instrumentedClasses uninstrumentedClasses 
+     version lineRate branchRate
+     linesCovered linesValid branchesCovered branchesValid complexity|
+
+    lineRate := 50.
+    branchRate := 61.
+    version := '0.4'.
+    linesCovered := 1000.
+    linesValid := 1000.
+    branchesCovered := 1000.
+    branchesValid := 1000.
+    complexity := 1.5.
 
     instrumentedClasses := OrderedCollection new.    
     uninstrumentedClasses := OrderedCollection new.    
 
-    Smalltalk allClassesInPackage:aPackageID do:[:eachClass |
-        ((eachClass methodDictionary values contains:[:someMethod | someMethod isInstrumented])
-        or:[ (eachClass class methodDictionary values contains:[:someMethod | someMethod isInstrumented]) ])
-        ifTrue:[
-            instrumentedClasses add:eachClass
-        ] ifFalse:[
-            uninstrumentedClasses add:eachClass
+    packages do:[:eachPackageID |
+        Smalltalk allClassesInPackage:eachPackageID do:[:eachClass |
+            ((eachClass methodDictionary values contains:[:someMethod | someMethod isInstrumented])
+            or:[ (eachClass class methodDictionary values contains:[:someMethod | someMethod isInstrumented]) ])
+            ifTrue:[
+                instrumentedClasses add:eachClass
+            ] ifFalse:[
+                uninstrumentedClasses add:eachClass
+            ].
         ].
     ].
 
@@ -119,8 +233,19 @@
         nextPutAll: '<coverage';
         nextPutAll:(' line-rate="%1"' bindWith:lineRate);
         nextPutAll:(' branch-rate="%1"' bindWith:branchRate);
-        nextPutAll:(' version="%1"' bindWith:'0.1' "dummy");
+        nextPutAll:(' version="%1"' bindWith:version);
+        nextPutAll:(' lines-covered="%1"' bindWith:linesCovered);
+        nextPutAll:(' lines-valid="%1"' bindWith:linesValid);
+        nextPutAll:(' branches-covered="%1"' bindWith:branchesCovered);
+        nextPutAll:(' branches-valid="%1"' bindWith:branchesValid);
+        nextPutAll:(' complexity="%1"' bindWith:complexity);
         nextPutAll:(' timestamp="%1>"' bindWith:Timestamp now utcSecondsSince1970 * 1000 "millis").
+
+    packages do:[:eachPackageID |
+    ].
+
+    stream
+        nextPutAll: '</coverage'.
 ! !
 
 !TestCoverageReporter methodsFor:'reporting-private'!
@@ -146,9 +271,9 @@
 !TestCoverageReporter class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCoverageReporter.st,v 1.1 2012-11-07 14:19:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCoverageReporter.st,v 1.2 2012-11-07 18:40:46 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCoverageReporter.st,v 1.1 2012-11-07 14:19:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCoverageReporter.st,v 1.2 2012-11-07 18:40:46 cg Exp $'
 ! !