TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
authorvrany
Fri, 29 Jul 2011 13:14:04 +0200
changeset 263 31c7107b5edd
parent 262 3c46acd3f64a
child 264 aa6c9be711f5
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
TestSuite.st
--- a/TestSuite.st	Fri Jul 29 13:13:52 2011 +0200
+++ b/TestSuite.st	Fri Jul 29 13:14:04 2011 +0200
@@ -102,104 +102,57 @@
 !TestSuite methodsFor:'running'!
 
 run
-	| result |
-	result := TestResult new.
-	[self run: result]
-		"sunitEnsure: [self resources reverseDo: [:each | each reset]]."
-			sunitEnsure: [TestResource resetResources: self resources].
-	^result
 
-    "Modified: / 11-09-2010 / 16:47:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    ^self run: TestResult new.
+
+    "Modified: / 29-07-2011 / 09:34:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-run:aResult
+run:aTestResult
 
-    aResult name:name.
-    self tests do:[:each |
-	self sunitChanged:each.
-	each run:aResult
-    ]
+    ^self run: aTestResult 
+        beforeEachDo: [:test :result|] 
+        afterEachDo: [:test :result|]
 
-    "Modified: / 19-03-2010 / 08:03:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-07-2011 / 09:59:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-run: aResult afterEachDo:block2
-
-    aResult name: name.
-    self tests do:
-	[:each |
-	self changed: each.
-	each run: aResult afterEachDo:block2]
+run:result beforeEachDo: before afterEachDo: after
 
-    "Modified: / 21-06-2000 / 10:14:01 / Sames"
-    "Modified: / 19-03-2010 / 08:01:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-run:aResult beforeEachDo:block1 afterEachDo:block2
-    |class|
-
-    aResult name: name.
-    class := name ifNotNil:[ Smalltalk classNamed:name ] ifNil:[ nil ].
-    class ifNotNil:[ class perform:#setUp ifNotUnderstood:nil ].
+    result name:name.
     [
         self tests do:[:each |
             self sunitChanged:each.
-            "/ block1 value:each value:aResult.  - do not call it twice
-            each
-                run:aResult
-                beforeEachDo:block1
-                afterEachDo:block2.
+            each run:result 
+                beforeEachDo: before 
+                afterEachDo: after 
+                resetResources: false "I'll reset it, see the ensure below"            
+        ]
+    ] sunitEnsure:[
+        TestResource resetResources: self resources
+    ].
 
-            "/ each run: aResult.
-            "/ block2 value:each value:aResult.  - do not call it twice
-        ].
-    ] ensure:[
-        self resources do:[:e |
-            e reset
-        ]
-    ].
-    class ifNotNil:[ class perform:#tearDown ifNotUnderstood:nil ]
+    ^result
 
-    "Modified: / 19-03-2010 / 08:02:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 06-07-2011 / 14:24:45 / cg"
+    "Modified: / 29-07-2011 / 12:09:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 run:aResult beforeEachTestCaseDo:block1 afterEachTestCaseDo:block2
 
-    aResult name: name.
-    self tests do:[:each |
-	self changed:each.
-	each
-	    run:aResult
-	    beforeEachTestCaseDo:block1
-	    afterEachTestCaseDo:block2.
-    ]
+    <resource: #obsolete>
 
-    "Modified: / 19-03-2010 / 08:02:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+    ^self run: aResult beforeEachDo: block1 afterEachDo: block2
 
-runAfterEachDo: aBlock
-	| result |
-	result := TestResult new.
-	result name: name.
-	[self run: result afterEachDo: aBlock]
-		sunitEnsure: [self resources reverseDo: [:each | each reset]].
-	^result
-
-    "Created: / 15-03-2010 / 20:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-03-2010 / 08:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-07-2011 / 09:49:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 runBeforeEachDo:block1 afterEachDo: block2
-        | result |
-        result := TestResult new.
-        result name: name.
-        [self run: result beforeEachDo:block1 afterEachDo: block2]
-                sunitEnsure: [self resources reverseDo: [:each | each reset]].
-        ^result
+
+    ^self run: TestResult new beforeEachDo: block1 afterEachDo: block2
 
-    "Modified: / 19-03-2010 / 08:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Created: / 05-07-2011 / 16:51:25 / cg"
+    "Modified: / 29-07-2011 / 09:51:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !TestSuite methodsFor:'testing'!
@@ -222,7 +175,7 @@
 !TestSuite class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestSuite.st,v 1.21 2011-07-06 12:29:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestSuite.st,v 1.22 2011-07-29 11:14:04 vrany Exp $'
 !
 
 version_SVN