Browse Source

tearDown called when async failure/error.

Herby Vojčík 12 years ago
parent
commit
7710e1cd34
6 changed files with 211 additions and 75 deletions
  1. 39 11
      js/SUnit-Tests.deploy.js
  2. 55 17
      js/SUnit-Tests.js
  3. 38 14
      js/SUnit.deploy.js
  4. 45 16
      js/SUnit.js
  5. 17 7
      st/SUnit-Tests.st
  6. 17 10
      st/SUnit.st

+ 39 - 11
js/SUnit-Tests.deploy.js

@@ -9,10 +9,24 @@ var self=this;
 self["@flag"]="bad";
 self["@flag"]="bad";
 smalltalk.send(self,"_graceTime_",[(10)]);
 smalltalk.send(self,"_graceTime_",[(10)]);
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
-smalltalk.send(self,"_error_",["Intentional"]);
-smalltalk.send(self,"_finished",[]);
 self["@flag"]="ok";
 self["@flag"]="ok";
-return self["@flag"];
+self["@flag"];
+return smalltalk.send(self,"_error_",["Intentional"]);
+})]),"_valueWithTimeout_",[(5)]);
+return self}
+}),
+smalltalk.SUnitAsyncTest);
+
+smalltalk.addMethod(
+"_fakeErrorFailingInTearDown",
+smalltalk.method({
+selector: "fakeErrorFailingInTearDown",
+fn: function (){
+var self=this;
+self["@flag"]="bad";
+smalltalk.send(self,"_graceTime_",[(10)]);
+self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
+return smalltalk.send(self,"_error_",["Intentional"]);
 })]),"_valueWithTimeout_",[(5)]);
 })]),"_valueWithTimeout_",[(5)]);
 return self}
 return self}
 }),
 }),
@@ -27,10 +41,9 @@ var self=this;
 self["@flag"]="bad";
 self["@flag"]="bad";
 smalltalk.send(self,"_graceTime_",[(10)]);
 smalltalk.send(self,"_graceTime_",[(10)]);
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
-smalltalk.send(self,"_assert_",[false]);
-smalltalk.send(self,"_finished",[]);
 self["@flag"]="ok";
 self["@flag"]="ok";
-return self["@flag"];
+self["@flag"];
+return smalltalk.send(self,"_assert_",[false]);
 })]),"_valueWithTimeout_",[(5)]);
 })]),"_valueWithTimeout_",[(5)]);
 return self}
 return self}
 }),
 }),
@@ -47,6 +60,21 @@ return self}
 }),
 }),
 smalltalk.SUnitAsyncTest);
 smalltalk.SUnitAsyncTest);
 
 
