Skip to content

Commit 13b9b4d

Browse files
authored
Merge pull request #4 from purescript-node/1.0-updates
Updates for 1.0, fix some warnings in the test suite
2 parents f979f0c + cb88b4f commit 13b9b4d

File tree

4 files changed

+66
-43
lines changed

4 files changed

+66
-43
lines changed

bower.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
"url": "git://github.com/purescript-node/purescript-node-child-process"
88
},
99
"dependencies": {
10-
"purescript-exceptions": "~0.3.4",
11-
"purescript-foreign": "~0.7.2",
12-
"purescript-functions": "~0.1.0",
13-
"purescript-maps": "~0.5.3",
14-
"purescript-node-fs": "~0.11.0",
15-
"purescript-node-streams": "~0.4.0",
16-
"purescript-nullable": "~0.2.1",
17-
"purescript-posix-types": "~0.1.1",
18-
"purescript-unsafe-coerce": "~0.1.0"
10+
"purescript-exceptions": "^1.0.0",
11+
"purescript-foreign": "^1.0.0",
12+
"purescript-functions": "^1.0.0",
13+
"purescript-maps": "^1.0.0",
14+
"purescript-node-fs": "^1.0.0",
15+
"purescript-node-streams": "^1.0.0",
16+
"purescript-nullable": "^1.0.0",
17+
"purescript-posix-types": "^1.0.0",
18+
"purescript-unsafe-coerce": "^1.0.0"
1919
},
2020
"devDependencies": {
21-
"purescript-console": "~0.1.1"
21+
"purescript-console": "^1.0.0"
2222
}
2323
}

src/Node/ChildProcess.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22

3-
// module Node.ChildProcess
43
/* eslint-env node*/
54

