#FEATURE by cg
class: TestCase
added: #invokeTestMethod
changed: #performTest
support timeout annotation
--- a/TestCase.st Thu Mar 28 15:25:17 2019 +0100
+++ b/TestCase.st Wed May 29 01:12:49 2019 +0200
@@ -746,22 +746,49 @@
^false.
!
+invokeTestMethod
+ self perform: testSelector sunitAsSymbol
+
+ "Created: / 29-05-2019 / 00:40:03 / Claus Gittinger"
+!
+
performTest
+ <modifier: #super> "must be called if redefined"
+
"handle unimplemented #should message,
so we can write:
- somthing should be:expectedResult
+ something should be:expectedResult
"
-
MessageNotUnderstood handle:[:ex |
ex selector == #should ifTrue:[
ex proceedWith:( Should new testCase:self; value:ex receiver )
].
ex reject.
- ] do:[
- self perform: testSelector sunitAsSymbol
+ ] do:[
+ |mthd timeoutAllotation maxSecondsToRun timeoutOccurred|
+
+ timeoutOccurred := false.
+ mthd := self class lookupMethodFor:testSelector.
+ mthd notNil ifTrue:[
+ (timeoutAllotation := mthd annotationAt:#timeout:) notNil ifTrue:[
+ (maxSecondsToRun := timeoutAllotation argumentAt:1 ifAbsent:[nil]) isNil ifTrue:[
+ Logger warning:'bad timeout annotation in %1' with:mthd whoString.
+ ].
+ ].
+ ].
+ maxSecondsToRun notNil ifTrue:[
+ [
+ self invokeTestMethod
+ ] valueWithWatchDog:[timeoutOccurred := true] afterMilliseconds:(maxSecondsToRun * 1000).
+ ] ifFalse:[
+ self invokeTestMethod
+ ].
+ timeoutOccurred ifTrue:[
+ self halt.
+ ].
].
- "Modified: / 01-07-2018 / 12:12:10 / Claus Gittinger"
+ "Modified: / 29-05-2019 / 00:51:42 / Claus Gittinger"
!
safeTearDown