+smalltalk.addMethod(
+"_sortedSelectors_",
+smalltalk.method({
+selector: "sortedSelectors:",
+fn: function (aCollection){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(aCollection,"_collect_",[(function(each){
+return smalltalk.send(each,"_selector",[]);
+})]),"_sorted",[]);
+return $1;
+}
+}),
+smalltalk.SUnitAsyncTest);
+
 smalltalk.addMethod(
 smalltalk.addMethod(
 "_tearDown",
 "_tearDown",
 smalltalk.method({
 smalltalk.method({
@@ -69,15 +97,15 @@ var suite;
 var runner;
 var runner;
 var result;
 var result;
 var assertBlock;
 var assertBlock;
-suite=[smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["fakeError"]),smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["fakeFailure"]),smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["testPass"])];
+suite=smalltalk.send(["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"],"_collect_",[(function(each){
+return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
+})]);
 runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
 runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
 smalltalk.send(self,"_graceTime_",[(200)]);
 smalltalk.send(self,"_graceTime_",[(200)]);
 result=smalltalk.send(runner,"_result",[]);
 result=smalltalk.send(runner,"_result",[]);
 assertBlock=smalltalk.send(self,"_async_",[(function(){
 assertBlock=smalltalk.send(self,"_async_",[(function(){
-smalltalk.send(self,"_assert_equals_",[(1),smalltalk.send(smalltalk.send(result,"_errors",[]),"_size",[])]);
-smalltalk.send(self,"_assert_equals_",["fakeError",smalltalk.send(smalltalk.send(smalltalk.send(result,"_errors",[]),"_first",[]),"_selector",[])]);
-smalltalk.send(self,"_assert_equals_",[(1),smalltalk.send(smalltalk.send(result,"_failures",[]),"_size",[])]);
-smalltalk.send(self,"_assert_equals_",["fakeFailure",smalltalk.send(smalltalk.send(smalltalk.send(result,"_failures",[]),"_first",[]),"_selector",[])]);
+smalltalk.send(self,"_assert_equals_",[["fakeError"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_errors",[])])]);
+smalltalk.send(self,"_assert_equals_",[["fakeErrorFailingInTearDown", "fakeFailure"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
 return smalltalk.send(self,"_finished",[]);
 return smalltalk.send(self,"_finished",[]);
 })]);
 })]);
 smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
 smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){

+ 55 - 17
js/SUnit-Tests.js

@@ -10,15 +10,34 @@ var self=this;
 self["@flag"]="bad";
 self["@flag"]="bad";
 smalltalk.send(self,"_graceTime_",[(10)]);
 smalltalk.send(self,"_graceTime_",[(10)]);
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
-smalltalk.send(self,"_error_",["Intentional"]);
-smalltalk.send(self,"_finished",[]);
 self["@flag"]="ok";
 self["@flag"]="ok";
-return self["@flag"];
+self["@flag"];
+return smalltalk.send(self,"_error_",["Intentional"]);
+})]),"_valueWithTimeout_",[(5)]);
+return self},
+args: [],
+source: "fakeError\x0a\x09flag := 'bad'.\x0a\x09self graceTime: 10.\x0a    flag := (self async: [ flag := 'ok'. self error: 'Intentional' ]) valueWithTimeout: 5\x0a",
+messageSends: ["graceTime:", "valueWithTimeout:", "async:", "error:"],
+referencedClasses: []
+}),
+smalltalk.SUnitAsyncTest);
+
+smalltalk.addMethod(
+"_fakeErrorFailingInTearDown",
+smalltalk.method({
+selector: "fakeErrorFailingInTearDown",
+category: 'tests',
+fn: function (){
+var self=this;
+self["@flag"]="bad";
+smalltalk.send(self,"_graceTime_",[(10)]);
+self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
+return smalltalk.send(self,"_error_",["Intentional"]);
 })]),"_valueWithTimeout_",[(5)]);
 })]),"_valueWithTimeout_",[(5)]);
 return self},
 return self},
 args: [],
 args: [],
-source: "fakeError\x0a\x09flag := 'bad'.\x0a\x09self graceTime: 10.\x0a    flag := (self async: [ self error: 'Intentional'. self finished. flag := 'ok' ]) valueWithTimeout: 5\x0a",
-messageSends: ["graceTime:", "valueWithTimeout:", "async:", "error:", "finished"],
+source: "fakeErrorFailingInTearDown\x0a\x09flag := 'bad'.\x0a\x09self graceTime: 10.\x0a    flag := (self async: [ self error: 'Intentional' ]) valueWithTimeout: 5\x0a",
+messageSends: ["graceTime:", "valueWithTimeout:", "async:", "error:"],
 referencedClasses: []
 referencedClasses: []
 }),
 }),
 smalltalk.SUnitAsyncTest);
 smalltalk.SUnitAsyncTest);
@@ -33,15 +52,14 @@ var self=this;
 self["@flag"]="bad";
 self["@flag"]="bad";
 smalltalk.send(self,"_graceTime_",[(10)]);
 smalltalk.send(self,"_graceTime_",[(10)]);
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
 self["@flag"]=smalltalk.send(smalltalk.send(self,"_async_",[(function(){
-smalltalk.send(self,"_assert_",[false]);
-smalltalk.send(self,"_finished",[]);
 self["@flag"]="ok";
 self["@flag"]="ok";
-return self["@flag"];
+self["@flag"];
+return smalltalk.send(self,"_assert_",[false]);
 })]),"_valueWithTimeout_",[(5)]);
 })]),"_valueWithTimeout_",[(5)]);
 return self},
 return self},
 args: [],
 args: [],
