TestResultStX.st
author Claus Gittinger <cg@exept.de>
Wed, 29 May 2019 01:12:49 +0200
changeset 747 1dcb53cf964d
parent 744 7f03f8bc1a15
child 761 757bd726452d
permissions -rw-r--r--
#FEATURE by cg class: TestCase added: #invokeTestMethod changed: #performTest support timeout annotation
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
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
     3
"{ NameSpace: Smalltalk }"
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
     4
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     5
TestResult subclass:#TestResultStX
744
7f03f8bc1a15 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 677
diff changeset
     6
	instanceVariableNames:''
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     7
	classVariableNames:''
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     8
	poolDictionaries:''
abd1f2918992 initial checkin
vrany
parents:
diff changeset
     9
	category:'SUnit-Smalltalk/X'
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    10
!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    11
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    12
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    13
!TestResultStX class methodsFor:'utilities'!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    14
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    15
sourceFilenameOfClass:aClass
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    16
    "that is ST/X specific"
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    17
    "no Smalltalk/X dialect detection needed..."
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 testClassSourceFile|
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 := aClass sourceStream.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    22
    sourceStream notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    23
        [
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    24
            sourceStream := sourceStream stream.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    25
            sourceStream isFileStream ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    26
                testClassSourceFile := sourceStream pathName asFilename pathName.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    27
            ].
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    28
        ] ensure:[
670
cee6c1d3e840 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 655
diff changeset
    29
            sourceStream notNil ifTrue:[ sourceStream close ].
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    30
        ]
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
    ^ testClassSourceFile
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
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    35
!TestResultStX methodsFor:'accessing'!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    36
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    37
endTime
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    38
    ^ endTime
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    39
!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    40
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    41
endTime:aTimestamp
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    42
    "sets the overall (suite) end time"
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    43
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    44
    endTime := aTimestamp.
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    45
!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    46
482
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    47
executionTime
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    48
    "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
    49
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    50
    |t1 t2|
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    51
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    52
    (t1 := self startTime) isNil ifTrue:[^ nil].
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    53
    (t2 := self endTime) isNil ifTrue:[^ nil].
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    54
    ^ t2 secondDeltaFrom: t1
482
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    55
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 b|
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 := Timestamp now.
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    60
     Delay waitForMilliseconds:567.
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    61
     b := Timestamp now.
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    62
     b - a   
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    63
    "
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    64
!
06dcc7ec96a5 added: #executionTime
Claus Gittinger <cg@exept.de>
parents: 479
diff changeset
    65
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    66
startTime
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    67
    ^ timestamp
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    68
!
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    69
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    70
startTime:aTimestamp
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    71
    "sets the overall (suite) start time"
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    72
493
2469037a625d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 482
diff changeset
    73
    timestamp := aTimestamp.
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    74
! !
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
    75
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    76
!TestResultStX methodsFor:'outcome'!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
    77
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    78
printLineForContextForJavaCompatibleStackTrace:con on:aStream
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    79
    "why in java-backtrace format?
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    80
     Because then jenkins will be able to extract sourcefile and linenumber
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    81
     and generate links in the report page.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    82
     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
    83
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    84
    |cls classSourceStream method s lineNumberOfMethod lineNumberInFile relPath methodSourcePosition|
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    85
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    86
    "/ used to be:
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    87
    "/ con printOn:aStream.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    88
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    89
    "/ be careful: some tests generate methods on the fly, which are unbound!!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    90
    "/ or even (javascript/other languages) may not have a method at all!!!!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    91
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    92
    con fixAllLineNumbers.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    93
    (method := con method) notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    94
        cls := method mclass.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    95
        cls notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    96
            relPath := cls package copyReplaceAll:$: with:$/.
593
4193d093e71c class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
    97
            relPath := relPath asUnixFilenameString.
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
    98
            relPath := (relPath asFilename construct:cls theNonMetaclass classFilename) name.
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
    99
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   100
            method isJavaMethod ifTrue:[
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   101
                lineNumberOfMethod :=  method lineNumberForPC0: 0.
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   102
            ] ifFalse:[
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   103
                methodSourcePosition := method sourcePosition.
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   104
                methodSourcePosition notNil ifTrue:[
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   105
                    classSourceStream := cls sourceStream.
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   106
                    classSourceStream notNil ifTrue:[
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   107
                        "/ 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
   108
                        "/ 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
   109
                        "/ need to calculate the absolute lineNumber in the file
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   110
                        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
   111
                        [
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   112
                            [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
   113
                                s nextLine
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   114
                            ].
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   115
                            lineNumberOfMethod := s lineNumber.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   116
                        ] ensure:[
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   117
                            s close.
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   118
                        ].
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   119
                    ].
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   120
                ]
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
    "/ 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
   126
    con printReceiverOn:aStream.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   127
    aStream nextPutAll:' >> '.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   128
    con selector printOn:aStream.
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   129
    aStream nextPutAll:' ['.
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   130
    con lineNumber printOn:aStream.
580
d86ef51e98ab Fix in TestResultStX>>#printLineForContextForJavaCompatibleStackTrace:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 571
diff changeset
   131
    aStream nextPut:$].
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   132
526
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   133
    relPath notNil ifTrue:[
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   134
        lineNumberOfMethod notNil ifTrue:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   135
            lineNumberInFile := lineNumberOfMethod + con lineNumber - 1.
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   136
            aStream nextPutAll:(' (%1:%2)'
526
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   137
                                bindWith: relPath
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   138
                                with: lineNumberInFile)
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   139
        ] ifFalse:[
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   140
            aStream nextPutAll:(' (%1)'
526
9988390f9282 lastState fixes
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   141
                                bindWith: relPath)
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   142
        ].
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
    aStream cr.
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
    "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
   147
    "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
   148
