#BUGFIX by Stefan Reise
authorsr
Thu, 06 Jun 2019 10:03:12 +0200
changeset 551e8b3552904ba
parent 550 57af1d2ef11e
child 552 815a1b5f7135
#BUGFIX by Stefan Reise
class: RunUnitTests
class definition

class: RunUnitTests class
added:20 methods

class: RunUnitTests::RunnerSelfTest
class definition
added:
#test01_shouldPass
#test02_shouldFail
#test03_shouldError
#test04_shouldError
#test05_shouldBeSkipped
quickSelfTest/RunUnitTests.st
     1.1 --- a/quickSelfTest/RunUnitTests.st	Thu Mar 28 15:57:11 2019 +0100
     1.2 +++ b/quickSelfTest/RunUnitTests.st	Thu Jun 06 10:03:12 2019 +0200
     1.3 @@ -18,32 +18,6 @@
     1.4  	privateIn:RunUnitTests
     1.5  !
     1.6  
     1.7 -!RunUnitTests::RunnerSelfTest methodsFor:'tests'!
     1.8 -
     1.9 -test01_shouldPass
    1.10 -    self assert:true.
    1.11 -!
    1.12 -
    1.13 -test02_shouldFail
    1.14 -    self assert:false.
    1.15 -!
    1.16 -
    1.17 -test03_shouldError
    1.18 -    |zero|
    1.19 -    zero := 0.
    1.20 -    self assert:(10 / zero).
    1.21 -!
    1.22 -
    1.23 -test04_shouldError
    1.24 -    self assert:(10 foo).
    1.25 -!
    1.26 -
    1.27 -test05_shouldBeSkipped
    1.28 -    self skip:'this is skipped'.
    1.29 -    self assert:(10 foo).
    1.30 -! !
    1.31 -
    1.32 -
    1.33  !RunUnitTests class methodsFor:'documentation'!
    1.34  
    1.35  documentation
    1.36 @@ -96,63 +70,63 @@
    1.37      runTestCases := OrderedCollection new.
    1.38      doRunSpecificUnitTests := false.
    1.39      unitTestSuiteName := 'All Unit Tests'.
    1.40 -    excludedUnitTestClassNames := self excludedUnitTestClassNamesForAll.
    1.41 +    excludedUnitTestClassNames := self excludedUnitTestClassNames.
    1.42      corruptedUnitTestClassNames := self corruptedUnitTestClassNames.
    1.43  
    1.44      index := arguments indexOf:'--settingsFile'.
    1.45      index > 0 ifTrue:[
    1.46 -	settingsFilePathName := arguments at:index + 1.
    1.47 -	self logInfo:'load settings file: %1' with:settingsFilePathName.
    1.48 -	settingsFilePathName asFilename fileIn.
    1.49 -	self logInfo:'makeCommand (from ParserFlags) is: %1' with:(ParserFlags makeCommand).
    1.50 +        settingsFilePathName := arguments at:index + 1.
    1.51 +        self logInfo:'load settings file: %1' with:settingsFilePathName.
    1.52 +        settingsFilePathName asFilename fileIn.
    1.53 +        self logInfo:'makeCommand (from ParserFlags) is: %1' with:(ParserFlags makeCommand).
    1.54      ].
    1.55  
    1.56      (arguments includes:'--runOnlyExpeccoUnitTests') ifTrue:[
    1.57 -	self logInfo:'configured to run expecco unit tests only'.
    1.58 -	doRunSpecificUnitTests := true.
    1.59 -	unitTestSuiteName := 'expecco Unit Tests'.
    1.60 -	excludedUnitTestClassNames := self excludedUnitTestClassNamesForExpecco.
    1.61 +        self logInfo:'configured to run expecco unit tests only'.
    1.62 +        doRunSpecificUnitTests := true.
    1.63 +        unitTestSuiteName := 'expecco Unit Tests'.
    1.64 +        excludedUnitTestClassNames := self excludedUnitTestClassNamesForExpecco.
    1.65      ].
    1.66  
    1.67      index := arguments indexOf:'--resultFile'.
    1.68      index > 0 ifTrue:[
    1.69 -	resultFilePathName := arguments at:index + 1.
    1.70 -	self logInfo:'set custom result file: %1' with:resultFilePathName.
    1.71 +        resultFilePathName := arguments at:index + 1.
    1.72 +        self logInfo:'set custom result file: %1' with:resultFilePathName.
    1.73      ].
    1.74  
    1.75      [
    1.76 -	(index := arguments indexOf:'--run') > 0
    1.77 +        (index := arguments indexOf:'--run') > 0
    1.78      ] whileTrue:[
    1.79 -	runTestCases add:(arguments at:index + 1).
    1.80 -	self logInfo:'run test: "%1"' with:(arguments at:index + 1).
    1.81 -	arguments removeIndex:index + 1.
    1.82 -	arguments removeIndex:index.
    1.83 +        runTestCases add:(arguments at:index + 1).
    1.84 +        self logInfo:'run test: "%1"' with:(arguments at:index + 1).
    1.85 +        arguments removeIndex:index + 1.
    1.86 +        arguments removeIndex:index.
    1.87      ].
    1.88  
    1.89      [
    1.90 -	(index := arguments indexOf:'--exclude') > 0
    1.91 +        (index := arguments indexOf:'--exclude') > 0
    1.92      ] whileTrue:[
    1.93 -	excludedUnitTestClassNames add:(arguments at:index + 1).
    1.94 -	self logInfo:'exclude test: "%1"' with:(arguments at:index + 1).
    1.95 -	arguments removeIndex:index + 1.
    1.96 -	arguments removeIndex:index.
    1.97 +        excludedUnitTestClassNames add:(arguments at:index + 1).
    1.98 +        self logInfo:'exclude test: "%1"' with:(arguments at:index + 1).
    1.99 +        arguments removeIndex:index + 1.
   1.100 +        arguments removeIndex:index.
   1.101      ].
   1.102  
   1.103      index := arguments indexOf:'--forceTestCase'.
   1.104      index > 0 ifTrue:[
   1.105 -	forceTestCase := arguments at:index + 1.
   1.106 -	self logInfo:'run single test (forceTestCase): "%1"' with:forceTestCase.
   1.107 +        forceTestCase := arguments at:index + 1.
   1.108 +        self logInfo:'run single test (forceTestCase): "%1"' with:forceTestCase.
   1.109      ].
   1.110  
   1.111      index := arguments indexOf:'--testRunner'.
   1.112      index > 0 ifTrue:[
   1.113 -	arguments removeIndex:index.
   1.114 -	forceTestCase := #'RunUnitTests::RunnerSelfTest'.
   1.115 -	self logInfo:'execute runner self test'.
   1.116 +        arguments removeIndex:index.
   1.117 +        forceTestCase := #'RunUnitTests::RunnerSelfTest'.
   1.118 +        self logInfo:'execute runner self test'.
   1.119      ].
   1.120  
   1.121      (doRunSpecificUnitTests not and:[forceTestCase isNil]) ifTrue:[
   1.122 -	self logInfo:'configured to run all available unit tests'.
   1.123 +        self logInfo:'configured to run all available unit tests'.
   1.124      ].
   1.125  
   1.126      "/ self logInfo:'collecting tests to run'.
   1.127 @@ -162,119 +136,120 @@
   1.128      possibleClassNames add:#'RunUnitTests::RunnerSelfTest'.
   1.129  
   1.130      possibleClassNames do:[:eachClassName |
   1.131 -	(excludedUnitTestClassNames includes:eachClassName) ifTrue:[
   1.132 -	    self logInfo:'exclude test "%1".' with:eachClassName.
   1.133 -	] ifFalse:[
   1.134 -	    (runTestCases notEmptyOrNil and:[(runTestCases includes:eachClassName) not]) ifTrue:[
   1.135 -		self logInfo:'not selected: "%1".' with:eachClassName.
   1.136 -	    ] ifFalse:[
   1.137 -		(corruptedUnitTestClassNames includes:eachClassName) ifTrue:[
   1.138 -		    self logWarning:'test "%1" is marked as corrupted, please fix' with:eachClassName.
   1.139 -		] ifFalse:[
   1.140 -		    (eachClassName notNil
   1.141 -		    and:[
   1.142 -			"/ skip non test class classes
   1.143 -			(#(
   1.144 -			    'stx_goodies_regression'
   1.145 -			) includes:eachClassName) not
   1.146 -		    and:[
   1.147 -			forceTestCase isNil
   1.148 -			or:[forceTestCase = eachClassName
   1.149 -			or:[forceTestCase = ((eachClassName subStrings:'::') lastIfEmpty:nil)]]
   1.150 -		    ]]) ifTrue:[
   1.151 -			eachClass := Smalltalk at:eachClassName.
   1.152 +        (excludedUnitTestClassNames includes:eachClassName) ifTrue:[
   1.153 +            self logInfo:'exclude test "%1".' with:eachClassName.
   1.154 +        ] ifFalse:[
   1.155 +            (runTestCases notEmptyOrNil and:[(runTestCases includes:eachClassName) not]) ifTrue:[
   1.156 +                self logInfo:'not selected: "%1".' with:eachClassName.
   1.157 +            ] ifFalse:[
   1.158 +                (corruptedUnitTestClassNames includes:eachClassName) ifTrue:[
   1.159 +                    self logWarning:'test "%1" is marked as corrupted, please fix' with:eachClassName.
   1.160 +                ] ifFalse:[
   1.161 +                    (eachClassName notNil
   1.162 +                    and:[
   1.163 +                        "/ skip non test class classes
   1.164 +                        (#(
   1.165 +                            'stx_goodies_regression'
   1.166 +                        ) includes:eachClassName) not
   1.167 +                    and:[
   1.168 +                        forceTestCase isNil
   1.169 +                        or:[forceTestCase = eachClassName
   1.170 +                        or:[forceTestCase = ((eachClassName subStrings:'::') lastIfEmpty:nil)]]
   1.171 +                    ]]) ifTrue:[
   1.172 +                        eachClass := Smalltalk at:eachClassName.
   1.173  
   1.174 -			useCompiledUnitTestClasses ifFalse:[
   1.175 -			    "here we want to test the jitter code
   1.176 -			     therfore we file in, exit if the class is already present somwhow"
   1.177 -			    eachClass notNil ifTrue:[
   1.178 -				self logWarning:'test class "%1" was already present as stc-compiled class before file in.' with:eachClassName.
   1.179 -				Smalltalk isSmalltalkDevelopmentSystem ifFalse:[
   1.180 -				    Smalltalk exit:1.
   1.181 -				].
   1.182 -			    ].
   1.183 +                        useCompiledUnitTestClasses ifFalse:[
   1.184 +                            "here we want to test the jitter code
   1.185 +                             therfore we file in, exit if the class is already present somwhow"
   1.186 +                            eachClass notNil ifTrue:[
   1.187 +                                self logWarning:'test class "%1" was already present as stc-compiled class before file in.' with:eachClassName.
   1.188 +                                Smalltalk isSmalltalkDevelopmentSystem ifFalse:[
   1.189 +                                    Smalltalk exit:1.
   1.190 +                                ].
   1.191 +                            ].
   1.192  
   1.193 -			    eachClass := Smalltalk
   1.194 -				fileInClass:eachClassName
   1.195 -				package:'stx:goodies/regression'.
   1.196 -			].
   1.197 +                            eachClass := Smalltalk
   1.198 +                                fileInClass:eachClassName
   1.199 +                                package:'stx:goodies/regression'.
   1.200 +                        ].
   1.201  
   1.202 -			eachClass notNil ifTrue:[
   1.203 -			    (eachClass isTestCaseLike
   1.204 -			    and:[eachClass isAbstract not]) ifTrue:[
   1.205 -				self logInfo:'added test "%1".' with:eachClassName.
   1.206 -				unitTestSuite addTest:eachClass suite.
   1.207 -			    ] ifFalse:[
   1.208 -				self logInfo:'not a test "%1" (abstract or something else).'
   1.209 -					with:eachClassName.
   1.210 -			    ].
   1.211 -			] ifFalse:[
   1.212 -			    self logWarning:'test class "%1" is not loaded.' with:eachClassName.
   1.213 -			].
   1.214 -		    ] ifFalse:[
   1.215 -			self logInfo:'skipped test "%1".' with:eachClassName.
   1.216 -		    ].
   1.217 -		].
   1.218 -	    ].
   1.219 -	].
   1.220 +                        eachClass notNil ifTrue:[
   1.221 +                            (eachClass isTestCaseLike
   1.222 +                            and:[eachClass isAbstract not]) ifTrue:[
   1.223 +                                self logInfo:'added test "%1".' with:eachClassName.
   1.224 +                                unitTestSuite addTest:eachClass suite.
   1.225 +                            ] ifFalse:[
   1.226 +                                self logInfo:'not a test "%1" (abstract or something else).'
   1.227 +                                        with:eachClassName.
   1.228 +                            ].
   1.229 +                        ] ifFalse:[
   1.230 +                            self logWarning:'test class "%1" is not loaded.' with:eachClassName.
   1.231 +                        ].
   1.232 +                    ] ifFalse:[
   1.233 +                        self logInfo:'skipped test "%1".' with:eachClassName.
   1.234 +                    ].
   1.235 +                ].
   1.236 +            ].
   1.237 +        ].
   1.238      ].
   1.239  
   1.240      self logInfo:'%1 unit test(s) collected' with:(unitTestSuite tests size).
   1.241  
   1.242      self logInfo:'start tests...'.
   1.243      [
   1.244 -	result :=
   1.245 -	    unitTestSuite
   1.246 -		run:TestResultStX new
   1.247 -		beforeEachDo:[:test |
   1.248 -		    self logInfo:'Run "%1"' with:test printString
   1.249 -		]
   1.250 -		afterEachDo:[:test :result|
   1.251 -		    |execTime status|
   1.252 +        result :=
   1.253 +            unitTestSuite
   1.254 +                run:TestResultStX new
   1.255 +                beforeEachDo:[:test |
   1.256 +                    self logInfo:'Run "%1"' with:test printString
   1.257 +                ]
   1.258 +                afterEachDo:[:test :result|
   1.259 +                    |execTime status|
   1.260  
   1.261 -		    execTime := result lastOutcome executionTimeDuration.
   1.262 -		    status := result lastOutcome result.
   1.263 -		    self logInfo:'   %1 (%2)' with:status with:execTime.
   1.264 -		    (status == TestResult stateFail or:[status == TestResult stateError]) ifTrue:[
   1.265 -			self logInfo:'   ==================='.
   1.266 -		    ]
   1.267 -		]
   1.268 -		debug:debug.
   1.269 +                    execTime := result lastOutcome executionTimeDuration.
   1.270 +                    status := result lastOutcome result.
   1.271 +                    self logInfo:'   %1 (%2)' with:status with:execTime.
   1.272 +                    (status == TestResult stateFail or:[status == TestResult stateError]) ifTrue:[
   1.273 +                        self logInfo:'   ==================='.
   1.274 +                    ]
   1.275 +                ]
   1.276 +                debug:debug.
   1.277      ] ifCurtailed:[
   1.278 -	self logWarning:'aborted in:.'.
   1.279 -	thisContext fullPrintAllOn:Stderr.
   1.280 +        self logWarning:'aborted in:.'.
   1.281 +        thisContext fullPrintAllOn:Stderr.
   1.282      ].
   1.283  
   1.284      self logInfo:'tests finished.'.
   1.285  
   1.286      self logInfo:'generating xml report...'.
   1.287      [
   1.288 -	TestResultReporter
   1.289 -	    report:result
   1.290 -	    format:#xml_jUnit
   1.291 -	    as:(resultFilePathName ? 'testresult.xml').
   1.292 +        TestResultReporter
   1.293 +            report:result
   1.294 +            format:#xml_jUnit
   1.295 +            as:(resultFilePathName ? 'testresult.xml').
   1.296      ] on:Error do:[:ex |
   1.297 -	self logWarning:'error while generating xml report: %1' with:ex description.
   1.298 -	self logWarning:'in: %1' with:(ex suspendedContext fullPrintAllString).
   1.299 -	Smalltalk isSmalltalkDevelopmentSystem ifFalse:[
   1.300 -	    Smalltalk exit:1.
   1.301 -	].
   1.302 +        self logWarning:'error while generating xml report: %1' with:ex description.
   1.303 +        self logWarning:'in: %1' with:(ex suspendedContext fullPrintAllString).
   1.304 +        Smalltalk isSmalltalkDevelopmentSystem ifFalse:[
   1.305 +            Smalltalk exit:1.
   1.306 +        ].
   1.307      ].
   1.308  
   1.309      self logInfo:'xml report generated in %1' with:(resultFilePathName ? 'testresult.xml') asFilename pathName.
   1.310  
   1.311      self logInfo:'Summary:'.
   1.312      self logInfo:('  %1 tests, %2 run (%3 skipped) / %4 passed, %5 failed, %6 errors'
   1.313 -		bindWith:result tests size
   1.314 -		with:result runCount
   1.315 -		with:result skippedCount
   1.316 -		with:result passedCount
   1.317 -		with:result failureCount
   1.318 -		with:result errorCount).
   1.319 +                bindWith:result tests size
   1.320 +                with:result runCount
   1.321 +                with:result skippedCount
   1.322 +                with:result passedCount
   1.323 +                with:result failureCount
   1.324 +                with:result errorCount).
   1.325      "/ self logInfo:'  exec. time: %1' with:(TimeDuration fromSeconds:result executionTime).
   1.326  
   1.327      "Modified (format): / 16-05-2018 / 13:59:47 / sr"
   1.328      "Modified: / 26-03-2019 / 19:00:38 / Claus Gittinger"
   1.329 +    "Modified: / 06-06-2019 / 10:02:52 / Stefan Reise"
   1.330  ! !
   1.331  
   1.332  !RunUnitTests class methodsFor:'constants'!
   1.333 @@ -287,35 +262,48 @@
   1.334      )
   1.335  !
   1.336  
   1.337 -excludedUnitTestClassNamesForAll
   1.338 -    ^ #(
   1.339 -	#'RegressionTests::SelectorNamespacesTests'
   1.340 -    )
   1.341 +excludedUnitTestClassNames
   1.342 +    |collection|
   1.343 +
   1.344 +    collection := OrderedCollection new.
   1.345 +    collection add:#'RegressionTests::SelectorNamespacesTests'.
   1.346 +
   1.347 +    "now exclude architecture dependent stuff"
   1.348 +    (OperatingSystem isMSWINDOWSlike not 
   1.349 +    or:[ExternalAddress pointerSize = 8]) ifTrue:[
   1.350 +        collection add:#'RegressionTests::Win32OLETests'.
   1.351 +    ].
   1.352 +
   1.353 +    ^ collection
   1.354 +
   1.355 +    "Created: / 06-06-2019 / 10:02:46 / Stefan Reise"
   1.356  !
   1.357  
   1.358  excludedUnitTestClassNamesForExpecco
   1.359 -    ^ self excludedUnitTestClassNamesForAll
   1.360 -	, #(
   1.361 -	    #'RegressionTests::VMCrashTestCase'
   1.362 -	    #'RegressionTests::VMCrashTests'
   1.363 -	    #'RegressionTests::ParserTests'
   1.364 -	    #'RegressionTests::BreakpointTests'
   1.365 -	    #'RegressionTests::SunitXMLOutputTest'
   1.366 -	    #'RegressionTests::CompilerTests2'
   1.367 -	    #'RegressionTests::BehaviorLookupObjectTests'
   1.368 -	    #'RegressionTests::ChangeSetTests'
   1.369 -	    #'RegressionTests::MakefileTests'
   1.370 -	    #'RegressionTests::MetaphoneStringComparatorTest'
   1.371 -	    #'RegressionTests::STCCompilerTests'
   1.372 -	    #'RegressionTests::VMCrashTests'
   1.373 -	    #'RegressionTests::SnapshotRestartTests'
   1.374 -	    #'RegressionTests::GraphicDrawingTest'
   1.375 -	    #'RegressionTests::OS_OLE_Tests'
   1.376 -	    #'RegressionTests::ExternalInterfaceTests'
   1.377 -	    #'RegressionTests::DebuggerTest'
   1.378 -	    #'RegressionTests::ContextTest2'
   1.379 -	    #'RegressionTests::QDoubleTests'
   1.380 -	)
   1.381 +    ^ self excludedUnitTestClassNames
   1.382 +        , #(
   1.383 +            #'RegressionTests::VMCrashTestCase'
   1.384 +            #'RegressionTests::VMCrashTests'
   1.385 +            #'RegressionTests::ParserTests'
   1.386 +            #'RegressionTests::BreakpointTests'
   1.387 +            #'RegressionTests::SunitXMLOutputTest'
   1.388 +            #'RegressionTests::CompilerTests2'
   1.389 +            #'RegressionTests::BehaviorLookupObjectTests'
   1.390 +            #'RegressionTests::ChangeSetTests'
   1.391 +            #'RegressionTests::MakefileTests'
   1.392 +            #'RegressionTests::MetaphoneStringComparatorTest'
   1.393 +            #'RegressionTests::STCCompilerTests'
   1.394 +            #'RegressionTests::VMCrashTests'
   1.395 +            #'RegressionTests::SnapshotRestartTests'
   1.396 +            #'RegressionTests::GraphicDrawingTest'
   1.397 +            #'RegressionTests::OS_OLE_Tests'
   1.398 +            #'RegressionTests::ExternalInterfaceTests'
   1.399 +            #'RegressionTests::DebuggerTest'
   1.400 +            #'RegressionTests::ContextTest2'
   1.401 +            #'RegressionTests::QDoubleTests'
   1.402 +        )
   1.403 +
   1.404 +    "Modified: / 06-06-2019 / 10:02:54 / Stefan Reise"
   1.405  ! !
   1.406  
   1.407  !RunUnitTests class methodsFor:'examples'!
   1.408 @@ -443,6 +431,31 @@
   1.409      self log:(aString bindWith:arg) type:'WARNING'
   1.410  ! !
   1.411  
   1.412 +!RunUnitTests::RunnerSelfTest methodsFor:'tests'!
   1.413 +
   1.414 +test01_shouldPass
   1.415 +    self assert:true.
   1.416 +!
   1.417 +
   1.418 +test02_shouldFail
   1.419 +    self assert:false.
   1.420 +!
   1.421 +
   1.422 +test03_shouldError
   1.423 +    |zero|
   1.424 +    zero := 0.
   1.425 +    self assert:(10 / zero).
   1.426 +!
   1.427 +
   1.428 +test04_shouldError
   1.429 +    self assert:(10 foo).
   1.430 +!
   1.431 +
   1.432 +test05_shouldBeSkipped
   1.433 +    self skip:'this is skipped'.
   1.434 +    self assert:(10 foo).
   1.435 +! !
   1.436 +
   1.437  !RunUnitTests class methodsFor:'documentation'!
   1.438  
   1.439  version
   1.440 @@ -452,3 +465,4 @@
   1.441  version_CVS
   1.442      ^ '$Header$'
   1.443  ! !
   1.444 +