-source: "fakeFailure\x0a\x09flag := 'bad'.\x0a\x09self graceTime: 10.\x0a    flag := (self async: [ self assert: false. self finished. flag := 'ok' ]) valueWithTimeout: 5\x0a",
-messageSends: ["graceTime:", "valueWithTimeout:", "async:", "assert:", "finished"],
+source: "fakeFailure\x0a\x09flag := 'bad'.\x0a\x09self graceTime: 10.\x0a    flag := (self async: [ flag := 'ok'. self assert: false ]) valueWithTimeout: 5\x0a",
+messageSends: ["graceTime:", "valueWithTimeout:", "async:", "assert:"],
 referencedClasses: []
 referencedClasses: []
 }),
 }),
 smalltalk.SUnitAsyncTest);
 smalltalk.SUnitAsyncTest);
@@ -62,6 +80,26 @@ referencedClasses: []
 }),
 }),
 smalltalk.SUnitAsyncTest);
 smalltalk.SUnitAsyncTest);
 
 
+smalltalk.addMethod(
+"_sortedSelectors_",
+smalltalk.method({
+selector: "sortedSelectors:",
+category: 'private',
+fn: function (aCollection){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(aCollection,"_collect_",[(function(each){
+return smalltalk.send(each,"_selector",[]);
+})]),"_sorted",[]);
+return $1;
+},
+args: ["aCollection"],
+source: "sortedSelectors: aCollection\x0a\x09^(aCollection collect: [:each | each selector]) sorted",
+messageSends: ["sorted", "collect:", "selector"],
+referencedClasses: []
+}),
+smalltalk.SUnitAsyncTest);
+
 smalltalk.addMethod(
 smalltalk.addMethod(
 "_tearDown",
 "_tearDown",
 smalltalk.method({
 smalltalk.method({
@@ -90,15 +128,15 @@ var suite;
 var runner;
 var runner;
 var result;
 var result;
 var assertBlock;
 var assertBlock;
-suite=[smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["fakeError"]),smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["fakeFailure"]),smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",["testPass"])];
+suite=smalltalk.send(["fakeError", "fakeErrorFailingInTearDown", "fakeFailure", "testPass"],"_collect_",[(function(each){
+return smalltalk.send(smalltalk.send(self,"_class",[]),"_selector_",[each]);
+})]);
 runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
 runner=smalltalk.send((smalltalk.TestSuiteRunner || TestSuiteRunner),"_on_",[suite]);
 smalltalk.send(self,"_graceTime_",[(200)]);
 smalltalk.send(self,"_graceTime_",[(200)]);
 result=smalltalk.send(runner,"_result",[]);
 result=smalltalk.send(runner,"_result",[]);
 assertBlock=smalltalk.send(self,"_async_",[(function(){
 assertBlock=smalltalk.send(self,"_async_",[(function(){
-smalltalk.send(self,"_assert_equals_",[(1),smalltalk.send(smalltalk.send(result,"_errors",[]),"_size",[])]);
-smalltalk.send(self,"_assert_equals_",["fakeError",smalltalk.send(smalltalk.send(smalltalk.send(result,"_errors",[]),"_first",[]),"_selector",[])]);
-smalltalk.send(self,"_assert_equals_",[(1),smalltalk.send(smalltalk.send(result,"_failures",[]),"_size",[])]);
-smalltalk.send(self,"_assert_equals_",["fakeFailure",smalltalk.send(smalltalk.send(smalltalk.send(result,"_failures",[]),"_first",[]),"_selector",[])]);
+smalltalk.send(self,"_assert_equals_",[["fakeError"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_errors",[])])]);
+smalltalk.send(self,"_assert_equals_",[["fakeErrorFailingInTearDown", "fakeFailure"],smalltalk.send(self,"_sortedSelectors_",[smalltalk.send(result,"_failures",[])])]);
 return smalltalk.send(self,"_finished",[]);
 return smalltalk.send(self,"_finished",[]);
 })]);
 })]);
 smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
 smalltalk.send(smalltalk.send(runner,"_announcer",[]),"_on_do_",[(smalltalk.ResultAnnouncement || ResultAnnouncement),(function(ann){
@@ -111,8 +149,8 @@ return smalltalk.send($2,"_ifTrue_",[assertBlock]);
 smalltalk.send(runner,"_run",[]);
 smalltalk.send(runner,"_run",[]);
 return self},
 return self},
 args: [],
 args: [],
-source: "testAsyncErrorsAndFailuresWork\x0a\x09| suite runner result assertBlock |\x0a\x09suite := { self class selector: 'fakeError'. self class selector: 'fakeFailure'. self class selector: 'testPass' }.\x0a    runner := TestSuiteRunner on: suite.\x0a    self graceTime: 200.\x0a\x09result := runner result.\x0a    assertBlock := self async: [\x0a\x09\x09self assert: 1 equals: result errors size.\x0a\x09\x09self assert: 'fakeError' equals: result errors first selector.\x0a\x09\x09self assert: 1 equals: result failures size.\x0a\x09\x09self assert: 'fakeFailure' equals: result failures first selector.\x0a\x09\x09self finished\x0a  \x09].\x0a    runner announcer on: ResultAnnouncement do: [:ann |\x0a    \x09ann result == result  ifTrue: [ result runs = result total ifTrue: assertBlock ]].\x0a\x09runner run",
-messageSends: ["selector:", "class", "on:", "graceTime:", "result", "async:", "assert:equals:", "size", "errors", "selector", "first", "failures", "finished", "on:do:", "ifTrue:", "=", "total", "runs", "==", "announcer", "run"],
+source: "testAsyncErrorsAndFailuresWork\x0a\x09| suite runner result assertBlock |\x0a\x09suite := #('fakeError' 'fakeErrorFailingInTearDown' 'fakeFailure' 'testPass') collect: [ :each | self class selector: each ].\x0a    runner := TestSuiteRunner on: suite.\x0a    self graceTime: 200.\x0a\x09result := runner result.\x0a    assertBlock := self async: [\x0a\x09\x09self assert: #('fakeError') equals: (self sortedSelectors: result errors).\x0a\x09\x09self assert: #('fakeErrorFailingInTearDown' 'fakeFailure') equals: (self sortedSelectors: result failures).\x0a\x09\x09self finished\x0a  \x09].\x0a    runner announcer on: ResultAnnouncement do: [:ann |\x0a    \x09ann result == result  ifTrue: [ result runs = result total ifTrue: assertBlock ]].\x0a\x09runner run",
+messageSends: ["collect:", "selector:", "class", "on:", "graceTime:", "result", "async:", "assert:equals:", "sortedSelectors:", "errors", "failures", "finished", "on:do:", "ifTrue:", "=", "total", "runs", "==", "announcer", "run"],
 referencedClasses: ["TestSuiteRunner", "ResultAnnouncement"]
 referencedClasses: ["TestSuiteRunner", "ResultAnnouncement"]
 }),
 }),
 smalltalk.SUnitAsyncTest);
 smalltalk.SUnitAsyncTest);

+ 38 - 14
js/SUnit.deploy.js

@@ -24,46 +24,70 @@ smalltalk.ResultAnnouncement);
 
 
 
 
 
 
-smalltalk.addClass('RunningTestContext', smalltalk.Object, ['finished', 'testCase', 'result'], 'SUnit');
+smalltalk.addClass('RunningTestContext', smalltalk.Object, ['finished', 'testCase', 'result', 'step'], 'SUnit');
+smalltalk.addMethod(
+"_exception_ifNotAsync_",
+smalltalk.method({
+selector: "exception:ifNotAsync:",
+fn: function (anException,aBlock){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@testCase"],"_isAsync",[]);
+if(smalltalk.assert($1)){
+self["@step"]=(function(){
+smalltalk.send(self["@testCase"],"_finished",[]);
+return smalltalk.send(anException,"_signal",[]);
+});
+self["@step"];
+} else {
+smalltalk.send(aBlock,"_value",[]);
+};
+return self}
+}),
+smalltalk.RunningTestContext);
+
 smalltalk.addMethod(
 smalltalk.addMethod(
 "_execute_",
 "_execute_",
 smalltalk.method({
 smalltalk.method({
 selector: "execute:",
 selector: "execute:",
 fn: function (aBlock){
 fn: function (aBlock){
 var self=this;
 var self=this;
-var $1,$2,$3,$4;
-smalltalk.send(self["@testCase"],"_context_",[self]);
+var $1,$2;
+self["@step"]=aBlock;
 smalltalk.send((function(){
 smalltalk.send((function(){
+return smalltalk.send(self["@step"],"_isNil",[]);
+}),"_whileFalse_",[(function(){
+smalltalk.send(self["@testCase"],"_context_",[self]);
+return smalltalk.send((function(){
 return smalltalk.send((function(){
 return smalltalk.send((function(){
 return smalltalk.send((function(){
 return smalltalk.send((function(){
-return smalltalk.send(aBlock,"_ensure_",[(function(){
+return smalltalk.send(self["@step"],"_ensure_",[(function(){
 smalltalk.send(self["@testCase"],"_context_",[nil]);
 smalltalk.send(self["@testCase"],"_context_",[nil]);
+self["@step"]=nil;
+self["@step"];
 $1=smalltalk.send(self["@testCase"],"_isAsync",[]);
 $1=smalltalk.send(self["@testCase"],"_isAsync",[]);
 if(! smalltalk.assert($1)){
 if(! smalltalk.assert($1)){
 return smalltalk.send(self["@testCase"],"_tearDown",[]);
 return smalltalk.send(self["@testCase"],"_tearDown",[]);
 };
 };
 })]);
 })]);
 }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
 }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
-$2=smalltalk.send(self["@testCase"],"_isAsync",[]);
-if(smalltalk.assert($2)){
-smalltalk.send(self["@testCase"],"_finished",[]);
-};
+return smalltalk.send(self,"_exception_ifNotAsync_",[ex,(function(){
 return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
 return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
 })]);
 })]);
+})]);
 }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
 }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
-$3=smalltalk.send(self["@testCase"],"_isAsync",[]);
-if(smalltalk.assert($3)){
-smalltalk.send(self["@testCase"],"_finished",[]);
-};
+return smalltalk.send(self,"_exception_ifNotAsync_",[ex,(function(){
 return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
 return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
 })]);
 })]);
+})]);
 }),"_ensure_",[(function(){
 }),"_ensure_",[(function(){
-$4=smalltalk.send(self["@testCase"],"_isAsync",[]);
-if(! smalltalk.assert($4)){
+$2=smalltalk.send(self["@testCase"],"_isAsync",[]);
+if(! smalltalk.assert($2)){
 smalltalk.send(self["@result"],"_increaseRuns",[]);
 smalltalk.send(self["@result"],"_increaseRuns",[]);
 return smalltalk.send(self["@finished"],"_value",[]);
 return smalltalk.send(self["@finished"],"_value",[]);
 };
 };
 })]);
 })]);
+})]);
 return self}
 return self}
 }),
 }),
 smalltalk.RunningTestContext);
 smalltalk.RunningTestContext);

