Bladeren bron

Async tests can now be rerun individually.

Herby Vojčík 11 jaren geleden
bovenliggende
commit
5ed9da31b3
3 gewijzigde bestanden met toevoegingen van 93 en 18 verwijderingen
  1. 29 6
      js/SUnit.deploy.js
  2. 42 9
      js/SUnit.js
  3. 22 3
      st/SUnit.st

+ 29 - 6
js/SUnit.deploy.js

@@ -159,6 +159,34 @@ return $1;
 smalltalk.RunningTestContext.klass);
 
 
+smalltalk.addClass('ErroringTestContext', smalltalk.RunningTestContext, [], 'SUnit');
+smalltalk.addMethod(
+"_exception_ifNotAsync_",
+smalltalk.method({
+selector: "exception:ifNotAsync:",
+fn: function (anException,aBlock){
+var self=this;
+smalltalk.send(anException,"_signal",[]);
+return self}
+}),
+smalltalk.ErroringTestContext);
+
+
+smalltalk.addMethod(
+"_testCase_",
+smalltalk.method({
+selector: "testCase:",
+fn: function (aTestCase){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_testCase_result_finished_",[aTestCase,smalltalk.send((smalltalk.TestResult || TestResult),"_new",[]),(function(){
+})]);
+return $1;
+}
+}),
+smalltalk.ErroringTestContext.klass);
+
+
 smalltalk.addClass('TestCase', smalltalk.Object, ['testSelector', 'asyncTimeout', 'context'], 'SUnit');
 smalltalk.addMethod(
 "_assert_",
@@ -312,12 +340,7 @@ smalltalk.method({
 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",[]);
-})]);
+smalltalk.send(smalltalk.send((smalltalk.ErroringTestContext || ErroringTestContext),"_testCase_",[self]),"_start",[]);
 return self}
 }),
 smalltalk.TestCase);

+ 42 - 9
js/SUnit.js

@@ -204,6 +204,44 @@ referencedClasses: []
 smalltalk.RunningTestContext.klass);
 
 
+smalltalk.addClass('ErroringTestContext', smalltalk.RunningTestContext, [], 'SUnit');
+smalltalk.addMethod(
+"_exception_ifNotAsync_",
+smalltalk.method({
+selector: "exception:ifNotAsync:",
+category: 'private',
+fn: function (anException,aBlock){
+var self=this;
+smalltalk.send(anException,"_signal",[]);
+return self},
+args: ["anException", "aBlock"],
+source: "exception: anException ifNotAsync: aBlock\x0a\x09anException signal",
+messageSends: ["signal"],
+referencedClasses: []
+}),
+smalltalk.ErroringTestContext);
+
+
+smalltalk.addMethod(
+"_testCase_",
+smalltalk.method({
+selector: "testCase:",
+category: 'instance creation',
+fn: function (aTestCase){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_testCase_result_finished_",[aTestCase,smalltalk.send((smalltalk.TestResult || TestResult),"_new",[]),(function(){
+})]);
+return $1;
+},
+args: ["aTestCase"],
+source: "testCase: aTestCase\x0a\x09^self\x0a        testCase: aTestCase\x0a        result: TestResult new\x0a        finished: []",
+messageSends: ["testCase:result:finished:", "new"],
+referencedClasses: ["TestResult"]
+}),
+smalltalk.ErroringTestContext.klass);
+
+
 smalltalk.addClass('TestCase', smalltalk.Object, ['testSelector', 'asyncTimeout', 'context'], 'SUnit');
 smalltalk.addMethod(
 "_assert_",
@@ -413,17 +451,12 @@ selector: "runCase",
 category: 'running',
 fn: function (){
 var self=this;
-smalltalk.send((function(){
-smalltalk.send(self,"_setUp",[]);
-return smalltalk.send(self,"_performTest",[]);
-}),"_ensure_",[(function(){
-return smalltalk.send(self,"_tearDown",[]);
-})]);
+smalltalk.send(smalltalk.send((smalltalk.ErroringTestContext || ErroringTestContext),"_testCase_",[self]),"_start",[]);
 return self},
 args: [],
-source: "runCase\x0a\x09[\x09self setUp.\x0a\x09\x09self performTest ] ensure: [\x0a\x09\x09self tearDown ]\x0a",
-messageSends: ["ensure:", "tearDown", "setUp", "performTest"],
-referencedClasses: []
+source: "runCase\x0a\x09\x22Runs a test case in isolated context, leaking all errors.\x22\x0a\x0a\x09(ErroringTestContext testCase: self) start",
+messageSends: ["start", "testCase:"],
+referencedClasses: ["ErroringTestContext"]
 }),
 smalltalk.TestCase);
 

+ 22 - 3
st/SUnit.st

@@ -66,6 +66,25 @@ testCase: aTestCase result: aTestResult finished: aBlock
         yourself
 ! !
 
+RunningTestContext subclass: #ErroringTestContext
+	instanceVariableNames: ''
+	package: 'SUnit'!
+
+!ErroringTestContext methodsFor: 'private'!
+
+exception: anException ifNotAsync: aBlock
+	anException signal
+! !
+
+!ErroringTestContext class methodsFor: 'instance creation'!
+
+testCase: aTestCase
+	^self
+        testCase: aTestCase
+        result: TestResult new
+        finished: []
+! !
+
 Object subclass: #TestCase
 	instanceVariableNames: 'testSelector asyncTimeout context'
 	package: 'SUnit'!
@@ -126,9 +145,9 @@ performTest
 !
 
 runCase
-	[	self setUp.
-		self performTest ] ensure: [
-		self tearDown ]
+	"Runs a test case in isolated context, leaking all errors."
+
+	(ErroringTestContext testCase: self) start
 !
 
 setUp