reports/Builder__CoverageReport.st
author Claus Gittinger <cg@exept.de>
Thu, 28 Mar 2019 13:54:38 +0100
changeset 542 aa25a71be62a
parent 290 c5fdcba3c682
permissions -rw-r--r--
#DOCUMENTATION by cg
class: stx_goodies_builder_quickSelfTest
class definition

class: stx_goodies_builder_quickSelfTest class
added:18 methods
jan@68
     1
"{ Package: 'stx:goodies/builder/reports' }"
jan@68
     2
jan@68
     3
"{ NameSpace: Builder }"
jan@68
     4
jan@166
     5
Report subclass:#CoverageReport
jan@166
     6
	instanceVariableNames:'instrumentedMethods'
jan@68
     7
	classVariableNames:''
jan@68
     8
	poolDictionaries:''
jan@166
     9
	category:'Builder-Reports'
jan@68
    10
!
jan@68
    11
jan@68
    12
jan@166
    13
!CoverageReport methodsFor:'accessing-defaults'!
jan@68
    14
jan@166
    15
defaultFileSuffix
jan@166
    16
jan@166
    17
    "Return a default filename suffix. Note that format suffix will be 
jan@166
    18
     appended too if not file is explicitely specified"
jan@166
    19
jan@166
    20
    ^'Coverage'
jan@166
    21
jan@166
    22
    "Created: / 25-06-2013 / 01:12:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
    23
!
jan@68
    24
jan@166
    25
defaultFormat
jan@166
    26
    "raise an error: must be redefined in concrete subclass(es)"
jan@166
    27
jan@166
    28
    ^ Builder::CoverageReportFormat::Cobertura new
jan@166
    29
jan@166
    30
    "Modified: / 25-06-2013 / 01:31:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
    31
!
jan@68
    32
jan@166
    33
defaultName
jan@166
    34
jan@166
    35
    packages isNil ifTrue:[
jan@166
    36
        ^'someClasses'.
jan@166
    37
    ].
jan@166
    38
jan@166
    39
    ^String streamContents:[:s|
jan@166
    40
        packages do:[:packageOrClass|
jan@166
    41
            s nextPutAll: packageOrClass printString 
jan@166
    42
        ] separatedBy:[
jan@166
    43
            s nextPut:$,;space
jan@166
    44
        ]
jan@166
    45
    ]
jan@166
    46
jan@166
    47
    "Created: / 25-06-2013 / 01:29:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@166
    48
! !
jan@166
    49
jan@166
    50
!CoverageReport methodsFor:'initialization'!
jan@166
    51
jan@166
    52
initialize
jan@166
    53
    instrumentedMethods := Set new.
jan@166
    54
jan@166
    55
    "Created: / 25-06-2013 / 01:40:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@166
    56
    "Modified: / 25-06-2013 / 13:21:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
    57
!
jan@68
    58
jan@166
    59
setupForClasses:classes
jan@166
    60
    "raise an error: must be redefined in concrete subclass(es)"
jan@166
    61
jan@166
    62
    classes do:[:each | self instrumentClass: each].
jan@166
    63
jan@166
    64
    "Modified: / 25-06-2013 / 16:22:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
    65
!
jan@68
    66
jan@166
    67
setupForPackages:pkgs
jan@166
    68
    "raise an error: must be redefined in concrete subclass(es)"
jan@166
    69
jan@166
    70
    pkgs do:[:each | self instrumentPackage: each ].
jan@166
    71
jan@166
    72
    "Modified: / 25-06-2013 / 16:22:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@166
    73
! !
jan@166
    74
jan@166
    75
!CoverageReport methodsFor:'instrumentation'!
jan@166
    76
jan@166
    77
instrumentClass:class
jan@166
    78
    class instAndClassMethods do:[:method|
jan@166
    79
        self instrumentMethod: method 
jan@166
    80
    ]
jan@166
    81
jan@166
    82
    "Created: / 25-06-2013 / 01:42:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
    83
!
jan@68
    84
jan@166
    85
instrumentMethod:method
jan@166
    86
jan@166
    87
    | class selector |
jan@166
    88
jan@166
    89
    class := method mclass.
jan@166
    90
    selector := method selector.
jan@185
    91
    (self excludedFromCoverage: method) ifFalse:[
jan@185
    92
        method isInstrumented ifFalse:[
jan@185
    93
            InstrumentingCompiler compileMethod: method.
jan@185
    94
        ].
jan@185
    95
        instrumentedMethods add: (class compiledMethodAt: selector)
jan@185
    96
    ]
jan@166
    97
jan@166
    98
    "Created: / 25-06-2013 / 01:44:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@185
    99
    "Modified: / 28-06-2013 / 02:45:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
   100
!
jan@68
   101
jan@166
   102
