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

class: stx_goodies_builder_quickSelfTest class
added:18 methods
jan@67
     1
"{ Package: 'stx:goodies/builder/reports' }"
jan@67
     2
jan@67
     3
"{ NameSpace: Builder }"
jan@67
     4
jan@67
     5
ReportFormat subclass:#TestReportFormat
jan@67
     6
	instanceVariableNames:''
jan@67
     7
	classVariableNames:''
jan@67
     8
	poolDictionaries:''
jan@67
     9
	category:'Builder-Reports-Formats'
jan@67
    10
!
jan@67
    11
jan@67
    12
TestReportFormat subclass:#JUnit
jan@104
    13
	instanceVariableNames:'position failures errors skipped startTime stopTime'
jan@67
    14
	classVariableNames:''
jan@67
    15
	poolDictionaries:''
jan@67
    16
	privateIn:TestReportFormat
jan@67
    17
!
jan@67
    18
jan@67
    19
TestReportFormat subclass:#PerfPublisher
jan@67
    20
	instanceVariableNames:''
jan@67
    21
	classVariableNames:''
jan@67
    22
	poolDictionaries:''
jan@67
    23
	privateIn:TestReportFormat
jan@67
    24
!
jan@67
    25
jan@67
    26
TestReportFormat subclass:#PythonUnittest
jan@67
    27
	instanceVariableNames:'index'
jan@67
    28
	classVariableNames:''
jan@67
    29
	poolDictionaries:''
jan@67
    30
	privateIn:TestReportFormat
jan@67
    31
!
jan@67
    32
jan@67
    33
TestReportFormat subclass:#TAP
jan@67
    34
	instanceVariableNames:'index'
jan@67
    35
	classVariableNames:''
jan@67
    36
	poolDictionaries:''
jan@67
    37
	privateIn:TestReportFormat
jan@67
    38
!
jan@67
    39
jan@67
    40
jan@67
    41
!TestReportFormat class methodsFor:'testing'!
jan@67
    42
jan@67
    43
isAbstract
jan@67
    44
jan@67
    45
    ^self == TestReportFormat
jan@67
    46
jan@67
    47
    "Created: / 04-08-2011 / 11:44:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
    48
! !
jan@67
    49
jan@67
    50
!TestReportFormat methodsFor:'accessing - defaults'!
jan@67
    51
jan@67
    52
defaultFileSuffix
jan@67
    53
    "superclass HDReportFormat says that I am responsible to implement this method"
jan@67
    54
jan@67
    55
    ^ 'xml'
jan@67
    56
jan@67
    57
    "Modified: / 04-08-2011 / 12:48:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
    58
! !
jan@67
    59
jan@67
    60
!TestReportFormat methodsFor:'writing'!
jan@67
    61
jan@67
    62
writeTestCase: testcase outcome: outcome time: time exception: exception
jan@67
    63
jan@67
    64
    | stacktrace |
jan@67
    65
    exception isNil ifTrue:[
mawalch@514
    66
        stacktrace := nil.
jan@67
    67
    ] ifFalse:[
jan@67
    68
        stacktrace :=
jan@67
    69
            (String streamContents:[:s|
jan@67
    70
                self writeStackTrace: exception of: testcase on: s
jan@67
    71
            ])
jan@67
    72
    ].
jan@67
    73
mawalch@514
    74
    ^self writeTestCase: testcase outcome: outcome time: time exception: exception
jan@67
    75
             stacktrace: stacktrace
jan@67
    76
jan@67
    77
    "Created: / 03-08-2011 / 19:44:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
    78
!
jan@67
    79
jan@67
    80
writeTestCase: testcase outcome: outcome time: time exception: exception stacktrace: stacktrace
jan@67
    81
jan@67
    82
    "Write an outcome of a given test.
jan@67
    83
     Argumments:
jan@235
    84
        testcase....the testcase <TestCase>
jan@235
    85
        outcome.....the testcase outcome <TestCaseOutcome>
jan@67
    86
        time........time taken to run the test in milliseconds
jan@235
    87
        exception...exception that caused error/failure or nil if N/A < Exception | nil >
jan@235
    88
        backtrace...stacktrace info or nil if N/A <String | nil >"
jan@67
    89
jan@67
    90
    self subclassResponsibility
jan@67
    91
jan@67
    92
    "Created: / 03-08-2011 / 19:43:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@235
    93
    "Modified (comment): / 06-06-2014 / 00:51:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
    94
! !
jan@67
    95
jan@67
    96
!TestReportFormat methodsFor:'writing - utilities'!
jan@67
    97
