https://github.com/nh2/proctest
A Haskell library for testing interactive command line programs
https://github.com/nh2/proctest
Last synced: about 1 month ago
JSON representation
A Haskell library for testing interactive command line programs
- Host: GitHub
- URL: https://github.com/nh2/proctest
- Owner: nh2
- License: mit
- Created: 2012-08-06T18:03:42.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2025-02-04T15:17:58.000Z (4 months ago)
- Last Synced: 2025-04-22T22:13:19.850Z (about 2 months ago)
- Language: Haskell
- Size: 23.4 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
proctest
========A Haskell library for testing interactive command line programs.
With Proctest you can write beautiful tests, for example testing `cat` with [hspec](http://hspec.github.com):
```haskell
import Control.Applicative
import Test.Hspec
import Test.HUnit
import Test.Proctestmain = hspec $ describe "cat" $ do
it "prints out what we put in" $ do-- Start up the program to test
(hIn, hOut, hErr, p) <- run "cat" []-- Make sure buffering doesn't prevent us from reading what we expect
setBuffering NoBuffering [hIn, hOut]-- Communicate with the program
hPutStrLn hIn "hello world"-- Define a convenient wrapper around 'waitOutput'.
--
-- It specifies how long we have to wait
-- (malfunctioning programs shall not block automated testing for too long)
-- and how many bytes we are sure the expected response fits into
-- (malfunctioning programs shall not flood us with garbage either).
let catWait h = asUtf8Str <$> waitOutput (seconds 0.01) 1000 h -- Wait max 10 ms, 1000 bytes-- Wait a little to allow `cat` processing the input
sleep (seconds 0.00001)-- Read the response
response <- catWait hOut-- Test if it is what we want (here using HUnit's 'expectEqual')
response @?= "hello world\n"
```Install
-------[Proctest is on Hackage](http://hackage.haskell.org/package/proctest).
`cabal install proctest`