Nicolas Petton 11 лет назад
Родитель
Сommit
512b87c89d
3 измененных файлов с 134 добавлено и 87 удалено
  1. 35 24
      js/SUnit.deploy.js
  2. 55 39
      js/SUnit.js
  3. 44 24
      st/SUnit.st

+ 35 - 24
js/SUnit.deploy.js

@@ -74,7 +74,7 @@ fn: function (aBlock){
 var self=this;
 var $2,$1;
 var c;
-smalltalk.send(self,"_mustBeAsync_",["#async"]);
+smalltalk.send(self,"_errorIfNotAsync_",["#async"]);
 c=self["@context"];
 $1=(function(){
 $2=smalltalk.send(self,"_isAsync",[]);
@@ -109,13 +109,28 @@ return self}
 }),
 smalltalk.TestCase);
 
+smalltalk.addMethod(
+"_errorIfNotAsync_",
+smalltalk.method({
+selector: "errorIfNotAsync:",
+fn: function (aString){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_isAsync",[]);
+if(! smalltalk.assert($1)){
+smalltalk.send(self,"_error_",[smalltalk.send(aString,"__comma",[" used without prior #graceTime:"])]);
+};
+return self}
+}),
+smalltalk.TestCase);
+
 smalltalk.addMethod(
 "_finished",
 smalltalk.method({
 selector: "finished",
 fn: function (){
 var self=this;
-smalltalk.send(self,"_mustBeAsync_",["#finished"]);
+smalltalk.send(self,"_errorIfNotAsync_",["#finished"]);
 self["@asyncTimeout"]=nil;
 return self}
 }),
@@ -155,21 +170,6 @@ return $1;
 }),
 smalltalk.TestCase);
 
-smalltalk.addMethod(
-"_mustBeAsync_",
-smalltalk.method({
-selector: "mustBeAsync:",
-fn: function (aString){
-var self=this;
-var $1;
-$1=smalltalk.send(self,"_isAsync",[]);
-if(! smalltalk.assert($1)){
-smalltalk.send(self,"_error_",[smalltalk.send(aString,"__comma",[" used without prior #graceTime:"])]);
-};
-return self}
-}),
-smalltalk.TestCase);
-
 smalltalk.addMethod(
 "_performTest",
 smalltalk.method({
@@ -487,14 +487,8 @@ fn: function (aBlock){
 var self=this;
 var $1,$3,$2;
 $1=(function(){
-return smalltalk.send((function(){
-return smalltalk.send((function(){
+return smalltalk.send(self,"_withErrorReporting_",[(function(){
 return smalltalk.send(self,"_execute_",[aBlock],smalltalk.TestContext);
-}),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
-return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
-})]);
-}),"_on_do_",[(smalltalk.Error || Error),(function(ex){
-return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
 })]);
 });
 $2=(function(){
@@ -531,6 +525,23 @@ return self}
 }),
 smalltalk.ReportingTestContext);
 
+smalltalk.addMethod(
+"_withErrorReporting_",
+smalltalk.method({
+selector: "withErrorReporting:",
+fn: function (aBlock){
+var self=this;
+smalltalk.send((function(){
+return smalltalk.send(aBlock,"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
+return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
+})]);
+}),"_on_do_",[(smalltalk.Error || Error),(function(ex){
+return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
+})]);
+return self}
+}),
+smalltalk.ReportingTestContext);
+
 
 smalltalk.addMethod(
 "_testCase_result_finished_",

+ 55 - 39
js/SUnit.js

@@ -101,7 +101,7 @@ fn: function (aBlock){
 var self=this;
 var $2,$1;
 var c;
-smalltalk.send(self,"_mustBeAsync_",["#async"]);
+smalltalk.send(self,"_errorIfNotAsync_",["#async"]);
 c=self["@context"];
 $1=(function(){
 $2=smalltalk.send(self,"_isAsync",[]);
@@ -112,8 +112,8 @@ return smalltalk.send(c,"_execute_",[aBlock]);
 return $1;
 },
 args: ["aBlock"],
-source: "async: aBlock\x0a\x09| c |\x0a\x09self mustBeAsync: '#async'.\x0a    c := context.\x0a    ^[ self isAsync ifTrue: [ c execute: aBlock ]]",
-messageSends: ["mustBeAsync:", "ifTrue:", "execute:", "isAsync"],
+source: "async: aBlock\x0a\x09| c |\x0a\x09self errorIfNotAsync: '#async'.\x0a    c := context.\x0a    ^ [ self isAsync ifTrue: [ c execute: aBlock ] ]",
+messageSends: ["errorIfNotAsync:", "ifTrue:", "execute:", "isAsync"],
 referencedClasses: []
 }),
 smalltalk.TestCase);