jan@67
    98
writeContext: context on: s
jan@67
    99
jan@67
   100
    |home mthd src|
jan@67
   101
    [
jan@67
   102
    context printOn: s.
jan@67
   103
    s cr.
jan@86
   104
    s nextPutAll:'receiver: '. context receiver printOn: s. s cr.
jan@86
   105
    s nextPutAll:'selector: '. context selector printOn: s. s cr.
jan@67
   106
    s nextPutAll:'args: '; cr.
jan@67
   107
    context args keysAndValuesDo:[:idx :eachArg |
jan@86
   108
        s nextPutAll:'  '. idx printOn: s. s nextPutAll:': '. eachArg printOn: s.s cr.
jan@67
   109
    ].
jan@67
   110
    s nextPutAll:'vars: '; cr.
jan@67
   111
    context vars keysAndValuesDo:[:idx :eachVar |
mawalch@514
   112
        s nextPutAll:'  '. idx printOn: s. s nextPutAll:': '.
jan@91
   113
        eachVar isString ifTrue:[
jan@91
   114
            eachVar storeOn: s.
jan@91
   115
        ] ifFalse:[
jan@91
   116
            eachVar printOn: s.
jan@91
   117
        ].
jan@91
   118
        s cr.
jan@67
   119
    ].
mawalch@514
   120
    s nextPutAll:'source: '; cr.
jan@67
   121
jan@67
   122
    [
jan@67
   123
    home := context methodHome.
jan@67
   124
    mthd := home method.
jan@67
   125
    mthd isNil ifTrue:[
jan@67
   126
         s nextPutAll: '** no source **'. s cr. s cr.
jan@67
   127
        ^ self.
jan@67
   128
    ].
jan@67
   129
    src := mthd source.
jan@67
   130
    src isNil ifTrue:[
jan@67
   131
        s nextPutAll: '** no source **'. s cr. s cr.
jan@67
   132
        ^ self.
jan@67
   133
    ].
jan@67
   134
    ] on: Error do:[:ex|
mawalch@514
   135
        s
jan@67
   136
            nextPutAll: '** error when getting source: ';
jan@67
   137
            nextPutAll:  ex description;
jan@67
   138
            nextPutAll: '**';
jan@67
   139
            cr; cr.
jan@67
   140
        ^ self.
jan@67
   141
    ].
jan@67
   142
    src := src asCollectionOfLines.
jan@67
   143
    src keysAndValuesDo:[:lNr :line |
jan@67
   144
        lNr == context lineNumber ifTrue:[
jan@67
   145
            s nextPutAll:'>> '.
jan@67
   146
        ] ifFalse:[
jan@67
   147
            s nextPutAll:'   '.
jan@67
   148
        ].
jan@67
   149
        s nextPutAll: line; cr.
jan@67
   150
    ].
jan@67
   151
    s cr.
jan@67
   152
    ] on: Error do:[:ex|
jan@67
   153
        s   cr;
jan@67
   154
            nextPutAll:'!!!!!!ERROR WHEN GETTING STACK TRACE!!!!!!'; cr;
jan@67
   155
            nextPutAll: ex description; cr
jan@67
   156
    ]
jan@67
   157
jan@67
   158
    "Created: / 03-08-2011 / 14:53:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   159
!
jan@67
   160
jan@67
   161
writeStackTrace:err of:aTestCase on: str
jan@67
   162
jan@91
   163
    | context stop |
jan@67
   164
jan@67
   165
    context := err signalerContext.
jan@91
   166
    stop := false.
jan@91
   167
jan@91
   168
    [ context notNil ] whileTrue:[
jan@91
   169
        self writeContext: context on: str.
jan@91
   170
        str cr; cr.
jan@91
   171
jan@91
   172
        context receiver == aTestCase ifTrue:[
jan@91
   173
            context selector == aTestCase selector ifTrue:[ ^ self ].
jan@91
   174
            context selector == #setUp ifTrue:[ ^ self ].
jan@91
   175
        ].
jan@91
   176
        context := context sender.
jan@91
   177
jan@91
   178
    ].
jan@67
   179
jan@67
   180
    "Created: / 03-08-2011 / 14:53:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   181
! !
jan@67
   182
jan@67
   183
!TestReportFormat::JUnit class methodsFor:'accessing'!
jan@67
   184
jan@67
   185
symbolicNames
jan@67
   186
    ^ #( #junit #junit40 )
jan@67
   187
jan@67
   188
    "Created: / 04-08-2011 / 11:45:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   189
! !
jan@67
   190
