7 Commits 2651404497 ... 9a5863100a

Author SHA1 Message Date
  Herby Vojčík 9a5863100a Edge-case test. 3 years ago
  Herby Vojčík 8394923393 Local-return-aware `Promise new:`. Fixes #1257. 3 years ago
  Herby Vojčík f442fb0f85 SUnit fix for promises rejected with non-Errors. 3 years ago
  Herby Vojčík e3af23e4be Promise tests. 3 years ago
  Herby Vojčík 2651404497 Local-return-aware `Promise new:`. Fixes #1257. 3 years ago
  Herby Vojčík 689851bad8 SUnit fix for promises rejected with non-Errors. 3 years ago
  Herby Vojčík 7a1336ff55 Promise tests. 3 years ago
4 changed files with 108 additions and 0 deletions
  1. 39 0
      lang/src/Compiler-Tests.js
  2. 7 0
      lang/src/Compiler-Tests.st
  3. 56 0
      lang/src/Kernel-Tests.js
  4. 6 0
      lang/src/Kernel-Tests.st

+ 39 - 0
lang/src/Compiler-Tests.js

@@ -1009,6 +1009,45 @@ return self;
 }; }),
 $globals.AbstractCompilerTest);
 
+$core.addMethod(
+$core.method({
+selector: "testNonLocalReturnWithCatch",
+protocol: "tests",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testNonLocalReturnWithCatch\x0a\x09self should: 'foo [ ^ 1 ] on: Error do: [ 2 ]' return: 1.\x0a\x09self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ 2 ]' return: 1.\x0a\x09self should: 'foo [ ^ 1 ] on: Error do: [ ^ 2 ]' return: 1.\x0a\x09self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ ^ 2 ]' return: 1.",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["should:return:"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+[$self._should_return_("foo [ ^ 1 ] on: Error do: [ 2 ]",(1))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["should:return:"]=1
+//>>excludeEnd("ctx");
+][0];
+[$self._should_return_("foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ 2 ]",(1))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["should:return:"]=2
+//>>excludeEnd("ctx");
+][0];
+[$self._should_return_("foo [ ^ 1 ] on: Error do: [ ^ 2 ]",(1))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["should:return:"]=3
+//>>excludeEnd("ctx");
+][0];
+$self._should_return_("foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ ^ 2 ]",(1));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturnWithCatch",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.AbstractCompilerTest);
+
 $core.addMethod(
 $core.method({
 selector: "testPascalCaseGlobal",

+ 7 - 0
lang/src/Compiler-Tests.st

@@ -236,6 +236,13 @@ testNonLocalReturn
 	self should: 'foo [ :x | ^ x + x ] value: 4. ^ 2' return: 8
 !
 
+testNonLocalReturnWithCatch
+	self should: 'foo [ ^ 1 ] on: Error do: [ 2 ]' return: 1.
+	self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ 2 ]' return: 1.
+	self should: 'foo [ ^ 1 ] on: Error do: [ ^ 2 ]' return: 1.
+	self should: 'foo [ ^ 1 ] tryIfTrue: [ true ] catch: [ ^ 2 ]' return: 1.
+!
+
 testPascalCaseGlobal
 	self should: 'foo ^Object' return: (Smalltalk globals at: 'Object').
 	self should: 'foo ^NonExistent' return: nil

+ 56 - 0
lang/src/Kernel-Tests.js

@@ -15728,6 +15728,62 @@ return $self._assert_equals_($recv(error)._messageText(),"Intentional");
 }; }),
 $globals.PromiseTest);
 
+$core.addMethod(
+$core.method({
+selector: "testPromiseExecutorAsyncNegativeTry",
+protocol: " tests",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testPromiseExecutorAsyncNegativeTry\x0a\x09self timeout: 40.\x0a\x09^ (Promise new: [ :m | [ m try: [ self error: 'Intentional' ] ] fork ])\x0a\x09\x09catch: [ :error | self assert: error messageText equals: 'Intentional' ]",
+referencedClasses: ["Promise"],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["timeout:", "catch:", "new:", "fork", "try:", "error:", "assert:equals:", "messageText"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$self._timeout_((40));
+return $recv($recv($globals.Promise)._new_((function(m){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx3) {
+//>>excludeEnd("ctx");
+return $recv(m)._try_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx4) {
+//>>excludeEnd("ctx");
+return $self._error_("Intentional");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx4) {$ctx4.fillBlock({},$ctx3,3)});
+//>>excludeEnd("ctx");
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
+//>>excludeEnd("ctx");
+}))._fork();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({m:m},$ctx1,1)});
+//>>excludeEnd("ctx");
+})))._catch_((function(error){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._assert_equals_($recv(error)._messageText(),"Intentional");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1,4)});
+//>>excludeEnd("ctx");
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testPromiseExecutorAsyncNegativeTry",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.PromiseTest);
+
 $core.addMethod(
 $core.method({
 selector: "testPromiseExecutorAsyncPositiveDo",

+ 6 - 0
lang/src/Kernel-Tests.st

@@ -2792,6 +2792,12 @@ testPromiseExecutorAsyncNegativeDo
 		catch: [ :error | self assert: error messageText equals: 'Intentional' ]
 !
 
+testPromiseExecutorAsyncNegativeTry
+	self timeout: 40.
+	^ (Promise new: [ :m | [ m try: [ self error: 'Intentional' ] ] fork ])
+		catch: [ :error | self assert: error messageText equals: 'Intentional' ]
+!
+
 testPromiseExecutorAsyncPositiveDo
 	self timeout: 40.
 	^ (Promise new: [ :m | [ m do: [ 3 ] ] fork ])