class: TestResource expecco_2_5_0 expecco_2_5_1 stable
authorClaus Gittinger <cg@exept.de>
Wed, 17 Apr 2013 20:42:06 +0200
changeset 569 edb941b33667
parent 568 49eafe2c5ae8
child 570 c9c4c97948cc
class: TestResource changed: #makeAvailable only do a tearDown, if the previous setup was executed (i.e. no tearDown, if an error happened during setup)
TestResource.st
--- a/TestResource.st	Tue Apr 16 20:09:01 2013 +0200
+++ b/TestResource.st	Wed Apr 17 20:42:06 2013 +0200
@@ -73,21 +73,35 @@
 !TestResource class methodsFor:'others'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestResource.st,v 1.9 2012-08-02 20:55:46 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestResource.st,v 1.10 2013-04-17 18:42:06 cg Exp $'
 ! !
 
 !TestResource class methodsFor:'private'!
 
 makeAvailable
-	"This method must be the _only_ way to set a notNil value for the unique instance (current).  First, obtain a candidate instance and set current to a notNil placeholder (any notNil object not an instance of me would do;  this version uses false).  Next, check any subordinate resources needed by this resource.  Lastly, setUp the candidate and put it in current if it is available, ensuring that it is torn down otherwise."
+    "This method must be the _only_ way to set a notNil value for the unique instance (current).  First, obtain a candidate instance and set current to a notNil placeholder (any notNil object not an instance of me would do;  this version uses false).  Next, check any subordinate resources needed by this resource.  Lastly, setUp the candidate and put it in current if it is available, ensuring that it is torn down otherwise."
+    
+    |candidate didSetup|
 
-	| candidate |
-	current := false.
-	candidate := self new.
-	self resources do: [:each | each availableFor: candidate].
-	[candidate setUp.
-	candidate isAvailable ifTrue: [current := candidate]]
-		sunitEnsure: [current == candidate ifFalse: [candidate tearDown]].
+    current := false.
+    candidate := self new.
+    self resources do:[:each | 
+        each availableFor:candidate
+    ].
+    [
+        didSetup := false.
+        candidate setUp.
+        didSetup := false.
+        candidate isAvailable ifTrue:[
+            current := candidate
+        ]
+    ] sunitEnsure:[
+        didSetup ifTrue:[
+            current == candidate ifFalse:[
+                candidate tearDown
+            ]
+        ]
+    ].
 !
 
 resetOrAddResourcesTo: aCollection
@@ -228,9 +242,10 @@
 !TestResource class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestResource.st,v 1.9 2012-08-02 20:55:46 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/goodies/sunit/TestResource.st,v 1.10 2013-04-17 18:42:06 cg Exp $'
 !
 
 version_SVN
     ^ '§Id: TestResource.st 204 2010-09-11 15:21:51Z vranyj1 §'
 ! !
+