jan@67
   191
!TestReportFormat::JUnit class methodsFor:'documentation'!
jan@67
   192
jan@67
   193
version_SVN
jan@191
   194
    ^ '$Id$'
jan@67
   195
! !
jan@67
   196
jan@67
   197
!TestReportFormat::JUnit methodsFor:'initialization'!
jan@67
   198
jan@67
   199
initialize
jan@67
   200
jan@67
   201
    super initialize.
jan@67
   202
    errors := 0.
jan@67
   203
    failures := 0.
jan@104
   204
    skipped := 0.
jan@67
   205
jan@67
   206
    "Created: / 03-08-2011 / 15:26:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@104
   207
    "Modified: / 21-11-2012 / 15:33:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   208
! !
jan@67
   209
jan@67
   210
!TestReportFormat::JUnit methodsFor:'writing'!
jan@67
   211
jan@67
   212
writeFooter
jan@67
   213
    stopTime := OperatingSystem getMillisecondTime.
jan@67
   214
    stream
jan@67
   215
        tab;
jan@67
   216
        nextPutAll:'<system-out><!![CDATA[]]></system-out>';
jan@67
   217
        nextPut:Character lf.
jan@67
   218
    stream
jan@67
   219
        tab;
jan@67
   220
        nextPutAll:'<system-err><!![CDATA[]]></system-err>';
jan@67
   221
        nextPut:Character lf.
jan@67
   222
    stream nextPutAll:'</testsuite>'.
jan@67
   223
    stream stream position:position.
jan@67
   224
    stream
jan@67
   225
        nextPutAll:' failures="';
jan@67
   226
        print:failures;
jan@67
   227
        nextPutAll:'" errors="';
jan@67
   228
        print:errors;
jan@104
   229
        nextPutAll:'" skipped="';
jan@104
   230
        print:skipped;
jan@67
   231
        nextPutAll:'" time="';
jan@67
   232
        print:(Time milliseconds:stopTime since:startTime) / 1000.0;
jan@67
   233
        nextPutAll:'">'.
jan@67
   234
    stream close.
jan@67
   235
jan@67
   236
    "Created: / 03-08-2011 / 14:22:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@104
   237
    "Modified: / 21-11-2012 / 15:34:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   238
!
jan@67
   239
jan@67
   240
writeHeader
jan@67
   241
    stream
jan@67
   242
        nextPutAll:'<?xml version="1.0" encoding="UTF-8"?>';
jan@67
   243
        nextPut:Character lf.
jan@67
   244
    stream
jan@67
   245
        nextPutAll:'<testsuite name="';
jan@67
   246
        nextPutAll:(Report encode:report name);
jan@67
   247
        nextPutAll:'" tests="';
mawalch@514
   248
        print:report suite countTests;
jan@235
   249
        nextPutAll:('" hostname="%1"' bindWith:OperatingSystem getHostName);
jan@235
   250
        nextPutAll:'>'.
jan@67
   251
     "Now this is ugly. We want to update the time and the number of failures and errors, but still at the same time stream a valid XML. So remember this position and add some whitespace, that we can fill later."
jan@67
   252
    position := stream stream position - 1.
jan@67
   253
    stream
jan@67
   254
        nextPutAll:(String new:100 withAll:$ );
jan@67
   255
        nextPut:Character lf.
jan@235
   256
    stream
jan@235
   257
        nextPutLine: '  <properties>';
jan@235
   258
        nextPutLine: '    <property name="programmingLanguage" value="Smalltalk" />';
jan@235
   259
        nextPutLine: '    <property name="smalltalk.vendor" value="exept Software AG" />';
jan@235
   260
        nextPutLine: '    <property name="smalltalk.compiler" value="Smalltalk/X" />';
jan@235
   261
        nextPutLine:('    <property name="smalltalk.version" value="%1" />'bindWith:Smalltalk versionString);
jan@235
   262
        nextPutLine:('    <property name="os.name" value="%1" />' bindWith:OperatingSystem osName);
jan@235
   263
        nextPutLine:('    <property name="os.arch" value="%1" />' bindWith:OperatingSystem getCPUType);
jan@235
   264
        nextPutLine:('    <property name="user.name" value="%1" />' bindWith:OperatingSystem getLoginName);
jan@235
   265
        nextPutLine:('    <property name="user.language" value="%1" />' bindWith:Smalltalk language).
jan@235
   266
"/    stream
jan@235
   267
"/        nextPutLine:('    <property name="smalltalk.libbasic.version" value="%1" />'bindWith:stx_libbasic versionString).
jan@235
   268
    stream