instrumentPackage:pkg
jan@166
   103
    Smalltalk allMethodsDo:[:method|
jan@166
   104
        method package asSymbol == pkg asSymbol ifTrue:[
jan@166
   105
            self instrumentMethod: method.
jan@166
   106
        ]
jan@166
   107
    ]
jan@68
   108
jan@166
   109
    "Created: / 25-06-2013 / 01:42:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@166
   110
    "Modified: / 25-06-2013 / 17:51:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
   111
! !
jan@68
   112
jan@185
   113
!CoverageReport methodsFor:'queries'!
jan@185
   114
jan@185
   115
excludedFromCoverage: aMethod
jan@185
   116
    "Returns true, if given method should be excluded from
jan@185
   117
     coverage report.
jan@185
   118
jan@185
   119
     Here, certain 'metadata' method like documentation, copyright,
jan@185
   120
     version methods, printOn: and so on are exluded. Also, testcases
jan@185
   121
     and test resources are ommited"
jan@185
   122
sv@290
   123
    | mclass mselector tree pkgdef |
jan@185
   124
jan@185
   125
    mclass := aMethod mclass.
jan@185
   126
    mselector := aMethod selector.
jan@185
   127
jan@185
   128
    aMethod hasPrimitiveCode ifTrue:[ ^ true ].
jan@185
   129
    (mclass inheritsFrom: TestCase) ifTrue:[ ^ true ].
jan@185
   130
    (mclass inheritsFrom: TestResource) ifTrue:[ ^ true ].
jan@185
   131
    (mclass inheritsFrom: ProjectDefinition) ifTrue:[ ^ true ].
jan@185
   132
    mclass isMetaclass ifTrue:[
jan@185
   133
        (#(
jan@185
   134
                copyright 
jan@185
   135
                documentation
jan@185
   136
        ) includes: mselector) ifTrue:[ ^ true ].
jan@185
   137
        (AbstractSourceCodeManager isVersionMethodSelector: mselector) ifTrue:[ ^ true ].
jan@185
   138
    ] ifFalse:[
jan@185
   139
        (#(
jan@185
   140
            printString printOn: 
jan@185
   141
            inspectorExtraAttributes inspectorClass
jan@185
   142
        ) includes: mselector) ifTrue:[ ^ true ].    
jan@185
   143
    ].
jan@185
   144
sv@290
   145
    tree := (Parser parseMethod: aMethod source in: mclass) tree.
jan@185
   146
    tree isNil ifTrue:[ ^ true ]. "/ empty method?
jan@185
   147
    (tree isStatement and:[tree isReturnNode not and:[tree nextStatement isNil]]) ifTrue:[
jan@185
   148
        tree := tree expression.
jan@185
   149
    ].
jan@185
   150
jan@185
   151
    "/ Exclude all getters/return constants...
sv@290
   152
    (aMethod numArgs == 0 
sv@290
   153
        and:[tree isReturnNode 
sv@290
   154
        and:[tree expression isVariable or:[tree expression isConstant]]]) ifTrue:[ ^ true ].
jan@185
   155
jan@185
   156
    "/ Exclude all setters
jan@185
   157
    (aMethod numArgs == 1 
jan@185
   158
        and:[tree isAssignment 
sv@290
   159
        and:[(tree variable isInstanceVariable or:[tree variable isClassVariable])
jan@185
   160
        and:[tree expression isVariable
sv@290
   161
        and:[tree expression isMethodArg]]]]) ifTrue:[ ^ true ].
jan@185
   162
jan@185
   163
    pkgdef := ProjectDefinition definitionClassForPackage: aMethod package.
jan@185
   164
    pkgdef notNil ifTrue:[
sv@290
   165
        ^ pkgdef excludedFromCoverage:aMethod.
jan@185
   166
    ].
sv@290
   167
    ^ false
jan@185
   168
jan@185
   169
    "Created: / 28-06-2013 / 02:20:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@187
   170
    "Modified (comment): / 28-06-2013 / 11:31:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@185
   171
! !
jan@185
   172
jan@68
   173
!CoverageReport methodsFor:'running'!
jan@68
   174
jan@166
   175
runReport
jan@166
   176
    "Actually run the report. What to do (what classes/packages to check)
jan@166
   177
     must be stored instance variables"
jan@148
   178
jan@166
   179
    format write: instrumentedMethods.
jan@68
   180
jan@166
   181
    "Modified: / 25-06-2013 / 13:13:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@68
   182
! !
jan@68
   183
jan@68
   184
!CoverageReport class methodsFor:'documentation'!
jan@68
   185
jan@68
   186
version
jan@68
   187
    ^ '$Header$'
jan@68
   188
!
jan@68
   189
jan@68
   190
version_CVS
jan@68
   191
    ^ '$Header$'
jan@68
   192
!
jan@68
   193
jan@68
   194
version_SVN
jan@148
   195
    ^ '$Id$'
jan@68
   196
! !
jan@148
   197