TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
authorvrany
Fri, 29 Jul 2011 13:13:52 +0200
changeset 262 3c46acd3f64a
parent 261 c4cfa4b800f0
child 263 31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
TestCase.st
--- a/TestCase.st	Thu Jul 07 14:47:40 2011 +0200
+++ b/TestCase.st	Fri Jul 29 13:13:52 2011 +0200
@@ -691,32 +691,87 @@
 !
 
 run
-	| result |
-	result := TestResult new.
-	[self run: result]
-		sunitEnsure: [TestResource resetResources: self resources].
-	^result
+
+    ^self run: TestResult new
+
+    "Modified: / 29-07-2011 / 12:07:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 run: aResult
-	aResult runCase: self
+
+    ^self run: aResult beforeEachDo: [:test :result|] afterEachDo: [:test :result|]
+
+    "Modified: / 29-07-2011 / 12:07:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 run: aResult afterEachDo:block2
-	aResult runCase: self.
-	block2 value:self value:aResult.
+
+    ^self run: aResult beforeEachDo: [:test :result|] afterEachDo:block2
+
+    "Modified: / 29-07-2011 / 12:07:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 run: aResult beforeEachDo:block1 afterEachDo:block2
-	block1 value:self value:aResult.
-	aResult runCase: self.
-	block2 value:self value:aResult.
+
+    ^self run: aResult beforeEachDo:block1 afterEachDo:block2 resetResources: true
+
+    "Modified: / 29-07-2011 / 12:06:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+run: result beforeEachDo: before afterEachDo: after resetResources: reset
+
+    "Workhorse for running a testcase. If reset is true, then
+     the resources are reset, otherwise not"
+
+    "1. Execute before block"
+    "This code is ugly in Smalltalk/X but it is so because
+     it is more portable - numArgs in ANSI (?)"
+    before numArgs == 2 ifTrue:[
+        before value: self value: result                
+    ] ifFalse:[
+        before numArgs == 1 ifTrue:[
+            before value: self
+        ] ifFalse:[
+            before value.
+        ]
+    ].
+
+    "2. Run the testcase"
+    reset ifTrue:[
+        [
+            result runCase: self
+        ] sunitEnsure: [
+            TestResource resetResources: self resources
+        ].
+    ] ifFalse:[
+        result runCase: self
+    ].
+
+    "3. Execute after block"
+    "This code is ugly in Smalltalk/X but it is so because
+     it is more portable - numArgs in ANSI (?)"
+    before numArgs == 2 ifTrue:[
+        before value: self value: result                
+    ] ifFalse:[
+        before numArgs == 1 ifTrue:[
+            before value: self
+        ] ifFalse:[
+            before value.
+        ]
+    ].
+    ^result
+
+    "Created: / 29-07-2011 / 12:04:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 run: aResult beforeEachTestCaseDo:block1 afterEachTestCaseDo:block2
-	block1 value:self value:aResult.
-	aResult runCase: self.
-	block2 value:self value:aResult.
+
+    <resource: #obsolete>
+    self obsoleteMethodWarning: 'Use #run:beforeEachDo:afterEachDo: instead'.
+
+    ^self run: aResult beforeEachDo:block1 afterEachDo:block2
+
+    "Modified: / 29-07-2011 / 12:06:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 runCase
@@ -755,7 +810,7 @@
 !TestCase class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCase.st,v 1.63 2011-07-07 10:35:29 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestCase.st,v 1.64 2011-07-29 11:13:52 vrany Exp $'
 !
 
 version_SVN