mawalch@514
   269
        nextPutLine: '  </properties>'.
jan@235
   270
jan@67
   271
    startTime := OperatingSystem getMillisecondTime.
jan@67
   272
jan@67
   273
    "Created: / 03-08-2011 / 19:14:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@235
   274
    "Modified: / 06-06-2014 / 01:14:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   275
!
jan@67
   276
jan@67
   277
writeTestCase:testcase outcome:outcome time:time exception: exception stacktrace:stacktrace
jan@235
   278
    | result |
jan@67
   279
mawalch@319
   280
    outcome result == TestResult statePass ifTrue:[
jan@235
   281
        result := #pass.
mawalch@319
   282
    ] ifFalse:[
mawalch@319
   283
        outcome result == TestResult stateFail ifTrue:[
jan@235
   284
            result := #failure.
jan@235
   285
            failures := failures + 1
mawalch@319
   286
        ] ifFalse:[
mawalch@319
   287
            outcome result == TestResult stateError ifTrue:[
jan@235
   288
                result := #error.
jan@235
   289
                errors := errors + 1.
mawalch@319
   290
            ] ifFalse:[
mawalch@319
   291
                outcome result == TestResult stateSkip ifTrue:[
jan@235
   292
                    result := #skip.
jan@235
   293
                    skipped := skipped + 1
jan@235
   294
                ] ifFalse:[
jan@235
   295
                    self error: 'Invalid test result'.
jan@235
   296
                ]
jan@235
   297
            ].
jan@235
   298
        ].
jan@235
   299
    ].
jan@67
   300
mawalch@319
   301
    stream tab;
mawalch@319
   302
            nextPutAll: '<testcase classname="';
mawalch@319
   303
            nextPutAll: (self encode: testcase nameForHDTestReport);
mawalch@319
   304
            nextPutAll: '" name="';
mawalch@319
   305
            nextPutAll: (self encode: testcase selectorForHDTestReport);
jan@67
   306
            nextPutAll: '" time="'; print: (time ? 0) / 1000.0; nextPutAll: '">'; cr.
jan@67
   307
jan@235
   308
    result == #skip ifTrue:[
jan@104
   309
        stream tab; tab; nextPutAll: '<skipped/>'.
jan@104
   310
    ] ifFalse:[
jan@235
   311
        result ~~ #pass ifTrue:[
jan@104
   312
            | type message |
jan@67
   313
jan@104
   314
            exception isNil ifTrue:[
jan@104
   315
                type := 'unknown exception'.
mawalch@319
   316
                message := 'unknown exception occurred (no exception details available)'
jan@104
   317
            ] ifFalse:[
jan@104
   318
                type := exception class name.
jan@104
   319
                message := exception messageText ifNil:[ exception description ].
jan@104
   320
            ].
mawalch@319
   321
jan@104
   322
jan@104
   323
            stream tab; tab;
jan@235
   324
                nextPut:$<; nextPutAll: result;
jan@104
   325
                nextPutAll:' type="';
jan@104
   326
                nextPutAll:(self encode:type);
jan@104
   327
                nextPutAll:'" message="';
jan@104
   328
                nextPutAll:(self encode: message);
jan@104
   329
                nextPutAll:'"><!![CDATA['; cr.
jan@191
   330
            self writeCDATA: (stacktrace ? 'stacktrace not available').
jan@104
   331
            stream
jan@235
   332
                nextPutAll:']]></'; nextPutAll: result; nextPutAll:'>';
jan@104
   333
                nextPut:Character lf
jan@67
   334
        ].
jan@104
   335
    ].
jan@242
   336
    report keepStdout ifTrue:[
jan@242
   337
        outcome collectedOutput notEmptyOrNil ifTrue:[
jan@235
   338
            stream nextPutAll:'    <system-out><!![CDATA['; cr.
jan@235
   339
            self writeCDATA: outcome collectedOutput.
jan@235
   340
            stream nextPutAll:']]> </system-out>'; cr.
mawalch@319
   341
        ].
jan@242
   342
    ].
jan@67
   343
mawalch@319
   344
    stream tab;
jan@67
   345
            nextPutAll: '</testcase>'; cr.
jan@67
   346
jan@67
   347
jan@67
   348
    stream flush
jan@67
   349
jan@67
   350
    "Created: / 03-08-2011 / 19:42:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@248
   351
    "Modified: / 16-09-2014 / 18:55:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@191
   352
! !
jan@191
   353
jan@191
   354
