-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.hs
41 lines (35 loc) · 1.45 KB
/
example.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- You will need this
{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
-- You might not need this
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-type-defaults #-}
import qualified Data.ByteString.Lazy as B
import "procex" Procex.Prelude
import System.IO (IOMode (..), withBinaryFile)
import Test.Hspec
main :: IO ()
main = hspec $ do
describe "capture" $ do
it "captures stdout" $ capture (mq "echo" "xjjj") `shouldReturn` "xjjj\n"
describe "captureLazy" $ do
it "captures stdout lazily" $ do
out <- captureLazy $ mq "cat" "/dev/zero"
B.take 16 out `shouldBe` B.pack (take 16 $ repeat 0)
describe "captureLazyNoThrow" $ do
it "captures stdout lazily without throwing" $ do
out <- captureLazyNoThrow $ mq "diff" (pipeArgStrIn "ab\ncd") (pipeArgStrIn "ab\nce")
out `shouldBe` "2c2\n< cd\n\\ No newline at end of file\n---\n> ce\n\\ No newline at end of file\n"
describe "run" $ do
it "throws when cmd fails" $ do
run (mq "false") `shouldThrow` \(_ :: CmdException) -> True
describe "QuickCmdArg" $ do
it "allows multiple arguments" $ do
out <- capture $ mq "echo" ["12", "34"] "56"
out `shouldBe` "12 34 56\n"
it "allows passing temporary handles" $ do
license1 <- capture $ mq "cat" (0, withBinaryFile "./LICENSE" ReadMode)
license2 <- B.readFile "./LICENSE"
license1 `shouldBe` license2