Hspec处理Haskell中的两个IO操作

时间:2018-06-30 03:49:15

标签: haskell monads hspec

我的问题是,是否有办法在Haskell的HSpec中测试两个IO actions

就像下面的例子一样((由于类型,下面是错误的)

  it "parse examples 0" $ liftM2 shouldBe (tests "ex0in.txt") (tests "ex0Out.txt")

  tests :: FileType -> IO (Either String String)

1 个答案:

答案 0 :(得分:3)

我不知道FileType,我认为它等于FilePath

使用do和liftIO

it "parse examples 0" $ do
  ex0in <- liftIO (tests "ex0in.txt")
  ex0out <- liftIO (tests "ex0Out.txt")
  ex0in `shouldBe` ex0out

使用join和liftIO

it "parse examples 0" $ join $ liftM2 shouldBe (liftIO (tests "ex0in.txt")) (liftIO (tests "ex0Out.txt"))