sydtest-typed-process (empty) → 0.0.0.0
raw patch · 5 files changed
+117/−0 lines, 5 filesdep +basedep +bytestringdep +sydtest
Dependencies added: base, bytestring, sydtest, sydtest-typed-process, typed-process
Files
- LICENSE.md +5/−0
- src/Test/Syd/Process/Typed.hs +33/−0
- sydtest-typed-process.cabal +54/−0
- test/Spec.hs +1/−0
- test/Test/Syd/Process/TypedSpec.hs +24/−0
+ LICENSE.md view
@@ -0,0 +1,5 @@+# Sydtest License++Copyright (c) 2020-2021 Tom Sydney Kerckhove++See the Sydtest License at https://github.com/NorfairKing/sydtest/blob/master/sydtest/LICENSE.md for the full license text.
+ src/Test/Syd/Process/Typed.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeOperators #-}++module Test.Syd.Process.Typed where++import System.Process.Typed+import Test.Syd++-- | Run a given process while a test is running and give access to a process handle as an inner resource.+--+-- See 'typedProcessSetupFunc'.+typedProcessSpec :: ProcessConfig stdin stdout stderr -> TestDefM outers (Process stdin stdout stderr) result -> TestDefM outers () result+typedProcessSpec pc = setupAround $ typedProcessSetupFunc pc++-- | Run a given process while a group of tests is running and give access to a process handle as an outer resource.+--+-- See 'typedProcessSetupFunc'.+--+-- == __FOOTGUN__+--+-- The process will be shared accross multiple tests.+-- This may well be a good idea because starting the process can be prohibitively expensive to do around every test.+-- However, sharing the process means that tests could be sharing state.+-- When using this function, it is important to implement some form of cleaning the state before every test.+-- It is also important to use 'sequential' if some such state is maintained (and cleaned) so that the state is not cleaned while another test is running.+outerTypedProcessSpec :: ProcessConfig stdin stdout stderr -> TestDefM (Process stdin stdout stderr ': outers) inner result -> TestDefM outers inner result+outerTypedProcessSpec pc = setupAroundAll $ typedProcessSetupFunc pc++-- | Set up a process beforehand and stop it afterwards.+--+-- The process will be terminated using 'stopProcess'.+typedProcessSetupFunc :: ProcessConfig stdin stdout stderr -> SetupFunc (Process stdin stdout stderr)+typedProcessSetupFunc pc = bracketSetupFunc (startProcess pc) stopProcess
+ sydtest-typed-process.cabal view
@@ -0,0 +1,54 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.4.+--+-- see: https://github.com/sol/hpack++name: sydtest-typed-process+version: 0.0.0.0+synopsis: A typed-process companion library for sydtest+category: Testing+homepage: https://github.com/NorfairKing/sydtest#readme+bug-reports: https://github.com/NorfairKing/sydtest/issues+author: Tom Sydney Kerckhove+maintainer: syd@cs-syd.eu+copyright: Copyright (c) 2021 Tom Sydney Kerckhove+license: OtherLicense+license-file: LICENSE.md+build-type: Simple++source-repository head+ type: git+ location: https://github.com/NorfairKing/sydtest++library+ exposed-modules:+ Test.Syd.Process.Typed+ other-modules:+ Paths_sydtest_typed_process+ hs-source-dirs:+ src+ build-depends:+ base >=4.7 && <5+ , sydtest+ , typed-process+ default-language: Haskell2010++test-suite sydtest-typed-process-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Test.Syd.Process.TypedSpec+ Paths_sydtest_typed_process+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+ build-tool-depends:+ sydtest-discover:sydtest-discover+ build-depends:+ base >=4.7 && <5+ , bytestring+ , sydtest+ , sydtest-typed-process+ , typed-process+ default-language: Haskell2010
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF sydtest-discover #-}
+ test/Test/Syd/Process/TypedSpec.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE OverloadedStrings #-}++module Test.Syd.Process.TypedSpec (spec) where++import qualified Data.ByteString as SB+import System.IO+import System.Process.Typed+import Test.Syd+import Test.Syd.Process.Typed++spec :: Spec+spec = typedProcessSpec (setStdin createPipe $ setStdout createPipe $ setStderr inherit $ proc "cat" []) $ do+ -- This test fails, see+ -- https://github.com/fpco/typed-process/issues/38+ xit "can communicate with the process" $ \ph -> do+ let inHandle = getStdin ph+ let outHandle = getStdout ph+ let contents = "Hello world"+ hSetBuffering inHandle NoBuffering+ hSetBuffering outHandle NoBuffering+ SB.hPut inHandle contents+ hFlush inHandle+ output <- SB.hGet outHandle (SB.length contents)+ output `shouldBe` contents