!TestReportFormat::JUnit methodsFor:'writing - utilities'!
jan@191
   355
jan@191
   356
writeCDATA: string
jan@191
   357
    | start stop |
jan@191
   358
mawalch@514
   359
    start := 1.
jan@191
   360
    stop := start.
jan@191
   361
    [ (stop := (string indexOf: $] startingAt: stop)) ~~ 0 ] whileTrue:[
mawalch@514
   362
        ((stop < (string size - 1))
jan@191
   363
            and:[(string at: stop + 1) == $]
jan@191
   364
                and:[(string at: stop + 2) == $>]]) ifTrue:[
jan@191
   365
                    " Okay, found CDATA end token "
jan@191
   366
                    stream nextPutAll: string startingAt: start to: stop + 1.
jan@191
   367
                    stream nextPutAll: ']]><!![CDATA[>'.
jan@191
   368
                    start := stop := stop + 3.
jan@191
   369
                ] ifFalse:[
jan@191
   370
                    stop := stop + 1.
jan@191
   371
                ].
jan@191
   372
    ].
jan@191
   373
    start < string size ifTrue:[
mawalch@514
   374
        stream nextPutAll: string startingAt: start to: string size.
jan@191
   375
    ].
jan@191
   376
jan@191
   377
    "
jan@191
   378
    String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'ABCD']
mawalch@514
   379
    String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:']]]]']
jan@191
   380
    String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'Some <[CDATA[ CDATA ]]> Some Text and stray terminator ]]> here']
jan@191
   381
    "
jan@191
   382
jan@191
   383
    "Created: / 05-07-2013 / 16:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   384
! !
jan@67
   385
jan@67
   386
!TestReportFormat::PerfPublisher class methodsFor:'accessing'!
jan@67
   387
jan@67
   388
symbolicNames
jan@67
   389
    "Returns a collection of symbolic names for this format"
jan@67
   390
jan@67
   391
    ^ #(perfPublisher)
jan@67
   392
jan@67
   393
    "Modified: / 04-08-2011 / 11:52:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   394
! !
jan@67
   395
jan@67
   396
!TestReportFormat::PerfPublisher class methodsFor:'documentation'!
jan@67
   397
jan@67
   398
version_SVN
jan@191
   399
    ^ '$Id$'
jan@67
   400
! !
jan@67
   401
jan@67
   402
!TestReportFormat::PerfPublisher methodsFor:'writing'!
jan@67
   403
jan@67
   404
writeFooter
jan@67
   405
jan@67
   406
    stream nextPutLine: '</report>'
jan@67
   407
jan@67
   408
    "Modified: / 03-08-2011 / 20:12:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   409
!
jan@67
   410
jan@67
   411
writeHeader
jan@67
   412
jan@67
   413
    |reportName reportCategory testClass|
jan@67
   414
jan@67
   415
    reportName := report suite name.
jan@67
   416
    reportCategory := 'uncategorized'.  "/ it is a required attribute; so what should we use ?
jan@67
   417
jan@67
   418
    (testClass := Smalltalk at:reportName asSymbol) isBehavior ifTrue:[
jan@67
   419
        reportCategory := testClass category.  "/ at least, something to show
jan@67
   420
    ].
jan@67
   421
jan@67
   422
    stream
jan@67
   423
        nextPutLine: '<?xml version="1.0"?>';
jan@67
   424
        nextPutLine:('<report name="%1" categ="%2">' bindWith:reportName with:reportCategory);
jan@67
   425
        nextPutLine:('  <start>');
jan@67
   426
        nextPutLine:('    <date format="YYYYMMDD" val="%1" />' bindWith:(Date today printStringFormat:'%y%m%d'));
jan@67
   427
        nextPutLine:('    <time format="HHMMSS" val="%1" />' bindWith:(Time now printStringFormat:'%h%m%s'));
jan@67
   428
        nextPutLine:('  </start>').
jan@67
   429
jan@67
   430
    "Modified: / 03-08-2011 / 20:12:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   431
!
jan@67
   432
jan@67
   433
writeTestCase:testcase outcome:outcome time:time exception:exception stacktrace:stacktrace
jan@67
   434
jan@67
   435
    "
jan@67
   436
    Example:
jan@67
   437
    <test
jan@67
   438
        name='test_format_link_not_in_repos_with_line'
jan@67
   439
        executed='exec-status'
mawalch@514
   440
      <result>
jan@67
   441
        <success passed='result-status' state='result-state'/>
jan@67
   442
        <errorlog><!![CDATA[EXEMPLE OF ERROR LOG]]></errorlog>