!
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   149
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   150
rememberEndTime
479
b6051320c2d1 comments
Claus Gittinger <cg@exept.de>
parents: 465
diff changeset
   151
    "remembers the endTime of the current test (in outcome)"
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   152
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   153
    ^outcome endTime: Timestamp now
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   154
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   155
    "Created: / 16-08-2011 / 17:36:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   156
!
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   157
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   158
rememberException:ex
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   159
    "common for failure and error:
677
fd06505f4d59 #OTHER by mawalch
mawalch
parents: 670
diff changeset
   160
     called when a test fails. testCase is the failed
fd06505f4d59 #OTHER by mawalch
mawalch
parents: 670
diff changeset
   161
     testcase, ex is platform specific object describing
fd06505f4d59 #OTHER by mawalch
mawalch
parents: 670
diff changeset
   162
     the failure. Actually, on all platforms except GemStone,
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   163
     ex is an instance of an exception that caused the failure"
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   164
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   165
    |backtrace|
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   166
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   167
    ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifTrue:[
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   168
        "remember the backtrace (as string, to prevent objects from being kept forwever
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   169
         from being garbage collected, the signal (i.e. the exception class) and the
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   170
         exceptions message (description).
677
fd06505f4d59 #OTHER by mawalch
mawalch
parents: 670
diff changeset
   171
         Would like to have an exceptionInfo obejct for that, but that might be hard to
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   172
         get returned back into the main stream sunit package..."
677
fd06505f4d59 #OTHER by mawalch
mawalch
parents: 670
diff changeset
   173
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   174
        backtrace := String streamContents:[:s |
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   175
                        |con topReached|
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   176
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   177
                        "could use printAllOn:s, but noone is interested in contexts above the
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   178
                         testcase's runtest context"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   179
                        topReached := false.
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   180
                        con := ex suspendedContext.
677
fd06505f4d59 #OTHER by mawalch
mawalch
parents: 670
diff changeset
   181
                        [
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   182
                            con notNil and:[topReached not]
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   183
                        ] whileTrue:[
500
b097ce6e7e84 class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   184
                            self printLineForContextForJavaCompatibleStackTrace:con on:s.
597
89fab642e33d class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   185
                            topReached := ((con selector == outcome selector) or:[con selector == #runCase])
465
0297ec178c9f changed: #rememberException:
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   186
                                          and:[con receiver == outcome
0297ec178c9f changed: #rememberException:
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   187
                                               or:[ con receiver == outcome testCase ]].
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   188
                            con := con sender.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   189
                        ]
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   190
                     ].
465
0297ec178c9f changed: #rememberException:
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   191
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   192
        outcome exceptionDetail:(Dictionary new
571
d5a1ac6d1743 use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   193
                                    at:#exception put:ex creator;
505
f624d7b45d5e class: TestResultStX
Claus Gittinger <cg@exept.de>
parents: 500
diff changeset
   194
                                    at:#description put:ex description;
345
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   195
                                    at:#backtrace put:backtrace;
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   196
                                    yourself).
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   197
        ^ self.
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   198
    ].
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   199
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   200
    "add other dialect specifics here"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   201
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   202
    "Created: / 06-08-2011 / 11:29:23 / cg"
abd1f2918992 initial checkin
vrany
parents:
diff changeset
   203
    "Created: / 16-08-2011 / 17:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
677
fd06505f4d59 #OTHER by mawalch
mawalch
parents: 670
diff changeset
   204
    "Modified (format): / 22-05-2017 / 18:26:41 / mawalch"
345
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, 
655
a949c7616b2a #OTHER by mawalch
mawalch
parents: 608
diff changeset
   228
        or better: acquire the lock and making collecting explicit via
580
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
608
dd61addf0336 class: TestResultStX
Stefan Vogel <sv@exept.de>
parents: 597
diff changeset
   233
    |savedStdout savedTranscript collector|
345
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.
608
dd61addf0336 class: TestResultStX
Stefan Vogel <sv@exept.de>
parents: 597
diff changeset
   237
    collector := CharacterWriteStream new:100.
345
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
655
a949c7616b2a #OTHER by mawalch
mawalch
parents: 608
diff changeset
   255
    ^ '$Header$'
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
655
a949c7616b2a #OTHER by mawalch
mawalch
parents: 608
diff changeset
   259
    ^ '$Header$'
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