Browse Source

Pharo-inspired changes; setUp/tearDown covered.

Herbert Vojčík 12 years ago
parent
commit
0ac15010cc
3 changed files with 116 additions and 60 deletions
  1. 42 19
      js/SUnit.deploy.js
  2. 56 28
      js/SUnit.js
  3. 18 13
      st/SUnit.st

+ 42 - 19
js/SUnit.deploy.js

@@ -77,29 +77,29 @@ fn: function (aBoolean) {
 smalltalk.TestCase);
 
 smalltalk.addMethod(
-"_performTestFor_",
+"_performTest",
 smalltalk.method({
-selector: "performTestFor:",
-fn: function (aResult) {
-    var self = this;
-    smalltalk.send(function () {return smalltalk.send(function () {return smalltalk.send(self, "_perform_", [smalltalk.send(self, "_selector", [])]);}, "_on_do_", [smalltalk.TestFailure || TestFailure, function (ex) {return smalltalk.send(aResult, "_addFailure_", [self]);}]);}, "_on_do_", [smalltalk.Error || Error, function (ex) {return smalltalk.send(aResult, "_addError_", [self]);}]);
-    return self;
-}
+selector: "performTest",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_perform_",[smalltalk.send(self,"_selector",[])]);
+return self}
 }),
 smalltalk.TestCase);
 
 smalltalk.addMethod(
-"_runCaseFor_",
+"_runCase",
 smalltalk.method({
-selector: "runCaseFor:",
-fn: function (aTestResult) {
-    var self = this;
-    smalltalk.send(self, "_setUp", []);
-    smalltalk.send(aTestResult, "_increaseRuns", []);
-    smalltalk.send(self, "_performTestFor_", [aTestResult]);
-    smalltalk.send(self, "_tearDown", []);
-    return self;
-}
+selector: "runCase",
+fn: function (){
+var self=this;
+smalltalk.send((function(){
+smalltalk.send(self,"_setUp",[]);
+return smalltalk.send(self,"_performTest",[]);
+}),"_ensure_",[(function(){
+return smalltalk.send(self,"_tearDown",[]);
+})]);
+return self}
 }),
 smalltalk.TestCase);
 
@@ -498,11 +498,14 @@ index=(1);
 worker=(function(){
 $1=smalltalk.send(index,"__lt_eq",[smalltalk.send(self["@suite"],"_size",[])]);
 if(smalltalk.assert($1)){
-smalltalk.send(smalltalk.send(self["@suite"],"_at_",[index]),"_runCaseFor_",[self["@result"]]);
+return smalltalk.send((function(){
+smalltalk.send(self,"_runCase_for_",[smalltalk.send(self["@suite"],"_at_",[index]),self["@result"]]);
+return smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
+}),"_ensure_",[(function(){
 index=smalltalk.send(index,"__plus",[(1)]);
 index;
-smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
 return smalltalk.send(worker,"_valueWithTimeout_",[(0)]);
+})]);
 };
 });
 smalltalk.send(smalltalk.send(smalltalk.send(self["@suite"],"_size",[]),"_min_",[(25)]),"_timesRepeat_",[(function(){
@@ -512,6 +515,26 @@ return self}
 }),
 smalltalk.TestSuiteRunner);
 
