An answer for https://teratail.com/questions/337667
Last active
May 11, 2021 08:32
-
-
Save kakkun61/c6f52d196e66a6f5096cd07ac24f4310 to your computer and use it in GitHub Desktop.
An answer for https://teratail.com/questions/337667
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[*] | |
charset = utf-8 | |
end_of_line = lf | |
insert_final_newline = true | |
indent_size = 2 | |
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/dist-newstyle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packages: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified UnitTestIO | |
main :: IO () | |
main = UnitTestIO.main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UnitTestIO (main) where | |
main :: IO () | |
main = interact id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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