mawalch@514
   443
      </result>
mawalch@514
   444
    </test>
jan@67
   445
    "
jan@67
   446
mawalch@514
   447
    |testClassName executionTime testName testDescription
jan@67
   448
     successPassed successState exceptionInfo
mawalch@514
   449
     compilerName compilerVersion compilerConfiguration compilerVersionDate
mawalch@514
   450
     timeUnit timeMeasure
jan@67
   451
     sysInfo osType osVersion cpuType|
jan@67
   452
jan@67
   453
    testClassName := testcase printString.
jan@67
   454
    testName := testcase selector.
jan@67
   455
jan@67
   456
    "most tests do not know, and return nil here!!"
jan@67
   457
    executionTime := time.    "/ millis
jan@67
   458
    testDescription := '%1-%2' bindWith:testClassName with:testName.
jan@67
   459
jan@235
   460
    successPassed := (outcome result == TestResult statePass) ifTrue:['yes'] ifFalse:['no'].
jan@235
   461
    (outcome result ~~ TestResult statePass) ifTrue:[
jan@67
   462
        exceptionInfo := stacktrace ? 'No stacktrace available'.
jan@67
   463
    ].
jan@67
   464
jan@67
   465
    successState := 'foo'.
jan@67
   466
jan@67
   467
    "/ caveat: the following needs to be made dialect-specific
jan@67
   468
    compilerName := 'Smalltalk/X'.
jan@67
   469
    compilerVersion := Smalltalk versionString.
jan@67
   470
    compilerConfiguration := Smalltalk configuration.
jan@67
   471
    compilerVersionDate := Smalltalk versionDate.
jan@67
   472
jan@67
   473
    sysInfo := OperatingSystem getSystemInfo.
