TestResultStX.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 13 Nov 2013 00:10:09 +0100
changeset 580 d86ef51e98ab
parent 571 d5a1ac6d1743
child 593 4193d093e71c
permissions -rw-r--r--
Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on: Care for Java methods...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     1
"{ Package: 'stx:goodies/sunit' }"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     2
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     3
TestResult subclass:#TestResultStX
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
     4
	instanceVariableNames:'endTime'
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     5
	classVariableNames:''
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     6
	poolDictionaries:''
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     7
	category:'SUnit-Smalltalk/X'
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     8
!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     9
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    10
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    11
!TestResultStX class methodsFor:'utilities'!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    12
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    13
sourceFilenameOfClass:aClass
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    14
    "that is ST/X specific"
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    15
    "no Smalltalk/X dialect detection needed..."
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    16
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    17
    |sourceStream testClassSourceFile|
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    18
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    19
    sourceStream := aClass sourceStream.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    20
    sourceStream notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    21
        [
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    22
            sourceStream := sourceStream stream.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    23
            sourceStream isFileStream ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    24
                testClassSourceFile := sourceStream pathName asFilename pathName.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    25
            ].
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    26
        ] ensure:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    27
            sourceStream close.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    28
        ]
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    29
    ].
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    30
    ^ testClassSourceFile
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    31
! !
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    32
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    33
!TestResultStX methodsFor:'accessing'!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    34
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    35
endTime
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    36
    ^ endTime
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    37
!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    38
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    39
endTime:aTimestamp
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    40
    "sets the overall (suite) end time"
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    41
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    42
    endTime := aTimestamp.
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    43
!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    44
482
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    45
executionTime
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    46
    "return the execution time (in seconds). If asked before or during a run, return nil"
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    47
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    48
    |t1 t2|
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    49
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    50
    (t1 := self startTime) isNil ifTrue:[^ nil].
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    51
    (t2 := self endTime) isNil ifTrue:[^ nil].
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    52
    ^ t2 secondDeltaFrom: t1
482
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    53
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    54
    "
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    55
     |a b|
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    56
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    57
     a := Timestamp now.
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    58
     Delay waitForMilliseconds:567.
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    59
     b := Timestamp now.
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    60
     b - a   
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    61
    "
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    62
!
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    63
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    64
startTime
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    65
    ^ timestamp
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    66
!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    67
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    68
startTime:aTimestamp
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    69
    "sets the overall (suite) start time"
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    70
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    71
    timestamp := aTimestamp.
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    72
! !
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    73
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    74
!TestResultStX methodsFor:'outcome'!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    75
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    76
printLineForContextForJavaCompatibleStackTrace:con on:aStream
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    77
    "why in java-backtrace format?
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    78
     Because then jenkins will be able to extract sourcefile and linenumber
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    79
     and generate links in the report page.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    80
     I am not willing to write another plugin for this - using junit compatible format"
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    81
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    82
    |cls classSourceFile method s lineNumberOfMethod lineNumberInFile relPath|
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    83
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    84
    "/ used to be:
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    85
    "/ con printOn:aStream.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    86
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    87
    "/ be careful: some tests generate methods on the fly, which are unbound!!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    88
    "/ or even (javascript/other languages) may not have a method at all!!!!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    89
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    90
    con fixAllLineNumbers.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    91
    (method := con method) notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    92
        cls := method mclass.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    93
        cls notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    94
            relPath := cls package copyReplaceAll:$: with:$/.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    95
            relPath := relPath copyReplaceAll:$\ with:$/.
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    96
            relPath := (relPath asFilename construct:cls theNonMetaclass classFilename) name.
508
c6352c44c013 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 505
diff changeset
    97
            classSourceFile := relPath.
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    98
526
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    99
            classSourceFile := Smalltalk getPackageFileName:relPath.
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   100
            classSourceFile isNil ifTrue:[    
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   101
                classSourceFile := self class sourceFilenameOfClass:cls.
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   102
            ].
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   103
            classSourceFile notNil ifTrue:[
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   104
                method isJavaMethod ifTrue:[
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   105
                    lineNumberOfMethod :=  method lineNumberForPC0: 0.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   106
                ] ifFalse:[
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   107
                    method sourcePosition notNil ifTrue:[
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   108
                        "/ sigh - we have the lineNumber within the method,
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   109
                        "/ and the characterPosition of the method's start.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   110
                        "/ need to calculate the absolute lineNumber in the file
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   111
                        s := LineNumberReadStream on:(classSourceFile asFilename readStream).
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   112
                        [
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   113
                            [s atEnd not and:[s position < method sourcePosition]] whileTrue:[
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   114
                                s nextLine
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   115
                            ].
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   116
                            lineNumberOfMethod := s lineNumber.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   117
                        ] ensure:[
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   118
                            s close.
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   119
                        ].
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   120
                    ]
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   121
                ]
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   122
            ]
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   123
        ].
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   124
    ].
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   125
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   126
    "/ output something (will not generate a ref to the source file)
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   127
    con printReceiverOn:aStream.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   128
    aStream nextPutAll:' >> '.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   129
    con selector printOn:aStream.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   130
    aStream nextPutAll:' ['.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   131
        con lineNumber printOn:aStream.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   132
    aStream nextPut:$].
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   133
526
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   134
    relPath notNil ifTrue:[
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   135
        lineNumberOfMethod notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   136
            lineNumberInFile := lineNumberOfMethod + con lineNumber - 1.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   137
            aStream nextPutAll:(' (%1:%2)'
526
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   138
                                bindWith: relPath
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   139
                                with: lineNumberInFile)
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   140
        ] ifFalse:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   141
            aStream nextPutAll:(' (%1)'
526
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   142
                                bindWith: relPath)
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   143
        ].
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   144
    ].
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   145
    aStream cr.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   146
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   147
    "Modified: / 05-08-2012 / 12:00:00 / cg"
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   148
    "Modified: / 12-11-2013 / 23:09:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   149