+ 45 - 16
js/SUnit.js

@@ -34,7 +34,33 @@ smalltalk.ResultAnnouncement);
 
 
 
 
 
 
-smalltalk.addClass('RunningTestContext', smalltalk.Object, ['finished', 'testCase', 'result'], 'SUnit');
+smalltalk.addClass('RunningTestContext', smalltalk.Object, ['finished', 'testCase', 'result', 'step'], 'SUnit');
+smalltalk.addMethod(
+"_exception_ifNotAsync_",
+smalltalk.method({
+selector: "exception:ifNotAsync:",
+category: 'private',
+fn: function (anException,aBlock){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@testCase"],"_isAsync",[]);
+if(smalltalk.assert($1)){
+self["@step"]=(function(){
+smalltalk.send(self["@testCase"],"_finished",[]);
+return smalltalk.send(anException,"_signal",[]);
+});
+self["@step"];
+} else {
+smalltalk.send(aBlock,"_value",[]);
+};
+return self},
+args: ["anException", "aBlock"],
+source: "exception: anException ifNotAsync: aBlock\x0a\x09testCase isAsync\x0a\x09\x09ifTrue: [ step := [ testCase finished. anException signal ]]\x0a\x09\x09ifFalse: [ aBlock value ]\x0a",
+messageSends: ["ifTrue:ifFalse:", "finished", "signal", "value", "isAsync"],
+referencedClasses: []
+}),
+smalltalk.RunningTestContext);
+
 smalltalk.addMethod(
 smalltalk.addMethod(
 "_execute_",
 "_execute_",
 smalltalk.method({
 smalltalk.method({
@@ -42,43 +68,46 @@ selector: "execute:",
 category: 'running',
 category: 'running',
 fn: function (aBlock){
 fn: function (aBlock){
 var self=this;
 var self=this;
-var $1,$2,$3,$4;
-smalltalk.send(self["@testCase"],"_context_",[self]);
+var $1,$2;
+self["@step"]=aBlock;
 smalltalk.send((function(){
 smalltalk.send((function(){
+return smalltalk.send(self["@step"],"_isNil",[]);
+}),"_whileFalse_",[(function(){
+smalltalk.send(self["@testCase"],"_context_",[self]);
 return smalltalk.send((function(){
 return smalltalk.send((function(){
 return smalltalk.send((function(){
 return smalltalk.send((function(){
-return smalltalk.send(aBlock,"_ensure_",[(function(){
+return smalltalk.send((function(){
+return smalltalk.send(self["@step"],"_ensure_",[(function(){
 smalltalk.send(self["@testCase"],"_context_",[nil]);
 smalltalk.send(self["@testCase"],"_context_",[nil]);
+self["@step"]=nil;
+self["@step"];
 $1=smalltalk.send(self["@testCase"],"_isAsync",[]);
 $1=smalltalk.send(self["@testCase"],"_isAsync",[]);
 if(! smalltalk.assert($1)){
 if(! smalltalk.assert($1)){
 return smalltalk.send(self["@testCase"],"_tearDown",[]);
 return smalltalk.send(self["@testCase"],"_tearDown",[]);
 };
 };
 })]);
 })]);
 }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
 }),"_on_do_",[(smalltalk.TestFailure || TestFailure),(function(ex){
-$2=smalltalk.send(self["@testCase"],"_isAsync",[]);
-if(smalltalk.assert($2)){
-smalltalk.send(self["@testCase"],"_finished",[]);
-};
+return smalltalk.send(self,"_exception_ifNotAsync_",[ex,(function(){
 return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
 return smalltalk.send(self["@result"],"_addFailure_",[self["@testCase"]]);
 })]);
 })]);
+})]);
 }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
 }),"_on_do_",[(smalltalk.Error || Error),(function(ex){
-$3=smalltalk.send(self["@testCase"],"_isAsync",[]);
-if(smalltalk.assert($3)){
-smalltalk.send(self["@testCase"],"_finished",[]);
-};
+return smalltalk.send(self,"_exception_ifNotAsync_",[ex,(function(){
 return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
 return smalltalk.send(self["@result"],"_addError_",[self["@testCase"]]);
 })]);
 })]);
+})]);
 }),"_ensure_",[(function(){
 }),"_ensure_",[(function(){
-$4=smalltalk.send(self["@testCase"],"_isAsync",[]);
-if(! smalltalk.assert($4)){
+$2=smalltalk.send(self["@testCase"],"_isAsync",[]);
+if(! smalltalk.assert($2)){
 smalltalk.send(self["@result"],"_increaseRuns",[]);
 smalltalk.send(self["@result"],"_increaseRuns",[]);
 return smalltalk.send(self["@finished"],"_value",[]);
 return smalltalk.send(self["@finished"],"_value",[]);
 };
 };
 })]);
 })]);
+})]);
 return self},
 return self},
 args: ["aBlock"],
 args: ["aBlock"],
-source: "execute: aBlock\x0a    testCase context: self.\x0a\x09[[[\x09aBlock\x0a        \x09ensure: [ testCase context: nil.\x0a\x09\x09\x09\x09testCase isAsync ifFalse: [ testCase tearDown ]]]\x0a\x09\x09\x09on: TestFailure do: [:ex | testCase isAsync ifTrue: [ testCase finished ]. result addFailure: testCase]]\x0a\x09\x09\x09on: Error do: [:ex | testCase isAsync ifTrue: [ testCase finished ]. result addError: testCase]]\x0a\x09\x09\x09ensure: [ testCase isAsync ifFalse: [\x0a                result increaseRuns.\x0a                finished value ]]",
-messageSends: ["context:", "ensure:", "ifFalse:", "increaseRuns", "value", "isAsync", "on:do:", "ifTrue:", "finished", "addError:", "addFailure:", "tearDown"],
+source: "execute: aBlock\x0a    step := aBlock.\x0a\x09[ step isNil ] whileFalse: [\x0a\x09    testCase context: self.\x0a\x09\x09[[[\x09step\x0a        \x09\x09ensure: [ testCase context: nil. step := nil. testCase isAsync ifFalse: [ testCase tearDown ]]]\x0a\x09\x09\x09\x09on: TestFailure do: [:ex | self exception: ex ifNotAsync: [ result addFailure: testCase]]]\x0a\x09\x09\x09\x09on: Error do: [:ex | self exception: ex ifNotAsync: [ result addError: testCase]]]\x0a\x09\x09\x09\x09ensure: [ testCase isAsync ifFalse: [ result increaseRuns. finished value ]]]",
+messageSends: ["whileFalse:", "context:", "ensure:", "ifFalse:", "increaseRuns", "value", "isAsync", "on:do:", "exception:ifNotAsync:", "addError:", "addFailure:", "tearDown", "isNil"],
 referencedClasses: ["Error", "TestFailure"]
 referencedClasses: ["Error", "TestFailure"]
 }),
 }),
 smalltalk.RunningTestContext);
 smalltalk.RunningTestContext);