jan@67
   474
    osType := (sysInfo at:#osType ifAbsent:'?').
jan@67
   475
    osVersion := (sysInfo at:#release ifAbsent:'?').
jan@67
   476
jan@67
   477
    cpuType := (sysInfo at:#cpuType ifAbsent:'?').
jan@67
   478
    "/ cpuSpeed := (sysInfo at:#cpuSpeed ifAbsent:'?').
jan@67
   479
jan@67
   480
    timeUnit := 'ms'.
jan@67
   481
    timeMeasure := executionTime.
jan@67
   482
jan@67
   483
    stream
jan@67
   484
        nextPutLine:('<test name="%1" executed="yes">' bindWith: testName);
jan@67
   485
        nextPutLine:('  <description><!![CDATA[%1]]></description>' bindWith: testDescription);
jan@67
   486
        nextPutLine:'  <platform>';
jan@67
   487
        nextPutLine:'    <os>';
jan@67
   488
        nextPutLine:('      <type><!![CDATA[%1]]></type>' bindWith:osType);
jan@67
   489
        nextPutLine:('      <version><!![CDATA[%1]]></version>' bindWith:osVersion);
jan@67
   490
        nextPutLine:'    </os>';
jan@67
   491
        nextPutLine:('    <processor arch="%1">' bindWith:cpuType);
jan@67
   492
        "/ nextPutLine:('      <frequency> unit="Mhz" cpufreq="%1" />' bindWith:cpuSpeed);
jan@67
   493
        nextPutLine:'    </processor>';
mawalch@514
   494
        nextPutLine:('    <compiler name="%1" version="%2" versiondate="%3" configuration="%4" />'
mawalch@514
   495
                            bindWith:compilerName with:compilerVersion
jan@67
   496
                            with:compilerVersionDate with:compilerConfiguration);
jan@67
   497
        "/ nextPutLine:'    <environment />';
jan@67
   498
        nextPutLine:'  </platform>';
jan@67
   499
        nextPutLine:'  <result>';
mawalch@514
   500
        nextPutLine:('    <success passed="%1" state="100" />'
jan@67
   501
                            bindWith:successPassed with:successState);
jan@67
   502
        "/ cg: in the perfPublisher documentation, I found "mesure".
jan@67
   503
        "/ I am not sure, if that was a typo, or is actually what is expected...
jan@67
   504
        "/ to be on the save side, I generate both a mesure and a measure attribute,
jan@67
   505
        "/ so it will work, even if they ever fix perfPublisher's xml parser.
mawalch@514
   506
        nextPutLine:('    <executiontime unit="%1" mesure="%2" measure="%2" isRelevant="yes" />'
jan@67
   507
                            bindWith:timeUnit with:timeMeasure).
jan@67
   508
jan@67
   509
    exceptionInfo notNil ifTrue:[
jan@67
   510
        stream
jan@67
   511
            nextPutLine:'    <errorlog><!![CDATA[';
jan@67
   512
            nextPutAll:exceptionInfo;
jan@67
   513
            nextPutLine:']]></errorlog>'.
jan@67
   514
        ].
jan@67
   515
    stream
jan@67
   516
        nextPutLine:'  </result>'.
jan@67
   517
jan@67
   518
    stream nextPutLine:'</test>'.
jan@67
   519
jan@235
   520
    "Modified: / 06-06-2014 / 00:47:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   521
! !
jan@67
   522
jan@67
   523
!TestReportFormat::PythonUnittest class methodsFor:'accessing'!
jan@67
   524
jan@67
   525
symbolicNames
jan@67
   526
    "Returns a collection of symbolic names for this format"
jan@67
   527
jan@67
   528
    ^ #(python python-unittest)
jan@67
   529
jan@67
   530
    "Modified: / 04-08-2011 / 11:52:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   531
! !
jan@67
   532
jan@67
   533
!TestReportFormat::PythonUnittest class methodsFor:'documentation'!
jan@67
   534
jan@67
   535
version_SVN
jan@191
   536
    ^ '$Id$'
jan@67
   537
! !
jan@67
   538
jan@67
   539
!TestReportFormat::PythonUnittest methodsFor:'writing'!
jan@67
   540
jan@67
   541
writeFooter
jan@67
   542
jan@67
   543
    stream
jan@67
   544
        nextPutLine: '</unittest-results>'
jan@67
   545
jan@67
   546
    "Modified: / 03-08-2011 / 20:19:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   547
!
jan@67
   548
jan@67
   549
writeHeader
jan@67
   550
jan@67
   551
    stream
jan@67
   552
        nextPutLine: '<?xml version="1.0"?>';
jan@67
   553
        nextPutLine: '<unittest-results>'.
jan@67
   554
jan@67
   555
    "Modified: / 03-08-2011 / 20:19:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   556
!
jan@67
   557
jan@67
   558
writeTestCase:testcase outcome:outcome time:time exception:exception stacktrace:stacktrace
jan@67
   559
jan@67
   560
    "
jan@67
   561
    Example:
jan@67
   562
    <test
jan@67
   563
        duration='0.0188629627228'
jan@67
   564
        status='error'
jan@67
   565
        fixture='bitten.tests.web_ui.SourceFileLinkFormatterTestCase'
jan@67
   566
        name='test_format_link_not_in_repos_with_line'
jan@67
   567
        file='/usr/src/trac-bitten-0.6b2.dfsg/bitten/tests/web_ui.py'>
jan@67
   568
    "
jan@67
   569
jan@235
   570
    | testClassName result |
jan@67
   571
jan@67
   572
    testClassName := testcase class printString.
jan@67
   573
mawalch@514
   574
    outcome result == TestResult statePass ifTrue:[
jan@235
   575
        result := #success.
mawalch@514
   576
    ] ifFalse:[
mawalch@514
   577
        outcome result == TestResult stateFail ifTrue:[
jan@235
   578
            result := #failure.
mawalch@514
   579
        ] ifFalse:[
mawalch@514
   580
            outcome result == TestResult stateError ifTrue:[
jan@235
   581
                result := #error.
mawalch@514
   582
            ] ifFalse:[
mawalch@514
   583
                outcome result == TestResult stateSkip ifTrue:[
jan@235
   584
                    result := #skip.
jan@235
   585
                ] ifFalse:[
jan@235
   586
                    self error: 'Invalid test result'.
jan@235
   587
                ]
jan@235
   588
            ].
jan@235
   589
        ].
mawalch@514
   590
    ].
jan@67
   591
jan@67
   592
    stream
mawalch@514
   593
        nextPutAll:'<test duration="'; nextPutAll:time; nextPutLine:'"';
jan@235
   594
        tab; nextPutAll:'status="'; nextPutAll: result; nextPutLine:'"';
jan@67
   595
        tab; nextPutAll:'ficture="'; nextPutAll: testClassName; nextPutLine:'"';
jan@67
   596
        tab; nextPutAll:'name="'; nextPutAll: testcase selector; nextPutLine:'"';
jan@67
   597
        "It seems that some tools requires the file attributes. So we supply one :-)"
jan@67
   598
        tab; nextPutAll:'file="'; nextPutAll: testClassName , '.st'; nextPutLine:'">'.
jan@67
   599
jan@67
   600
    outcome == #pass ifFalse:[
jan@67
   601
        stream nextPutLine:'<traceback><!![CDATA['.
jan@67
   602
        stream nextPutAll: stacktrace ? 'No stacktrace available'.
jan@67
   603
        stream nextPutLine:']]></traceback>'.
jan@67
   604
    ].
jan@67
   605
jan@67
   606
    stream nextPutLine:'</test>'.
jan@67
   607
jan@235
   608
    "Modified: / 06-06-2014 / 00:50:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   609
! !
jan@67
   610
jan@67
   611
!TestReportFormat::TAP class methodsFor:'accessing'!
jan@67
   612
jan@67
   613
symbolicNames
jan@67
   614
    "Returns a collection of symbolic names for this format"
jan@67
   615
jan@67
   616
    ^ #(tap TAP)
jan@67
   617
jan@67
   618
    "Modified: / 04-08-2011 / 11:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   619
! !
jan@67
   620
jan@67
   621
!TestReportFormat::TAP class methodsFor:'documentation'!
jan@67
   622
jan@67
   623
version_SVN
jan@191
   624
    ^ '$Id$'
jan@67
   625
! !
jan@67
   626
jan@67
   627
!TestReportFormat::TAP methodsFor:'accessing - defaults'!
jan@67
   628
jan@67
   629
defaultFileSuffix
jan@67
   630
    "superclass HDReportFormat says that I am responsible to implement this method"
jan@67
   631
jan@67
   632
    ^ 'tap'
jan@67
   633
jan@67
   634
    "Modified: / 04-08-2011 / 12:47:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   635
! !
jan@67
   636
jan@67
   637
!TestReportFormat::TAP methodsFor:'writing'!
jan@67
   638
jan@67
   639
writeFooter
jan@67
   640
jan@67
   641
    "nothing to do"
jan@67
   642
jan@67
   643
    "Modified: / 03-08-2011 / 20:05:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   644
!
jan@67
   645
jan@67
   646
writeHeader
jan@67
   647
mawalch@514
   648
    stream nextPutAll: '1..'; nextPutAll: report suite countTests printString; cr.
jan@67
   649
    index := 0
jan@67
   650
jan@67
   651
    "Modified: / 04-08-2011 / 13:49:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   652
!
jan@67
   653
jan@67
   654
writeTestCase:testcase outcome:outcome time:time exception:exception stacktrace:stacktrace
jan@67
   655
jan@235
   656
    | result testDescription statusString |
jan@67
   657
jan@67
   658
    index := index + 1.
mawalch@514
   659
    outcome result == TestResult statePass ifTrue:[
jan@235
   660
        result := #pass.
mawalch@514
   661
    ] ifFalse:[
mawalch@514
   662
        outcome result == TestResult stateFail ifTrue:[
jan@235
   663
            result := #failure.
mawalch@514
   664
        ] ifFalse:[
mawalch@514
   665
            outcome result == TestResult stateError ifTrue:[
jan@235
   666
                result := #error.
mawalch@514
   667
            ] ifFalse:[
mawalch@514
   668
                outcome result == TestResult stateSkip ifTrue:[
jan@235
   669
                    result := #skip.
jan@235
   670
                ] ifFalse:[
jan@235
   671
                    self error: 'Invalid test result'.
jan@235
   672
                ]
jan@235
   673
            ].
jan@235
   674
        ].
mawalch@514
   675
    ].
jan@67
   676
jan@67
   677
    testDescription := '%1-%2 (%3ms)'
jan@67
   678
                            bindWith:testcase printString
jan@67
   679
                            with:testcase selector
jan@67
   680
                            with:time.
jan@67
   681
jan@235
   682
    statusString := (result == #pass)
jan@67
   683
                        ifTrue:['ok']
jan@67
   684
                        ifFalse:['not ok'].
jan@67
   685
jan@67
   686
    stream nextPutLine:('%1 %2 - %3'
jan@67
   687
                            bindWith:statusString
jan@67
   688
                            with:index
jan@67
   689
                            with:testDescription).
jan@67
   690
jan@235
   691
    "Modified: / 06-06-2014 / 00:46:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@67
   692
! !
jan@67
   693
jan@67
   694
!TestReportFormat class methodsFor:'documentation'!
jan@67
   695
jan@67
   696
version
jan@67
   697
    ^ '$Header$'
jan@67
   698
!
jan@67
   699
jan@67
   700
version_CVS
jan@67
   701
    ^ '$Header$'
jan@67
   702
!
jan@67
   703
jan@67
   704
version_SVN
jan@191
   705
    ^ '$Id$'
jan@67
   706
! !
jan@191
   707