@@ -150,6 +150,26 @@ referencedClasses: []
 }),
 smalltalk.TestCase);
 
+smalltalk.addMethod(
+"_errorIfNotAsync_",
+smalltalk.method({
+selector: "errorIfNotAsync:",
+category: 'error handling',
+fn: function (aString){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_isAsync",[]);
+if(! smalltalk.assert($1)){
+smalltalk.send(self,"_error_",[smalltalk.send(aString,"__comma",[" used without prior #graceTime:"])]);
+};
+return self},
+args: ["aString"],
+source: "errorIfNotAsync: aString\x0a\x09self isAsync ifFalse: [ \x0a    \x09self error: aString, ' used without prior #graceTime:' ]",
+messageSends: ["ifFalse:", "error:", ",", "isAsync"],
+referencedClasses: []
+}),
+smalltalk.TestCase);
+
 smalltalk.addMethod(
 "_finished",
 smalltalk.method({
@@ -157,12 +177,12 @@ selector: "finished",
 category: 'async',
 fn: function (){
 var self=this;
-smalltalk.send(self,"_mustBeAsync_",["#finished"]);
+smalltalk.send(self,"_errorIfNotAsync_",["#finished"]);
 self["@asyncTimeout"]=nil;
 return self},
 args: [],
-source: "finished\x0a\x09self mustBeAsync: '#finished'.\x0a\x09asyncTimeout := nil",
-messageSends: ["mustBeAsync:"],
+source: "finished\x0a\x09self errorIfNotAsync: '#finished'.\x0a\x09asyncTimeout := nil",
+messageSends: ["errorIfNotAsync:"],
 referencedClasses: []
 }),
 smalltalk.TestCase);
@@ -197,7 +217,7 @@ smalltalk.addMethod(
 "_isAsync",
 smalltalk.method({
 selector: "isAsync",
-category: 'async',
+category: 'testing',
 fn: function (){
 var self=this;
 var $1;
@@ -211,26 +231,6 @@ referencedClasses: []
 }),
 smalltalk.TestCase);
 
-smalltalk.addMethod(
-"_mustBeAsync_",
-smalltalk.method({
-selector: "mustBeAsync:",
-category: 'async',
-fn: function (aString){
-var self=this;
-var $1;
-$1=smalltalk.send(self,"_isAsync",[]);
-if(! smalltalk.assert($1)){
-smalltalk.send(self,"_error_",[smalltalk.send(aString,"__comma",[" used without prior #graceTime:"])]);
-};
-return self},
-args: ["aString"],
-source: "mustBeAsync: aString\x0a\x09self isAsync ifFalse: [ self error: aString, ' used without prior #graceTime:' ]",
-messageSends: ["ifFalse:", "error:", ",", "isAsync"],
-referencedClasses: []
-}),
-smalltalk.TestCase);
-
 smalltalk.addMethod(
 "_performTest",
 smalltalk.method({
@@ -581,7 +581,7 @@ return smalltalk.send(self["@testCase"],"_tearDown",[]);
 smalltalk.send($1,"_ensure_",[$2]);
 return self},
 args: ["aBlock"],
-source: "execute: aBlock\x0a\x09| failed |\x0a    testCase context: self.\x0a    [ failed := true. aBlock value. failed := false ] ensure: [\x0a        testCase context: nil.\x0a        (failed and: [testCase isAsync]) ifTrue: [ testCase finished ].\x0a        testCase isAsync ifFalse: [ testCase tearDown ]\x0a    ]\x0a",
+source: "execute: aBlock\x0a\x09| failed |\x0a    \x0a    testCase context: self.\x0a    [ \x0a    \x09failed := true. \x0a        aBlock value. \x0a        failed := false \x0a\x09] \x0a    \x09ensure: [\x0a        \x09testCase context: nil.\x0a            \x0a        \x09(failed and: [ testCase isAsync ]) ifTrue: [ \x0a            \x09testCase finished ].\x0a        \x09testCase isAsync ifFalse: [ \x0a        \x09\x09testCase tearDown ] ]",
 messageSends: ["context:", "ensure:", "ifTrue:", "finished", "and:", "isAsync", "ifFalse:", "tearDown", "value"],
 referencedClasses: []
 }),
@@ -600,7 +600,7 @@ return smalltalk.send(self["@testCase"],"_performTest",[]);
 })]);
 return self},
 args: [],