+smalltalk.addMethod(
+"_runCase_for_",
+smalltalk.method({
+selector: "runCase:for:",
+fn: function (aTestCase,aTestResult){
+var self=this;
+smalltalk.send((function(){
+return smalltalk.send((function(){
+smalltalk.send(aTestResult,"_increaseRuns",[]);
+return smalltalk.send(aTestCase,"_runCase",[]);
+}),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
+return smalltalk.send(aTestResult,"_addFailure_",[aTestCase]);
+})]);
+}),"_on_do_",[(smalltalk.Error || Error),(function(ex){
+return smalltalk.send(aTestResult,"_addError_",[aTestCase]);
+})]);
+return self}
+}),
+smalltalk.TestSuiteRunner);
+
 smalltalk.addMethod(
 "_suite_",
 smalltalk.method({

+ 56 - 28
js/SUnit.js

@@ -107,38 +107,38 @@ referencedClasses: []
 smalltalk.TestCase);
 
 smalltalk.addMethod(
-"_performTestFor_",
+"_performTest",
 smalltalk.method({
-selector: "performTestFor:",
+selector: "performTest",
 category: 'running',
-fn: function (aResult) {
-    var self = this;
-    smalltalk.send(function () {return smalltalk.send(function () {return smalltalk.send(self, "_perform_", [smalltalk.send(self, "_selector", [])]);}, "_on_do_", [smalltalk.TestFailure || TestFailure, function (ex) {return smalltalk.send(aResult, "_addFailure_", [self]);}]);}, "_on_do_", [smalltalk.Error || Error, function (ex) {return smalltalk.send(aResult, "_addError_", [self]);}]);
-    return self;
-},
-args: ["aResult"],
-source: "performTestFor: aResult\x0a\x09[[self perform: self selector]\x0a\x09\x09on: TestFailure do: [:ex | aResult addFailure: self]]\x0a\x09\x09on: Error do: [:ex | aResult addError: self]",
-messageSends: ["on:do:", "addError:", "addFailure:", "perform:", "selector"],
-referencedClasses: ["Error", "TestFailure"]
+fn: function (){
+var self=this;
+smalltalk.send(self,"_perform_",[smalltalk.send(self,"_selector",[])]);
+return self},
+args: [],
+source: "performTest\x0a\x09self perform: self selector\x0a",
+messageSends: ["perform:", "selector"],
+referencedClasses: []
 }),
 smalltalk.TestCase);
 
 smalltalk.addMethod(
-"_runCaseFor_",
+"_runCase",
 smalltalk.method({
-selector: "runCaseFor:",
+selector: "runCase",
 category: 'running',
-fn: function (aTestResult) {
-    var self = this;
-    smalltalk.send(self, "_setUp", []);
-    smalltalk.send(aTestResult, "_increaseRuns", []);
-    smalltalk.send(self, "_performTestFor_", [aTestResult]);
-    smalltalk.send(self, "_tearDown", []);
-    return self;
-},
-args: ["aTestResult"],
-source: "runCaseFor: aTestResult\x0a\x09self setUp.\x0a\x09aTestResult increaseRuns.\x0a\x09self performTestFor: aTestResult.\x0a\x09self tearDown",
-messageSends: ["setUp", "increaseRuns", "performTestFor:", "tearDown"],
+fn: function (){
+var self=this;
+smalltalk.send((function(){
+smalltalk.send(self,"_setUp",[]);
+return smalltalk.send(self,"_performTest",[]);
+}),"_ensure_",[(function(){
+return smalltalk.send(self,"_tearDown",[]);
+})]);
+return self},
+args: [],
+source: "runCase\x0a\x09[\x09self setUp.\x0a\x09\x09self performTest ] ensure: [\x0a\x09\x09self tearDown.\x0a\x09\x09\x22self cleanUpInstanceVariables\x22 ]\x0a",
+messageSends: ["ensure:", "tearDown", "setUp", "performTest"],
 referencedClasses: []
 }),
 smalltalk.TestCase);
@@ -684,11 +684,14 @@ index=(1);
 worker=(function(){
 $1=smalltalk.send(index,"__lt_eq",[smalltalk.send(self["@suite"],"_size",[])]);
 if(smalltalk.assert($1)){
-smalltalk.send(smalltalk.send(self["@suite"],"_at_",[index]),"_runCaseFor_",[self["@result"]]);
+return smalltalk.send((function(){
+smalltalk.send(self,"_runCase_for_",[smalltalk.send(self["@suite"],"_at_",[index]),self["@result"]]);
+return smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
+}),"_ensure_",[(function(){
 index=smalltalk.send(index,"__plus",[(1)]);
 index;
-smalltalk.send(self["@announcer"],"_announce_",[smalltalk.send(smalltalk.send((smalltalk.ResultAnnouncement || ResultAnnouncement),"_new",[]),"_result_",[self["@result"]])]);
 return smalltalk.send(worker,"_valueWithTimeout_",[(0)]);
+})]);
 };
 });
 smalltalk.send(smalltalk.send(smalltalk.send(self["@suite"],"_size",[]),"_min_",[(25)]),"_timesRepeat_",[(function(){
@@ -696,12 +699,37 @@ return smalltalk.send(worker,"_valueWithTimeout_",[(0)]);
 })]);
 return self},
 args: [],
-source: "run\x0a\x09| worker index |\x0a\x09result total: suite size.\x0a    announcer announce: (ResultAnnouncement new result: result).\x0a    index := 1.\x0a    worker := [ index <= suite size ifTrue: [\x0a\x09\x09(suite at: index) runCaseFor: result.\x0a        index := index + 1.\x0a\x09\x09announcer announce: (ResultAnnouncement new result: result).\x0a        worker valueWithTimeout: 0\x0a\x09]].\x0a\x09(suite size min: 25) timesRepeat: [ worker valueWithTimeout: 0 ]",
-messageSends: ["total:", "size", "announce:", "result:", "new", "ifTrue:", "runCaseFor:", "at:", "+", "valueWithTimeout:", "<=", "timesRepeat:", "min:"],
+source: "run\x0a\x09| worker index |\x0a\x09result total: suite size.\x0a    announcer announce: (ResultAnnouncement new result: result).\x0a    index := 1.\x0a    worker := [ index <= suite size ifTrue: [\x0a        [ self runCase: (suite at: index)  for: result.\x0a\x09\x09announcer announce: (ResultAnnouncement new result: result). ]\x0a      \x09ensure: [ index := index + 1.\x0a        worker valueWithTimeout: 0 ]\x0a\x09]].\x0a\x09(suite size min: 25) timesRepeat: [ worker valueWithTimeout: 0 ]",
+messageSends: ["total:", "size", "announce:", "result:", "new", "ifTrue:", "ensure:", "+", "valueWithTimeout:", "runCase:for:", "at:", "<=", "timesRepeat:", "min:"],
 referencedClasses: ["ResultAnnouncement"]
 }),
 smalltalk.TestSuiteRunner);
 
