Tony Garnock-Jones uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-tonyg.354.mcz==================== Summary ====================
Name: KernelTests-tonyg.354
Author: tonyg
Time: 30 January 2019, 5:20:42.793134 pm
UUID: c2e9e25b-0ef1-4bd1-bdde-0c11647c959c
Ancestors: KernelTests-eem.353
Improve promise resolution error handling via #fulfillWith:.
=============== Diff against KernelTests-eem.353 ===============
Item was added:
+ ----- Method: PromiseTest>>testFulfillWithError (in category 'testing') -----
+ testFulfillWithError
+ | p |
+ p := Promise new.
+ p fulfillWith: [ 1 / 0 ] passErrors: false.
+ self assert: p isRejected.
+ self assert: ZeroDivide equals: p error class.!
Item was added:
+ ----- Method: PromiseTest>>testFulfillWithHaltAndResult (in category 'testing') -----
+ testFulfillWithHaltAndResult
+ | p |
+ p := Promise new.
+ [
+ p fulfillWith: [ self halt. 3 + 4 ]
+ ] on: Halt do: [:ex | ex resume].
+ self assert: p isResolved.
+ self assert: 7 equals: p value.!
Item was added:
+ ----- Method: PromiseTest>>testFulfillWithResult (in category 'testing') -----
+ testFulfillWithResult
+ | p |
+ p := Promise new.
+ p fulfillWith: [ 3 + 4 ].
+ self assert: p isResolved.
+ self assert: 7 equals: p value.!
Item was added:
+ ----- Method: PromiseTest>>testFutureRejectionInvisibleError (in category 'testing - future') -----
+ testFutureRejectionInvisibleError
+ | p |
+ p := 1 future / 0.
+ p whenRejected: []. "Installing a rejection handler is enough to cause the exception to be swallowed."
+ self assert: (self waitUntil: [p isRejected] orCycleCount: 100).
+ self assert: p isRejected.
+ self assert: ZeroDivide equals: p error class.!
Item was added:
+ ----- Method: PromiseTest>>testFutureRejectionVisibleError (in category 'testing - future') -----
+ testFutureRejectionVisibleError
+ | p |
+ p := 1 future / 0.
+ [
+ self assert: (self waitUntil: [p isRejected] orCycleCount: 100)
+ ] on: ZeroDivide do: [:ex | "Fall through." ].
+ self assert: p isRejected.
+ self assert: ZeroDivide equals: p error class.!
Item was added:
+ ----- Method: PromiseTest>>testFutureResolution (in category 'testing - future') -----
+ testFutureResolution
+ | p |
+ p := 3 future + 4.
+ self assert: (self waitUntil: [p isResolved] orCycleCount: 100).
+ self assert: p isResolved.
+ self assert: 7 equals: p value.!
Item was added:
+ ----- Method: PromiseTest>>waitUntil:orCycleCount: (in category 'testing - future') -----
+ waitUntil: aBlock orCycleCount: anInteger
+ "This is a gross hack that depends on running the tests in Morphic.
+ We simply repeatedly do a cycle of the interaction loop, which happens
+ to also be the way that the queue of pending futures gets serviced."
+ | counter |
+ counter := 0.
+ [
+ aBlock value ifTrue: [^ true].
+ World doOneSubCycle.
+ counter := counter + 1.
+ counter >= anInteger ifTrue: [^ false].
+ ] repeat!