+ 17 - 7
st/SUnit-Tests.st

@@ -3,6 +3,12 @@ TestCase subclass: #SUnitAsyncTest
 	instanceVariableNames: 'flag'
 	instanceVariableNames: 'flag'
 	package: 'SUnit-Tests'!
 	package: 'SUnit-Tests'!
 
 
+!SUnitAsyncTest methodsFor: 'private'!
+
+sortedSelectors: aCollection
+	^(aCollection collect: [:each | each selector]) sorted
+! !
+
 !SUnitAsyncTest methodsFor: 'running'!
 !SUnitAsyncTest methodsFor: 'running'!
 
 
 setUp
 setUp
@@ -18,26 +24,30 @@ tearDown
 fakeError
 fakeError
 	flag := 'bad'.
 	flag := 'bad'.
 	self graceTime: 10.
 	self graceTime: 10.
-    flag := (self async: [ self error: 'Intentional'. self finished. flag := 'ok' ]) valueWithTimeout: 5
+    flag := (self async: [ flag := 'ok'. self error: 'Intentional' ]) valueWithTimeout: 5
+!
+
+fakeErrorFailingInTearDown
+	flag := 'bad'.
+	self graceTime: 10.
+    flag := (self async: [ self error: 'Intentional' ]) valueWithTimeout: 5
 !
 !
 
 
 fakeFailure
 fakeFailure
 	flag := 'bad'.
 	flag := 'bad'.
 	self graceTime: 10.
 	self graceTime: 10.
