diff --git a/core-lib/Assertions.som b/core-lib/Assertions.som index 38129dfe9..590671c2f 100644 --- a/core-lib/Assertions.som +++ b/core-lib/Assertions.som @@ -76,15 +76,11 @@ class Assertions usingVmMirror: vmMirror usingKernel: kernel usingPlatform: plat ^vmMirror isPromiseComplete: aPromise. ) - public assertResultUsed = ( + public isResultUsed = ( | pp | pp := createUntracedPromisePair. vmMirror assertResultUsed: (pp resolver). - pp promise whenResolved:[ :r | - r ifFalse: [ - signalAssertionError: 'Result Unused' - ] - ] + ^ pp promise ) public assert: aBlock = ( @@ -92,62 +88,35 @@ class Assertions usingVmMirror: vmMirror usingKernel: kernel usingPlatform: plat ) public assert: aBlock msg: msg = ( - aBlock value ifFalse:[ - signalAssertionError: msg + isPromise: aBlock ifTrue: [ + aBlock whenResolved: [ :r | r ifFalse:[signalAssertionError: msg]] + ] ifFalse: [ + aBlock value ifFalse:[signalAssertionError: msg] ] ) - public assertNext: aBlock = ( - assertNext: aBlock msg: ''. - ) - - public assertNext: aBlock msg: msg = ( + public next: aBlock = ( | pp | pp := createUntracedPromisePair. vmMirror assertNext: aBlock res: (pp resolver). - pp promise whenResolved:[ :r | - r ifFalse: [ - signalAssertionError: msg - ] - ] + ^ pp promise ) - public assertFuture: aBlock = ( - - assertFuture: aBlock msg: ''. - ) - - public assertFuture: aBlock msg: msg = ( + public future: aBlock = ( | pp | pp := createUntracedPromisePair. vmMirror assertFuture: aBlock res: (pp resolver). - pp promise whenResolved:[ :r | - r ifFalse: [ - signalAssertionError: msg - ] - ] - ) - - public assertGlobally: aBlock = ( - assertGlobally: aBlock msg: ''. + ^ pp promise ) - public assertGlobally: aBlock msg: msg= ( + public globally: aBlock = ( | pp | pp := createUntracedPromisePair. vmMirror assertGlobally: aBlock res: (pp resolver). - pp promise whenResolved:[ :r | - r ifFalse: [ - signalAssertionError: msg - ] - ] + ^ pp promise ) public assert: aBlock until: anotherBlock = ( - assert: aBlock until: anotherBlock msg: ''. - ) - - public assert: aBlock until: anotherBlock msg: msg = ( | pp | pp := createUntracedPromisePair. vmMirror assert: aBlock until: anotherBlock res: (pp resolver). @@ -159,10 +128,6 @@ class Assertions usingVmMirror: vmMirror usingKernel: kernel usingPlatform: plat ) public assert: aBlock release: anotherBlock = ( - assert: aBlock release: anotherBlock msg: ''. - ) - - public assert: aBlock release: anotherBlock msg: msg = ( | pp | pp := createUntracedPromisePair. vmMirror assert: aBlock release: anotherBlock res: (pp resolver). @@ -173,7 +138,159 @@ class Assertions usingVmMirror: vmMirror usingKernel: kernel usingPlatform: plat ] ) + + promise: a and: b = ( + | pp aval bval done | + done := false. + pp := createUntracedPromisePair. + aval := a value. + bval := b value. + + isPromise: aval ifTrue: [ + aval whenResolved: [:r | aval := r + done ifFalse: [ + aval ifFalse: [ + pp resolve: false. + done := true. + ] ifTrue: [ + isPromise: bval ifFalse:[ + pp resolve: (aval and: bval). + done := true. + ] + ] + ] + ] + ]. + + isPromise: bval ifTrue: [ + bval whenResolved: [:r | bval := r + done ifFalse: [ + bval ifFalse: [ + pp resolve: false. + done := true. + ] ifTrue: [ + isPromise: aval ifFalse:[ + pp resolve: (aval and: bval). + done := true. + ] + ] + ] + ] + ]. + + (isPromise: aval or: (isPromise: bval)) ifFalse:[ + pp resolve: (aval and: bval). + ]. + + ^ pp promise + ) + + promise: a or: b = ( + | pp aval bval done | + done := false. + pp := createUntracedPromisePair. + aval := a value. + bval := b value. + + isPromise: aval ifTrue: [ + aval whenResolved: [:r | aval := r + done ifFalse: [ + aval ifTrue: [ + pp resolve: true. + done := true. + ] ifFalse: [ + isPromise: bval ifFalse:[ + pp resolve: (aval or: bval). + done := true. + ] + ] + ] + ] + ]. + + isPromise: bval ifTrue: [ + bval whenResolved: [:r | bval := r + done ifFalse: [ + bval ifTrue: [ + pp resolve: true. + done := true. + ] ifFalse: [ + isPromise: aval ifFalse:[ + pp resolve: (aval or: bval). + done := true. + ] + ] + ] + ] + ]. + + (isPromise: aval or: (isPromise: bval)) ifFalse:[ + pp resolve: (aval or: bval). + ]. + + ^ pp promise + ) + + promise: a implies: b = ( + | pp aval bval done | + done := false. + pp := createUntracedPromisePair. + aval := a value. + bval := b value. + + isPromise: aval ifTrue: [ + aval whenResolved: [:r | aval := r + done ifFalse: [ + aval ifFalse: [ + pp resolve: true. + done := true. + ] ifTrue: [ + isPromise: bval ifFalse:[ + pp resolve: bval. + done := true. + ] + ] + ] + ] + ]. + + isPromise: bval ifTrue: [ + bval whenResolved: [:r | bval := r + done ifFalse: [ + isPromise: aval ifFalse:[ + pp resolve: ((aval and: bval) or: (aval not)). + done := true. + ] + ] + ] + ]. + + (isPromise: aval or: (isPromise: bval)) ifFalse:[ + pp resolve: ((aval and: bval) or: (aval not)). + ]. + + ^ pp promise + ) + + not: a = ( + | pp aval | + pp := createUntracedPromisePair. + aval := a value. + + isPromise: aval ifTrue: [ + aval whenResolved: [:r | pp resolve: (r not)] + ] ifFalse: [ + pp resolve: (aval not) + ]. + + ^ pp promise + ) + private signalAssertionError: message = ( AssertionError signalWith: message ) + + private isPromise: obj = ( + ^ (ObjectMirror reflecting: obj) className = 'Promise' + ) )