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