!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   150
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   151
rememberEndTime
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   152
    "remembers the endTime of the current test (in outcome)"
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   153
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   154
    ^outcome endTime: Timestamp now
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   155
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   156
    "Created: / 16-08-2011 / 17:36:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   157
!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   158
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   159
rememberException:ex
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   160
    "common for failure and error:
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   161
     called when a test fails. testCase is the failed 
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   162
     testcase, ex is platform specific object describing 
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   163
     the failure. Actually, on all platforms exeptt GemStone, 
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   164
     ex is an instance of an exception that caused the failure"
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   165
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   166
    |backtrace|
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   167
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   168
    ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifTrue:[
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   169
        "remember the backtrace (as string, to prevent objects from being kept forwever
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   170
         from being garbage collected, the signal (i.e. the exception class) and the
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   171
         exceptions message (description).
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   172
         Would like to have an exceptionInfo obejct for that, but that might be hard to 
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   173
         get returned back into the main stream sunit package..."
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   174
        
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   175
        backtrace := String streamContents:[:s |
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   176
                        |con topReached|
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   177
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   178
                        "could use printAllOn:s, but noone is interested in contexts above the
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   179
                         testcase's runtest context"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   180
                        topReached := false.
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   181
                        con := ex suspendedContext.
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   182
                        [ 
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   183
                            con notNil and:[topReached not]
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   184
                        ] whileTrue:[
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   185
                            self printLineForContextForJavaCompatibleStackTrace:con on:s.
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   186
                            topReached := (con selector == outcome selector)
465
0297ec178c9f changed: #rememberException:
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   187
                                          and:[con receiver == outcome
0297ec178c9f changed: #rememberException:
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   188
                                               or:[ con receiver == outcome testCase ]].
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   189
                            con := con sender.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   190
                        ]
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   191
                     ].
465
0297ec178c9f changed: #rememberException:
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   192
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   193
        outcome exceptionDetail:(Dictionary new
571
d5a1ac6d1743 use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   194
                                    at:#exception put:ex creator;
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   195
                                    at:#description put:ex description;
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   196
                                    at:#backtrace put:backtrace;
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   197
                                    yourself).
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   198
        ^ self.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   199
    ].
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   200
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   201
    "add other dialect specifics here"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   202
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   203
    "Created: / 06-08-2011 / 11:29:23 / cg"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   204
    "Created: / 16-08-2011 / 17:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   205
!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   206
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   207
rememberOutput: aString
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   208
    outcome collectedOutput: aString
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   209
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   210
    "Created: / 16-08-2011 / 18:18:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   211
!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   212
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   213
rememberStartTime
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   214
    "remembers the startTime of the current test (in outcome)"
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   215
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   216
    ^outcome startTime: Timestamp now
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   217
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   218
    "Created: / 16-08-2011 / 17:36:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   219
! !
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   220
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   221
!TestResultStX methodsFor:'running'!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   222
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   223
performCase: aTestCase
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   224
    "while performing a testcase, any output to the Transcript is also
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   225
     collected and is attached to the test result. Nice when tests are executed
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   226
     automatically, for example by jenkins.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   227
     Q: I think, we MUST lock this, 
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   228
        or better: aquire the lock and making collecting explicit via
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   229
                   call to 'self collectingTranscriptOutputDo:[...]' in the testcase.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   230
        Otherwise we'll run into trouble, when executing multiple tests in parallel.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   231
"
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   232
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   233
    | savedStdout savedTranscript collector|
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   234
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   235
    savedStdout := Stdout.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   236
    savedTranscript := Transcript.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   237
    collector := WriteStream on:(String new:100).
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   238
    [
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   239
        Stdout := SplittingWriteStream on:collector and: Stdout.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   240
        Transcript := SplittingWriteStream on:collector and: Transcript.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   241
        super performCase: aTestCase.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   242
    ] ensure:[
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   243
        Stdout := savedStdout.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   244
        Transcript := savedTranscript.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   245
        self rememberOutput: collector contents.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   246
    ].
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   247
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   248
    "Created: / 16-08-2011 / 18:18:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   249
    "Modified (comment): / 29-08-2013 / 11:15:36 / cg"
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   250
! !
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   251
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   252
!TestResultStX class methodsFor:'documentation'!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   253
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   254
version
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   255
    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestResultStX.st,v 1.14 2013-11-12 23:10:09 vrany Exp $'
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   256
!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   257
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   258
version_CVS
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   259
    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestResultStX.st,v 1.14 2013-11-12 23:10:09 vrany Exp $'
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   260
! !
571
d5a1ac6d1743 use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   261