-source: "start\x0a\x09self execute: [ testCase setUp. testCase performTest ]",
+source: "start\x0a\x09self execute: [ \x0a    \x09testCase setUp. \x0a        testCase performTest ]",
 messageSends: ["execute:", "setUp", "performTest"],
 referencedClasses: []
 }),
@@ -656,14 +656,8 @@ fn: function (aBlock){
 var self=this;
 var $1,$3,$2;
 $1=(function(){
-return smalltalk.send((function(){
-return smalltalk.send((function(){
+return smalltalk.send(self,"_withErrorReporting_",[(function(){
 return smalltalk.send(self,"_execute_",[aBlock],smalltalk.TestContext);
-}),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
-return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
-})]);
-}),"_on_do_",[(smalltalk.Error || Error),(function(ex){
-return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
 })]);
 });
 $2=(function(){
@@ -676,9 +670,9 @@ return smalltalk.send(self["@finished"],"_value",[]);
 smalltalk.send($1,"_ensure_",[$2]);
 return self},
 args: ["aBlock"],
-source: "execute: aBlock\x0a    [\x0a    \x09[\x0a        \x09[ super execute: aBlock ]\x0a    \x09\x09\x09on: TestFailure \x0a                do: [:ex | result addFailure: testCase ] \x0a  \x09\x09]\x0a    \x09\x09on: Error \x0a            do: [:ex | result addError: testCase] \x0a\x09]\x0a    \x09ensure: [ testCase isAsync ifFalse: [ result increaseRuns. finished value ] ]",
-messageSends: ["ensure:", "ifFalse:", "increaseRuns", "value", "isAsync", "on:do:", "addError:", "addFailure:", "execute:"],
-referencedClasses: ["Error", "TestFailure"]
+source: "execute: aBlock\x0a    [ \x0a    \x09self withErrorReporting: [ super execute: aBlock ] \x0a\x09]\x0a    \x09ensure: [ \x0a        \x09testCase isAsync ifFalse: [ \x0a            \x09result increaseRuns. finished value ] ]",
+messageSends: ["ensure:", "ifFalse:", "increaseRuns", "value", "isAsync", "withErrorReporting:", "execute:"],
+referencedClasses: []
 }),
 smalltalk.ReportingTestContext);
 
@@ -714,6 +708,28 @@ referencedClasses: []
 }),
 smalltalk.ReportingTestContext);
 
