TestCaseOutcome.st
branchworking_v5_0
changeset 614 3003097506c9
parent 589 b7cd9f791bb1
child 615 f1b888de7817
equal deleted inserted replaced
613:5a546630cfcf 614:3003097506c9
     1 "{ Package: 'stx:goodies/sunit' }"
     1 "{ Package: 'stx:goodies/sunit' }"
     2 
     2 
     3 Object subclass:#TestCaseOutcome
     3 Object subclass:#TestCaseOutcome
     4 	instanceVariableNames:'testCase result properties'
     4 	instanceVariableNames:'testCase result properties'
     5 	classVariableNames:''
     5 	classVariableNames:'RemeberedOutcomes'
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'SUnit-Base'
     7 	category:'SUnit-Base'
     8 !
     8 !
     9 
     9 
    10 !TestCaseOutcome class methodsFor:'documentation'!
    10 !TestCaseOutcome class methodsFor:'documentation'!
    16         backtrace (if fail or error)
    16         backtrace (if fail or error)
    17         and collectedStdout
    17         and collectedStdout
    18 "
    18 "
    19 ! !
    19 ! !
    20 
    20 
       
    21 !TestCaseOutcome class methodsFor:'initialization'!
       
    22 
       
    23 initialize
       
    24     "Invoked at system start or when the class is dynamically loaded."
       
    25 
       
    26     "/ please change as required (and remove this comment)
       
    27 
       
    28 
       
    29     RemeberedOutcomes := SUnitNameResolver weakIdentityDictionaryClass new
       
    30 
       
    31     "Modified: / 14-07-2014 / 09:59:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    32 ! !
       
    33 
    21 !TestCaseOutcome class methodsFor:'instance creation'!
    34 !TestCaseOutcome class methodsFor:'instance creation'!
    22 
    35 
    23 forCase: aTestCase
    36 forCase: aTestCase
    24 
    37 
    25     ^self new testCase: aTestCase; yourself
    38     ^self new testCase: aTestCase; yourself
    26 
    39 
    27     "Created: / 16-08-2011 / 15:24:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    40     "Created: / 16-08-2011 / 15:24:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    41 ! !
       
    42 
       
    43 !TestCaseOutcome class methodsFor:'notifying'!
       
    44 
       
    45 notifyOutcomeChanged: currentOutcome ifDifferentFrom: previousOutcome
       
    46     "Notifies whoever is interested that the current outcome for a testcase has
       
    47      changed, but only if result of the current (pass, fail or error) is actually 
       
    48      different the result of previous outcome"   
       
    49 
       
    50     (previousOutcome isNil or:[ previousOutcome result ~~ currentOutcome result ]) ifTrue:[ 
       
    51         currentOutcome testCase class lastTestRunResultChanged:currentOutcome testCase selector         
       
    52     ].
       
    53 
       
    54     "Created: / 14-07-2014 / 21:07:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    55 ! !
       
    56 
       
    57 !TestCaseOutcome class methodsFor:'remembering'!
       
    58 
       
    59 rememberOutcome: current
       
    60     | method outcomes previous |    
       
    61 
       
    62     method := current method.                                    
       
    63     outcomes := RemeberedOutcomes at: method ifAbsent:[ RemeberedOutcomes at: method put: TestCaseOutcomeWeakIdentityDictionary new ]. 
       
    64     previous := outcomes at: current testCase class ifAbsent:[ nil ].
       
    65     outcomes at: current testCase class put: current.
       
    66     self notifyOutcomeChanged: current ifDifferentFrom: previous.
       
    67 
       
    68     "Created: / 13-07-2014 / 23:28:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    69     "Modified: / 14-07-2014 / 21:16:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    70 !
       
    71 
       
    72 rememberedOutcomeFor: selector in: class
       
    73     | implementor method outcomes |
       
    74 
       
    75     implementor := class.
       
    76     [implementor notNil and:[implementor includesSelector: selector]]
       
    77             whileFalse: [implementor := implementor superclass].
       
    78     implementor isNil ifTrue:[ ^ nil ].
       
    79     method := implementor compiledMethodAt: selector.                   
       
    80     outcomes := RemeberedOutcomes at: method ifAbsent:[ ^ nil ].
       
    81     ^ outcomes at: class ifAbsent: [ nil ]
       
    82 
       
    83     "Created: / 13-07-2014 / 23:56:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    84     "Modified: / 14-07-2014 / 21:15:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    28 ! !
    85 ! !
    29 
    86 
    30 !TestCaseOutcome methodsFor:'accessing'!
    87 !TestCaseOutcome methodsFor:'accessing'!
    31 
    88 
    32 collectedOutput
    89 collectedOutput
    87         endTime := Timestamp now
   144         endTime := Timestamp now
    88     ].
   145     ].
    89     ^ (endTime millisecondDeltaFrom:startTime)
   146     ^ (endTime millisecondDeltaFrom:startTime)
    90 
   147 
    91     "Modified (format): / 18-08-2011 / 21:02:28 / cg"
   148     "Modified (format): / 18-08-2011 / 21:02:28 / cg"
       
   149 !
       
   150 
       
   151 method
       
   152     "Return the CompiledMethod corresponding to this test case in as dialect-neutral a way as possible.  We code on the assumption there must be one. If there isn't and we work up to nil superclass then fail, not bothering with implementor isNil ifTrue: [^nil] as we assume the caller would immediately fail in that case."
       
   153 
       
   154     | implementor |
       
   155     implementor := testCase class.
       
   156     [implementor includesSelector: testCase selector]
       
   157             whileFalse: [implementor := implementor superclass].
       
   158     ^ implementor compiledMethodAt: testCase selector
       
   159 
       
   160     "Created: / 13-07-2014 / 23:31:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    92 !
   161 !
    93 
   162 
    94 propertyAt: aSymbol
   163 propertyAt: aSymbol
    95 
   164 
    96     ^ self propertyAt: aSymbol ifAbsent: [nil]
   165     ^ self propertyAt: aSymbol ifAbsent: [nil]
   193 
   262 
   194 !TestCaseOutcome methodsFor:'remembering'!
   263 !TestCaseOutcome methodsFor:'remembering'!
   195 
   264 
   196 remember
   265 remember
   197 
   266 
   198     ^testCase class rememberOutcome: self.
   267     ^TestCaseOutcome rememberOutcome: self.
   199 
   268 
   200     "Created: / 20-08-2011 / 12:45:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   269     "Created: / 20-08-2011 / 12:45:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   270     "Modified: / 14-07-2014 / 21:35:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   201 ! !
   271 ! !
   202 
   272 
   203 !TestCaseOutcome class methodsFor:'documentation'!
   273 !TestCaseOutcome class methodsFor:'documentation'!
   204 
   274 
   205 version_CVS
   275 version_CVS
   206     ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCaseOutcome.st,v 1.6 2014-04-16 22:06:04 cg Exp $'
   276     ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCaseOutcome.st,v 1.6 2014-04-16 22:06:04 cg Exp $'
   207 ! !
   277 ! !
   208 
   278 
       
   279 
       
   280 TestCaseOutcome initialize!