+smalltalk.addMethod(
+"_runCase_for_",
+smalltalk.method({
+selector: "runCase:for:",
+category: 'actions',
+fn: function (aTestCase,aTestResult){
+var self=this;
+smalltalk.send((function(){
+return smalltalk.send((function(){
+smalltalk.send(aTestResult,"_increaseRuns",[]);
+return smalltalk.send(aTestCase,"_runCase",[]);
+}),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
+return smalltalk.send(aTestResult,"_addFailure_",[aTestCase]);
+})]);
+}),"_on_do_",[(smalltalk.Error || Error),(function(ex){
+return smalltalk.send(aTestResult,"_addError_",[aTestCase]);
+})]);
+return self},
+args: ["aTestCase", "aTestResult"],
+source: "runCase: aTestCase for: aTestResult\x0a\x09[[\x09aTestResult increaseRuns.\x0a    \x09aTestCase runCase]\x0a\x09on: TestFailure do: [:ex | aTestResult addFailure: aTestCase]]\x0a\x09on: Error do: [:ex | aTestResult addError: aTestCase]\x0a",
+messageSends: ["on:do:", "addError:", "addFailure:", "increaseRuns", "runCase"],
+referencedClasses: ["Error", "TestFailure"]
+}),
+smalltalk.TestSuiteRunner);
+
 smalltalk.addMethod(
 "_suite_",
 smalltalk.method({

+ 18 - 13
st/SUnit.st

@@ -37,17 +37,15 @@ signalFailure: aString
 
 !TestCase methodsFor: 'running'!
 
-performTestFor: aResult
-	[[self perform: self selector]
-		on: TestFailure do: [:ex | aResult addFailure: self]]
-		on: Error do: [:ex | aResult addError: self]
+performTest
+	self perform: self selector
 !
 
-runCaseFor: aTestResult
-	self setUp.
-	aTestResult increaseRuns.
-	self performTestFor: aTestResult.
-	self tearDown
+runCase
+	[	self setUp.
+		self performTest ] ensure: [
+		self tearDown.
+		"self cleanUpInstanceVariables" ]
 !
 
 setUp
@@ -220,12 +218,19 @@ run
     announcer announce: (ResultAnnouncement new result: result).
     index := 1.
     worker := [ index <= suite size ifTrue: [
-		(suite at: index) runCaseFor: result.
-        index := index + 1.
-		announcer announce: (ResultAnnouncement new result: result).
-        worker valueWithTimeout: 0
+        [ self runCase: (suite at: index)  for: result.
+		announcer announce: (ResultAnnouncement new result: result). ]
+      	ensure: [ index := index + 1.
+        worker valueWithTimeout: 0 ]
 	]].
 	(suite size min: 25) timesRepeat: [ worker valueWithTimeout: 0 ]
+!
+
+runCase: aTestCase for: aTestResult
+	[[	aTestResult increaseRuns.
+    	aTestCase runCase]
+	on: TestFailure do: [:ex | aTestResult addFailure: aTestCase]]
+	on: Error do: [:ex | aTestResult addError: aTestCase]
 ! !
 
 !TestSuiteRunner methodsFor: 'initialization'!