Skip to content

Instantly share code, notes, and snippets.

@kakkun61
Last active May 11, 2021 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakkun61/c6f52d196e66a6f5096cd07ac24f4310 to your computer and use it in GitHub Desktop.
Save kakkun61/c6f52d196e66a6f5096cd07ac24f4310 to your computer and use it in GitHub Desktop.
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
/dist-newstyle/
cradle:
cabal:
- path: "././"
component: "lib:unit-test-io"
- path: "././Main.hs"
component: "unit-test-io:exe:unit-test-io"
- path: "././UnitTestIO.hs"
component: "unit-test-io:exe:unit-test-io"
- path: "././"
component: "unit-test-io:test:spec"
import qualified UnitTestIO
main :: IO ()
main = UnitTestIO.main
cabal-version: >=1.10
-- Initial package description 'unit-test-io.cabal' generated by 'cabal
-- init'. For further documentation, see
-- http://haskell.org/cabal/users-guide/
name: unit-test-io
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
-- license:
-- license-file: LICENSE
author: Kazuki Okamoto
maintainer: kazuki.okamoto@kakkun61.com
-- copyright:
-- category:
build-type: Simple
-- extra-source-files: CHANGELOG.md
library
exposed-modules: UnitTestIO
build-depends: base >=4.14 && <4.15
default-language: Haskell2010
executable unit-test-io
main-is: Main.hs
other-modules: UnitTestIO
build-depends: base >=4.14 && <4.15
default-language: Haskell2010
test-suite spec
type: exitcode-stdio-1.0
main-is: UnitTestIOSpec.hs
other-modules: UnitTestIO
build-depends: base >=4.14 && <4.15,
bytestring,
hspec,
main-tester
default-language: Haskell2010
module UnitTestIO (main) where
main :: IO ()
main = interact id
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as B
import System.Exit (ExitCode (ExitSuccess))
import Test.Hspec (hspec, it, shouldBe, shouldSatisfy)
import Test.Main (captureProcessResult, prExitCode, prStderr,
prStdout, withStdin)
import qualified UnitTestIO
main =
hspec $ do
it "hello → hello" $ do
result <- withStdin "hello" $ captureProcessResult UnitTestIO.main
prExitCode result `shouldBe` ExitSuccess
prStderr result `shouldSatisfy` B.null
prStdout result `shouldBe` "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment