quickSelfTest/RunUnitTests.st
author Claus Gittinger <cg@exept.de>
Thu, 28 Mar 2019 13:54:38 +0100
changeset 542 aa25a71be62a
parent 539 532fab2fb2a5
child 544 fda58d35b323
permissions -rw-r--r--
#DOCUMENTATION by cg
class: stx_goodies_builder_quickSelfTest
class definition

class: stx_goodies_builder_quickSelfTest class
added:18 methods
sr@448
     1
"{ Encoding: utf8 }"
sr@448
     2
sr@350
     3
"{ Package: 'stx:goodies/builder/quickSelfTest' }"
sr@330
     4
sr@330
     5
"{ NameSpace: Smalltalk }"
sr@330
     6
sr@330
     7
Object subclass:#RunUnitTests
sr@330
     8
	instanceVariableNames:''
sr@330
     9
	classVariableNames:''
sr@330
    10
	poolDictionaries:''
sr@330
    11
	category:'tests-Regression'
sr@330
    12
!
sr@330
    13
sr@330
    14
!RunUnitTests class methodsFor:'documentation'!
sr@330
    15
sr@330
    16
documentation
sr@330
    17
"
cg@539
    18
    typically invoked by RunUnitTestsStart
sr@330
    19
sr@330
    20
    [author:]
cg@539
    21
        sr
sr@330
    22
sr@330
    23
    [instance variables:]
sr@330
    24
sr@330
    25
    [class variables:]
sr@330
    26
sr@330
    27
    [see also:]
sr@330
    28
sr@330
    29
"
sr@330
    30
! !
sr@330
    31
sr@330
    32
!RunUnitTests class methodsFor:'actions'!
sr@330
    33
sr@330
    34
run
sr@401
    35
    self runWithCompiledUnitTestClasses:false.
sr@399
    36
!
sr@399
    37
sr@399
    38
runWithCompiledUnitTestClasses:useCompiledUnitTestClasses
sr@427
    39
    |cmdArgs|
sr@427
    40
sr@427
    41
    cmdArgs := Smalltalk commandLineArguments.
sv@515
    42
sv@515
    43
    self
sv@515
    44
	runWithCompiledUnitTestClasses:useCompiledUnitTestClasses
sv@515
    45
	arguments:cmdArgs
sv@515
    46
	debug:(cmdArgs includes:'--debug')
sr@427
    47
!
sr@427
    48
sr@427
    49
runWithCompiledUnitTestClasses:useCompiledUnitTestClasses
cg@539
    50
    arguments:argumentsIn
sr@427
    51
    debug:debug
sr@427
    52
cg@539
    53
    |arguments
cg@539
    54
     doRunSpecificUnitTests unitTestSuiteName excludedUnitTestClassNames corruptedUnitTestClassNames
sr@399
    55
     unitTestSuite
sr@428
    56
     eachClass
sr@420
    57
     result index
cg@539
    58
     settingsFilePathName resultFilePathName forceTestCase runTestCases|
sr@399
    59
cg@539
    60
    arguments := argumentsIn asOrderedCollection.
cg@539
    61
cg@539
    62
    runTestCases := OrderedCollection new.
sr@399
    63
    doRunSpecificUnitTests := false.
sr@399
    64
    unitTestSuiteName := 'All Unit Tests'.
sr@399
    65
    excludedUnitTestClassNames := self excludedUnitTestClassNamesForAll.
sr@399
    66
    corruptedUnitTestClassNames := self corruptedUnitTestClassNames.
sr@399
    67
sr@448
    68
    index := arguments indexOf:'--settingsFile'.
sr@399
    69
    index > 0 ifTrue:[
sr@516
    70
        settingsFilePathName := arguments at:index + 1.
sr@516
    71
        self logInfo:'load settings file: ', settingsFilePathName printString.
sr@516
    72
        settingsFilePathName asFilename fileIn.
sr@516
    73
        self logInfo:'ParserFlags makeCommand: ', ParserFlags makeCommand printString.
sr@419
    74
    ].
sr@419
    75
sr@448
    76
    (arguments includes:'--runOnlyExpeccoUnitTests') ifTrue:[
sr@516
    77
        self logInfo:'configured to run expecco unit tests only'.
sr@516
    78
        doRunSpecificUnitTests := true.
sr@516
    79
        unitTestSuiteName := 'expecco Unit Tests'.
sr@516
    80
        excludedUnitTestClassNames := self excludedUnitTestClassNamesForExpecco.
sr@399
    81
    ].
sr@399
    82
sr@448
    83
    index := arguments indexOf:'--resultFile'.
sr@414
    84
    index > 0 ifTrue:[
sr@516
    85
        resultFilePathName := arguments at:index + 1.
sr@516
    86
        self logInfo:'set custom result file: ', resultFilePathName printString.
sr@414
    87
    ].
sr@414
    88
cg@539
    89
    [   
cg@539
    90
        (index := arguments indexOf:'--run') > 0 
cg@539
    91
    ] whileTrue:[
cg@539
    92
        runTestCases add:(arguments at:index + 1).
cg@539
    93
        self logInfo:'run test case: ', (arguments at:index + 1) printString.
cg@539
    94
        arguments removeIndex:index + 1.
cg@539
    95
        arguments removeIndex:index.
cg@539
    96
    ].
cg@539
    97
    
sr@448
    98
    index := arguments indexOf:'--forceTestCase'.
sr@419
    99
    index > 0 ifTrue:[
sr@516
   100
        forceTestCase := arguments at:index + 1.
sr@516
   101
        self logInfo:'set force test case: ', forceTestCase printString.
sr@420
   102
    ].
sr@399
   103
sr@399
   104
    doRunSpecificUnitTests ifFalse:[
sr@516
   105
        self logInfo:'configured to run all available unit tests'.
sr@399
   106
    ].
sr@399
   107
sr@399
   108
    self logInfo:'collecting unit test classes to run'.
sr@399
   109
    unitTestSuite := TestSuite named:unitTestSuiteName.
sr@399
   110
sr@428
   111
    (Smalltalk at: #'stx_goodies_regression') classNames do:[:eachClassName |
sr@516
   112
        (excludedUnitTestClassNames includes:eachClassName) ifTrue:[
sr@516
   113
            self
sr@516
   114
                logInfo:('excluded unit test class "%1".'
sr@516
   115
                    bindWith:eachClassName).
sr@516
   116
        ] ifFalse:[
sr@516
   117
            (corruptedUnitTestClassNames includes:eachClassName) ifTrue:[
sr@516
   118
                self
sr@516
   119
                    logWarning:('RunUnitTest: unit test class is marked as corrupted, please fix #%1'
sr@516
   120
                        bindWith:eachClassName).
sr@516
   121
            ] ifFalse:[
sr@516
   122
                (eachClassName notNil
sr@516
   123
                and:[
sr@516
   124
                    "/ skip non test case classes
sr@516
   125
                    (#(
sr@516
   126
                        'stx_goodies_regression'
sr@516
   127
                    ) includes:eachClassName) not
sr@516
   128
                and:[
sr@516
   129
                    forceTestCase isNil
sr@516
   130
                    or:[forceTestCase = eachClassName
sr@516
   131
                    or:[forceTestCase = ((eachClassName subStrings:'::') lastIfEmpty:nil)]]
sr@516
   132
                ]]) ifTrue:[
sr@516
   133
                    eachClass := Smalltalk at:eachClassName.
sr@408
   134
sr@516
   135
                    useCompiledUnitTestClasses ifFalse:[
sr@516
   136
                        "here we want test the jitter code
sr@516
   137
                         therfor we file in, exit if the class is already present somwhow"
sr@516
   138
                        eachClass notNil ifTrue:[
sr@516
   139
                            self
sr@516
   140
                                logWarning:('Unit test class "%1" was already present before file in.'
sr@516
   141
                                    bindWith:eachClassName).
sr@408
   142
sr@516
   143
                            Smalltalk exit:1.
sr@516
   144
                        ].
sr@408
   145
sr@516
   146
                        eachClass := Smalltalk
sr@516
   147
                            fileInClass:eachClassName
sr@516
   148
                            package:'stx:goodies/regression'.
sr@516
   149
                    ].
sr@399
   150
sr@516
   151
                    eachClass notNil ifTrue:[
sr@516
   152
                        (eachClass isTestCaseLike
sr@516
   153
                        and:[eachClass isAbstract not]) ifTrue:[
sr@516
   154
                            self
sr@516
   155
                                logInfo:('added unit test class "%1".'
sr@516
   156
                                    bindWith:eachClassName).
sr@423
   157
sr@516
   158
                            unitTestSuite addTest:eachClass suite.
sr@516
   159
                        ] ifFalse:[
sr@516
   160
                            self
sr@516
   161
                                logInfo:('not a unit test class "%1" (class is abstract or something else).'
sr@516
   162
                                    bindWith:eachClassName).
sr@516
   163
                        ].
sr@516
   164
                    ] ifFalse:[
sr@516
   165
                        self
sr@516
   166
                            logWarning:('unit test class "%1" is not loaded.'
sr@516
   167
                                bindWith:eachClassName).
sr@516
   168
                    ].
sr@516
   169
                ] ifFalse:[
sr@516
   170
                    self
sr@516
   171
                        logInfo:('skipped unit test class "%1".'
sr@516
   172
                            bindWith:eachClassName).
sr@516
   173
                ].
sr@516
   174
            ].
sr@516
   175
        ].
sr@399
   176
    ].
sr@399
   177
sr@399
   178
    self
sr@516
   179
        logInfo:('%1 unit test classes collected'
sr@516
   180
            bindWith:unitTestSuite tests size).
sr@399
   181
cg@539
   182
    self logInfo:'start tests...'.
sr@399
   183
    result := unitTestSuite
sr@516
   184
        run:TestResultStX new
sr@516
   185
        beforeEachDo:[:test | self logInfo:'performing unit test ', test printString]
sr@516
   186
        afterEachDo:[:test| ]
sr@516
   187
        debug:debug.
sr@399
   188
cg@539
   189
    self logInfo:'tests finished.'.
cg@539
   190
    
cg@539
   191
    self logInfo:'generating xml report...'.
sr@399
   192
    TestResultReporter
sr@516
   193
        report:result
sr@516
   194
        format:#xml_jUnit
sr@516
   195
        as:resultFilePathName ? 'testresult.xml'.
sr@399
   196
cg@539
   197
    self logInfo:('xml report in %1' bindWith:(resultFilePathName ? 'testresult.xml') asFilename pathName).
cg@539
   198
cg@539
   199
    self logInfo:'Summary:'.
cg@539
   200
    self logInfo:('%1 tests' bindWith:result tests size).
cg@539
   201
    self logInfo:('%1 run' bindWith:result runCount).
cg@539
   202
    self logInfo:('%1 skipped' bindWith:result skippedCount).
sr@399
   203
    self logInfo:('%1 passed' bindWith:result passedCount).
sr@399
   204
    self logInfo:('%1 failed' bindWith:result failureCount).
sr@399
   205
    self logInfo:('%1 errors' bindWith:result errorCount).
sr@516
   206
sr@516
   207
    "Modified (format): / 16-05-2018 / 13:59:47 / sr"
cg@539
   208
    "Modified: / 26-03-2019 / 19:00:38 / Claus Gittinger"
sr@330
   209
! !
sr@330
   210
sr@330
   211
!RunUnitTests class methodsFor:'constants'!
sr@330
   212
sr@330
   213
corruptedUnitTestClassNames
sr@330
   214
    ^ #(
sr@337
   215
	#'RegressionTests::ExternalInterfaceTests'
sr@337
   216
	#'RegressionTests::DebuggerTest'
sr@346
   217
	#'RegressionTests::ContextTest2'
sr@330
   218
    )
sr@330
   219
!
sr@330
   220
sr@330
   221
excludedUnitTestClassNamesForAll
sr@420
   222
    ^ #(
sr@420
   223
	#'RegressionTests::SelectorNamespacesTests'
sr@420
   224
    )
sr@330
   225
!
sr@330
   226
sr@337
   227
excludedUnitTestClassNamesForExpecco
sr@330
   228
    ^ self excludedUnitTestClassNamesForAll
sr@411
   229
	, #(
sr@425
   230
	    #'RegressionTests::VMCrashTestCase'
sr@420
   231
	    #'RegressionTests::VMCrashTests'
sr@421
   232
	    #'RegressionTests::ParserTests'
sr@411
   233
	    #'RegressionTests::BreakpointTests'
sr@411
   234
	    #'RegressionTests::SunitXMLOutputTest'
sr@411
   235
	    #'RegressionTests::CompilerTests2'
sr@411
   236
	    #'RegressionTests::BehaviorLookupObjectTests'
sr@411
   237
	    #'RegressionTests::ChangeSetTests'
sr@411
   238
	    #'RegressionTests::MakefileTests'
sr@411
   239
	    #'RegressionTests::MetaphoneStringComparatorTest'
sr@411
   240
	    #'RegressionTests::STCCompilerTests'
sr@411
   241
	    #'RegressionTests::VMCrashTests'
sr@411
   242
	    #'RegressionTests::SnapshotRestartTests'
sr@411
   243
	    #'RegressionTests::GraphicDrawingTest'
sr@411
   244
	    #'RegressionTests::OS_OLE_Tests'
sr@411
   245
	    #'RegressionTests::ExternalInterfaceTests'
sr@411
   246
	    #'RegressionTests::DebuggerTest'
sr@411
   247
	    #'RegressionTests::ContextTest2'
sr@416
   248
	    #'RegressionTests::QDoubleTests'
sr@411
   249
	)
sr@330
   250
! !
sr@330
   251
sr@429
   252
!RunUnitTests class methodsFor:'examples'!
sr@429
   253
sr@429
   254
example1
sr@429
   255
    Processor activeProcess exceptionHandlerSet
sv@515
   256
	on:Class updateChangeFileQuerySignal
sv@515
   257
	do:[:ex | ex proceedWith:false].
sr@429
   258
sr@429
   259
    self
sv@515
   260
	runWithCompiledUnitTestClasses:true
sv@515
   261
	arguments:#(
sv@515
   262
	    '--runOnlyExpeccoUnitTests'
sv@515
   263
	    '--forceTestCase'
sv@515
   264
	    'ExternalStreamTest'
sv@515
   265
	)
sv@515
   266
	debug:true
cg@539
   267
!
cg@539
   268
cg@539
   269
example2
cg@539
   270
    Processor activeProcess exceptionHandlerSet
cg@539
   271
        on:Class updateChangeFileQuerySignal
cg@539
   272
        do:[:ex | ex proceedWith:false].
cg@539
   273
cg@539
   274
    self
cg@539
   275
        runWithCompiledUnitTestClasses:true
cg@539
   276
        arguments:#(
cg@539
   277
            '--forceTestCase'
cg@539
   278
            'RegressionTests::ExternalStreamTest'
cg@539
   279
        )
cg@539
   280
        debug:true
cg@539
   281
cg@539
   282
    "Created: / 26-03-2019 / 18:46:46 / Claus Gittinger"
cg@539
   283
!
cg@539
   284
cg@539
   285
example2b
cg@539
   286
    Processor activeProcess exceptionHandlerSet
cg@539
   287
        on:Class updateChangeFileQuerySignal
cg@539
   288
        do:[:ex | ex proceedWith:false].
cg@539
   289
cg@539
   290
    self
cg@539
   291
        runWithCompiledUnitTestClasses:true
cg@539
   292
        arguments:#(
cg@539
   293
            '--forceTestCase'
cg@539
   294
            'ExternalStreamTest'
cg@539
   295
        )
cg@539
   296
        debug:true
cg@539
   297
cg@539
   298
    "Created: / 26-03-2019 / 18:55:46 / Claus Gittinger"
cg@539
   299
!
cg@539
   300
cg@539
   301
example2c
cg@539
   302
    Processor activeProcess exceptionHandlerSet
cg@539
   303
        on:Class updateChangeFileQuerySignal
cg@539
   304
        do:[:ex | ex proceedWith:false].
cg@539
   305
cg@539
   306
    self
cg@539
   307
        runWithCompiledUnitTestClasses:true
cg@539
   308
        arguments:#(
cg@539
   309
            '--forceTestCase'
cg@539
   310
            'CRCTests'
cg@539
   311
        )
cg@539
   312
        debug:true
cg@539
   313
cg@539
   314
    "Created: / 26-03-2019 / 18:58:36 / Claus Gittinger"
cg@539
   315
!
cg@539
   316
cg@539
   317
example3
cg@539
   318
    Processor activeProcess exceptionHandlerSet
cg@539
   319
        on:Class updateChangeFileQuerySignal
cg@539
   320
        do:[:ex | ex proceedWith:false].
cg@539
   321
cg@539
   322
    self
cg@539
   323
        runWithCompiledUnitTestClasses:true
cg@539
   324
        arguments:#(
cg@539
   325
            '--run'
cg@539
   326
            'ExternalStreamTest'
cg@539
   327
        )
cg@539
   328
        debug:true
cg@539
   329
cg@539
   330
    "Created: / 26-03-2019 / 18:51:42 / Claus Gittinger"
sr@429
   331
! !
sr@429
   332
sr@330
   333
!RunUnitTests class methodsFor:'logging'!
sr@330
   334
cg@539
   335
log:aString type:aType
cg@539
   336
    Transcript notNil ifTrue:[
cg@539
   337
        Transcript showCR:'%1 [%2] : %3'
cg@539
   338
                with:Timestamp now printString
cg@539
   339
                with:(aType printString asLowercase paddedTo:'warning' size)
cg@539
   340
                with:aString.
cg@539
   341
        ^ self       
cg@539
   342
    ].    
cg@539
   343
    Stderr showCR:'%1 [%2] : %3'
cg@539
   344
            with:Timestamp now printString
cg@539
   345
            with:(aType printString asLowercase paddedTo:'warning' size)
cg@539
   346
            with:aString.
sr@330
   347
cg@539
   348
    "Modified: / 26-03-2019 / 18:53:48 / Claus Gittinger"
sr@330
   349
!
sr@330
   350
sr@330
   351
logInfo:aString
sr@330
   352
    self
sr@337
   353
	log:aString
sr@337
   354
	type:'INFO'
sr@330
   355
!
sr@330
   356
sr@330
   357
logWarning:aString
sr@330
   358
    self
sr@337
   359
	log:aString
sr@337
   360
	type:'WARNING'
sr@330
   361
! !
sr@350
   362
sr@350
   363
!RunUnitTests class methodsFor:'documentation'!
sr@350
   364
sr@400
   365
version
sr@400
   366
    ^ '$Header$'
sr@400
   367
!
sr@400
   368
sr@350
   369
version_CVS
sr@350
   370
    ^ '$Header$'
sr@350
   371
! !
sr@516
   372