+smalltalk.addMethod(
+"_withErrorReporting_",
+smalltalk.method({
+selector: "withErrorReporting:",
+category: 'private',
+fn: function (aBlock){
+var self=this;
+smalltalk.send((function(){
+return smalltalk.send(aBlock,"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
+return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
+})]);
+}),"_on_do_",[(smalltalk.Error || Error),(function(ex){
+return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
+})]);
+return self},
+args: ["aBlock"],
+source: "withErrorReporting: aBlock\x0a \x09[ aBlock\x0a\x09\x09on: TestFailure \x0a\x09\x09do: [ :ex | result addFailure: testCase ] \x0a\x09]\x0a    \x09on: Error \x0a        do: [ :ex | result addError: testCase ]",
+messageSends: ["on:do:", "addError:", "addFailure:"],
+referencedClasses: ["Error", "TestFailure"]
+}),
+smalltalk.ReportingTestContext);
+
 
 smalltalk.addMethod(
 "_testCase_result_finished_",

+ 44 - 24
st/SUnit.st

@@ -45,13 +45,13 @@ setTestSelector: aSelector
 
 async: aBlock
 	| c |
-	self mustBeAsync: '#async'.
+	self errorIfNotAsync: '#async'.
     c := context.
-    ^[ self isAsync ifTrue: [ c execute: aBlock ]]
+    ^ [ self isAsync ifTrue: [ c execute: aBlock ] ]
 !
 
 finished
-	self mustBeAsync: '#finished'.
+	self errorIfNotAsync: '#finished'.
 	asyncTimeout := nil
 !
 
@@ -61,14 +61,13 @@ graceTime: millis
 	asyncTimeout :=
 		(self async: [ self assert: false description: 'SUnit grace time exhausted' ])
         valueWithTimeout: millis
-!
+! !
 
-isAsync
-	^asyncTimeout notNil
-!
+!TestCase methodsFor: 'error handling'!
 
-mustBeAsync: aString
-	self isAsync ifFalse: [ self error: aString, ' used without prior #graceTime:' ]
+errorIfNotAsync: aString
+	self isAsync ifFalse: [ 
+    	self error: aString, ' used without prior #graceTime:' ]
 ! !
 
 !TestCase methodsFor: 'private'!
@@ -116,6 +115,10 @@ deny: aBoolean
 	self assert: aBoolean not
 !
 
+isAsync
+	^asyncTimeout notNil
+!
+
 should: aBlock
 	self assert: aBlock value
 !
@@ -190,16 +193,26 @@ testCase: aTestCase
 
 execute: aBlock
 	| failed |
+    
     testCase context: self.
-    [ failed := true. aBlock value. failed := false ] ensure: [
-        testCase context: nil.
-        (failed and: [testCase isAsync]) ifTrue: [ testCase finished ].
-        testCase isAsync ifFalse: [ testCase tearDown ]
-    ]
+    [ 
+    	failed := true. 
+        aBlock value. 
+        failed := false 
+	] 
+    	ensure: [
+        	testCase context: nil.
+            
+        	(failed and: [ testCase isAsync ]) ifTrue: [ 
+            	testCase finished ].
+        	testCase isAsync ifFalse: [ 
+        		testCase tearDown ] ]
 !
 
 start
-	self execute: [ testCase setUp. testCase performTest ]
+	self execute: [ 
+    	testCase setUp. 
+        testCase performTest ]
 ! !
 
 !TestContext class methodsFor: 'instance creation'!
@@ -231,19 +244,26 @@ result: aTestResult
 	result := aTestResult
 ! !
 
+!ReportingTestContext methodsFor: 'private'!
+
+withErrorReporting: aBlock
+ 	[ aBlock
+		on: TestFailure 
+		do: [ :ex | result addFailure: testCase ] 
+	]
+    	on: Error 
+        do: [ :ex | result addError: testCase ]
+! !
+
 !ReportingTestContext methodsFor: 'running'!
 
 execute: aBlock
-    [
-    	[
-        	[ super execute: aBlock ]
-    			on: TestFailure 
-                do: [:ex | result addFailure: testCase ] 
-  		]
-    		on: Error 
-            do: [:ex | result addError: testCase] 
+    [ 
+    	self withErrorReporting: [ super execute: aBlock ] 
 	]
-    	ensure: [ testCase isAsync ifFalse: [ result increaseRuns. finished value ] ]
+    	ensure: [ 
+        	testCase isAsync ifFalse: [ 
+            	result increaseRuns. finished value ] ]
 ! !
 
 !ReportingTestContext class methodsFor: 'instance creation'!