65
exports.unsafeFromNullable = function unsafeFromNullable(msg){

src/Node/ChildProcess.purs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,18 @@ import Control.Bind ((>=>))
5252
import Control.Monad.Eff (Eff())
5353
import Control.Monad.Eff.Exception as Exception
5454
import Control.Monad.Eff.Exception.Unsafe (unsafeThrow)
55-
56-
import Data.StrMap (StrMap())
57-
import Data.Function (Fn2(), runFn2)
58-
import Data.Nullable (Nullable(), toNullable, toMaybe)
59-
import Data.Maybe (Maybe(..), fromMaybe)
6055
import Data.Foreign (Foreign())
56+
import Data.Function.Uncurried (Fn2(), runFn2)
57+
import Data.Maybe (Maybe(..), fromMaybe)
58+
import Data.Nullable (Nullable(), toNullable, toMaybe)
6159
import Data.Posix (Pid(), Gid(), Uid())
6260
import Data.Posix.Signal (Signal())
6361
import Data.Posix.Signal as Signal
64-
import Unsafe.Coerce (unsafeCoerce)
65-
62+
import Data.StrMap (StrMap())
6663
import Node.Buffer (Buffer())
6764
import Node.FS as FS
6865
import Node.Stream (Readable(), Writable(), Stream())
66+
import Unsafe.Coerce (unsafeCoerce)
6967

7068
-- | A handle for inter-process communication (IPC).
7169
foreign import data Handle :: *
@@ -147,7 +145,6 @@ instance showExit :: Show Exit where
147145
show (Normally x) = "Normally " <> show x
148146
show (BySignal sig) = "BySignal " <> show sig
149147

150-
151148
mkExit :: Nullable Int -> Nullable String -> Exit
152149
mkExit code signal =
153150
case fromCode code <|> fromSignal signal of

test/Main.purs

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
module Test.Main where
22

33
import Prelude
4-
import Control.Apply
5-
import Control.Bind
6-
7-
import Control.Monad.Eff.Console
8-
import Control.Monad.Eff.Console.Unsafe
94

5+
import Control.Monad.Eff (Eff)
6+
import Control.Monad.Eff.Console (CONSOLE, log)
7+
import Control.Monad.Eff.Exception (EXCEPTION)
108
import Data.Posix.Signal (Signal(..))
11-
import Node.Encoding (Encoding(UTF8))
129
import Node.Buffer as Buffer
13-
import Node.ChildProcess
10+
import Node.ChildProcess (CHILD_PROCESS, Exit(..), defaultExecOptions, exec, onError,
11+
defaultSpawnOptions, spawn, stdout, onExit, kill)
12+
import Node.Encoding (Encoding(UTF8))
1413
import Node.Stream (onData)
1514

15+
main :: forall eff. Eff
16+
( cp :: CHILD_PROCESS
17+
, console :: CONSOLE
18+
, err :: EXCEPTION
19+
, buffer :: Buffer.BUFFER
20+
| eff
21+
) Unit
1622
main = do
1723
log "spawns processes ok"
1824
spawnLs
@@ -22,38 +28,59 @@ main = do
2228
log "nonexistent executable: all good."
2329

2430
log "doesn't perform effects too early"
25-
ls <- spawn "ls" ["-la"] defaultSpawnOptions
26-
let unused = kill SIGTERM ls
27-
onExit ls \exit ->
28-
case exit of
29-
Normally 0 ->
30-
log "All good!"
31-
_ -> do
32-
log ("Bad exit: expected `Normally 0`, got: " <> show exit)
31+
spawn "ls" ["-la"] defaultSpawnOptions >>= \ls -> do
32+
let unused = kill SIGTERM ls
33+
onExit ls \exit ->
34+
case exit of
35+
Normally 0 ->
36+
log "All good!"
37+
_ -> do
38+
log ("Bad exit: expected `Normally 0`, got: " <> show exit)
3339

3440
log "kills processes"
35-
ls <- spawn "ls" ["-la"] defaultSpawnOptions
36-
kill SIGTERM ls
37-
onExit ls \exit ->
38-
case exit of
39-
BySignal SIGTERM ->
40-
log "All good!"
41-
_ -> do
42-
log ("Bad exit: expected `BySignal SIGTERM`, got: " <> show exit)
41+
spawn "ls" ["-la"] defaultSpawnOptions >>= \ls -> do
42+
kill SIGTERM ls
43+
onExit ls \exit ->
44+
case exit of
45+
BySignal SIGTERM ->
46+
log "All good!"
47+
_ -> do
48+
log ("Bad exit: expected `BySignal SIGTERM`, got: " <> show exit)
4349

4450
log "exec"
4551
execLs
4652

53+
spawnLs :: forall eff. Eff ( cp :: CHILD_PROCESS
54+
, console :: CONSOLE
55+
, err :: EXCEPTION
56+
, buffer :: Buffer.BUFFER
57+
| eff
58+
) Unit
4759
spawnLs = do
4860
ls <- spawn "ls" ["-la"] defaultSpawnOptions
4961
onExit ls \exit ->
5062
log $ "ls exited: " <> show exit
5163
onData (stdout ls) (Buffer.toString UTF8 >=> log)
5264

65+
nonExistentExecutable
66+
:: forall eff
67+
. Eff ( console :: CONSOLE
68+
, cp :: CHILD_PROCESS
69+
| eff
70+
) Unit
71+
-> Eff ( cp :: CHILD_PROCESS
72+
, console :: CONSOLE
73+
| eff
74+
) Unit
5375
nonExistentExecutable done = do
5476
ch <- spawn "this-does-not-exist" [] defaultSpawnOptions
55-
onError ch (\err -> logAny err *> done)
77+
onError ch (\err -> log err.code *> done)
5678

79+
execLs :: forall eff. Eff ( cp :: CHILD_PROCESS
80+
, console :: CONSOLE
81+
, buffer :: Buffer.BUFFER
82+
| eff
83+
) Unit
5784
execLs = do
5885
exec "ls >&2" defaultExecOptions \r ->
5986
log "redirected to stderr:" *> (Buffer.toString UTF8 r.stderr >>= log)

0 commit comments

Comments
 (0)