-    flag := (self async: [ self assert: false. self finished. flag := 'ok' ]) valueWithTimeout: 5
+    flag := (self async: [ flag := 'ok'. self assert: false ]) valueWithTimeout: 5
 !
 !
 
 
 testAsyncErrorsAndFailuresWork
 testAsyncErrorsAndFailuresWork
 	| suite runner result assertBlock |
 	| suite runner result assertBlock |
-	suite := { self class selector: 'fakeError'. self class selector: 'fakeFailure'. self class selector: 'testPass' }.
+	suite := #('fakeError' 'fakeErrorFailingInTearDown' 'fakeFailure' 'testPass') collect: [ :each | self class selector: each ].
     runner := TestSuiteRunner on: suite.
     runner := TestSuiteRunner on: suite.
     self graceTime: 200.
     self graceTime: 200.
 	result := runner result.
 	result := runner result.
     assertBlock := self async: [
     assertBlock := self async: [
-		self assert: 1 equals: result errors size.
-		self assert: 'fakeError' equals: result errors first selector.
-		self assert: 1 equals: result failures size.
-		self assert: 'fakeFailure' equals: result failures first selector.
+		self assert: #('fakeError') equals: (self sortedSelectors: result errors).
+		self assert: #('fakeErrorFailingInTearDown' 'fakeFailure') equals: (self sortedSelectors: result failures).
 		self finished
 		self finished
   	].
   	].
     runner announcer on: ResultAnnouncement do: [:ann |
     runner announcer on: ResultAnnouncement do: [:ann |

+ 17 - 10
st/SUnit.st

@@ -14,7 +14,7 @@ result: aTestResult
 ! !
 ! !
 
 
 Object subclass: #RunningTestContext
 Object subclass: #RunningTestContext
-	instanceVariableNames: 'finished testCase result'
+	instanceVariableNames: 'finished testCase result step'
 	package: 'SUnit'!
 	package: 'SUnit'!
 
 
 !RunningTestContext methodsFor: 'accessing'!
 !RunningTestContext methodsFor: 'accessing'!
@@ -31,18 +31,25 @@ testCase: aTestCase
 	testCase := aTestCase
 	testCase := aTestCase
 ! !
 ! !
 
 
+!RunningTestContext methodsFor: 'private'!
+
+exception: anException ifNotAsync: aBlock
+	testCase isAsync
+		ifTrue: [ step := [ testCase finished. anException signal ]]
+		ifFalse: [ aBlock value ]
+! !
+
 !RunningTestContext methodsFor: 'running'!
 !RunningTestContext methodsFor: 'running'!
 
 
 execute: aBlock
 execute: aBlock
-    testCase context: self.
-	[[[	aBlock
-        	ensure: [ testCase context: nil.
-				testCase isAsync ifFalse: [ testCase tearDown ]]]
-			on: TestFailure do: [:ex | testCase isAsync ifTrue: [ testCase finished ]. result addFailure: testCase]]
-			on: Error do: [:ex | testCase isAsync ifTrue: [ testCase finished ]. result addError: testCase]]
-			ensure: [ testCase isAsync ifFalse: [
-                result increaseRuns.
-                finished value ]]
+    step := aBlock.
+	[ step isNil ] whileFalse: [
+	    testCase context: self.
+		[[[	step
+        		ensure: [ testCase context: nil. step := nil. testCase isAsync ifFalse: [ testCase tearDown ]]]
+				on: TestFailure do: [:ex | self exception: ex ifNotAsync: [ result addFailure: testCase]]]
+				on: Error do: [:ex | self exception: ex ifNotAsync: [ result addError: testCase]]]
+				ensure: [ testCase isAsync ifFalse: [ result increaseRuns. finished value ]]]
 !
 !
 
 
 start
 start