Skip to content

Commit 09f6c37

Browse files
committed
Adds tests for makeAff paths
1 parent 5110647 commit 09f6c37

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

bower.json

+3
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"purescript-exceptions": "^1.0.0",
2222
"purescript-functions": "^1.0.0",
2323
"purescript-transformers": "^1.0.0"
24+
},
25+
"devDependencies": {
26+
"purescript-partial": "^1.1.2"
2427
}
2528
}

test/Test/Main.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
exports.synchronousUnexpectedThrowError = function() {
4+
throw new Error("ok");
5+
};

test/Test/Main.purs

+22-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ 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)
17-
18-
import Data.Either (Either(..), either)
17+
import Data.Either (Either(..), either, fromLeft, fromRight)
1918
import Data.Unfoldable (replicate)
19+
import Partial.Unsafe (unsafePartial)
2020

2121
type Test a = forall e. Aff (console :: CONSOLE | e) a
2222
type TestAVar a = forall e. Aff (console :: CONSOLE, avar :: AVAR | e) a
@@ -30,6 +30,21 @@ test_sequencing n = do
3030
later' 100 (log (show (n / 10) <> " seconds left"))
3131
test_sequencing (n - 1)
3232

33+
foreign import synchronousUnexpectedThrowError :: forall e. Eff e Unit
34+
35+
test_makeAff :: Test Unit
36+
test_makeAff = unsafePartial do
37+
s <- attempt $ makeAff \reject resolve -> resolve "ok"
38+
log $ "makeAff success is " <> fromRight s
39+
40+
asyncF <- attempt $ makeAff \reject resolve -> reject (error "ok")
41+
log $ "makeAff asynchronous failure is " <> message (fromLeft asyncF)
42+
43+
asyncF <- attempt $ makeAff \reject resolve -> synchronousUnexpectedThrowError
44+
log $ "makeAff synchronous failure is " <> message (fromLeft asyncF)
45+
46+
log "Success: makeAff is ok"
47+
3348
test_pure :: Test Unit
3449
test_pure = do
3550
pure unit
@@ -60,7 +75,6 @@ test_killFirstForked = do
6075
b <- c `cancel` (error "Just die")
6176
log (if b then "Success: Killed first forked" else "Failure: Couldn't kill first forked")
6277

63-
6478
test_killVar :: TestAVar Unit
6579
test_killVar = do
6680
v <- makeVar
@@ -180,6 +194,9 @@ main = runAff throwException (const (pure unit)) $ do
180194
log "Testing pure"
181195
test_pure
182196

197+
log "Testing makeAff"
198+
test_makeAff
199+
183200
log "Testing attempt"
184201
test_attempt
185202

0 commit comments

Comments
 (0)