Skip to content

Commit 2eba38d

Browse files
committed
Adds tests for makeAff paths
1 parent 296b1ad commit 2eba38d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

test/Test/Main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
// module Test.Main
4+
5+
exports.synchronousUnexpectedThrowError = function () {
6+
throw new Error('ok')
7+
}

test/Test/Main.purs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import Prelude
44

55
import Control.Alt ((<|>))
66
import Control.Apply ((*>))
7-
import Control.Monad.Aff (Aff(), runAff, later, later', forkAff, forkAll, Canceler(..), cancel, attempt, finally, apathize)
7+
import Control.Monad.Aff (Aff(), runAff, makeAff, later, later', forkAff, forkAll, Canceler(..), cancel, attempt, finally, apathize)
88
import Control.Monad.Aff.AVar (AVAR(), makeVar, makeVar', putVar, modifyVar, takeVar, killVar)
99
import Control.Monad.Aff.Console (log)
1010
import Control.Monad.Aff.Par (Par(..), runPar)
1111
import Control.Monad.Cont.Class (callCC)
1212
import Control.Monad.Eff (Eff())
1313
import Control.Monad.Eff.Console (CONSOLE())
14-
import Control.Monad.Eff.Exception (EXCEPTION(), throwException, error)
14+
import Control.Monad.Eff.Exception (EXCEPTION(), throwException, error, message)
1515
import Control.Monad.Error.Class (throwError)
1616
import Control.Monad.Rec.Class (tailRecM)
1717

@@ -27,6 +27,21 @@ test_sequencing n = do
2727
later' 100 (log (show (n / 10) ++ " seconds left"))
2828
test_sequencing (n - 1)
2929

30+
foreign import synchronousUnexpectedThrowError :: forall e. Eff e Unit
31+
32+
test_makeAff :: Test Unit
33+
test_makeAff = do
34+
s <- attempt $ makeAff \reject resolve -> resolve "ok"
35+
log $ "makeAff success is " ++ (\(Right s') -> s') s
36+
37+
asyncF <- attempt $ makeAff \reject resolve -> reject (error "ok")
38+
log $ "makeAff asynchronous failure is " ++ message ((\(Left f) -> f) asyncF)
39+
40+
asyncF <- attempt $ makeAff \reject resolve -> synchronousUnexpectedThrowError
41+
log $ "makeAff synchronous failure is " ++ message ((\(Left f) -> f) asyncF)
42+
43+
log "Success: makeAff is ok"
44+
3045
test_pure :: Test Unit
3146
test_pure = do
3247
pure unit
@@ -57,7 +72,6 @@ test_killFirstForked = do
5772
b <- c `cancel` (error "Just die")
5873
log (if b then "Success: Killed first forked" else "Failure: Couldn't kill first forked")
5974

60-
6175
test_killVar :: TestAVar Unit
6276
test_killVar = do
6377
v <- makeVar
@@ -156,6 +170,9 @@ main = runAff throwException (const (pure unit)) $ do
156170
log "Testing pure"
157171
test_pure
158172

173+
log "Testing makeAff"
174+
test_makeAff
175+
159176
log "Testing attempt"
160177
test_attempt
161178

0 commit comments

Comments
 (0)