Hspec 在 Haskell 中处理两个 IO 操作
Hspec deal with two IO actions in Haskell
我的问题是是否有办法在Haskell的HSpec中测试两个IO actions
?
就像下面的例子:(下面是错误的类型)
it "parse examples 0" $ liftM2 shouldBe (tests "ex0in.txt") (tests "ex0Out.txt")
tests :: FileType -> IO (Either String String)
我不知道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"))
我的问题是是否有办法在Haskell的HSpec中测试两个IO actions
?
就像下面的例子:(下面是错误的类型)
it "parse examples 0" $ liftM2 shouldBe (tests "ex0in.txt") (tests "ex0Out.txt")
tests :: FileType -> IO (Either String String)
我不知道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"))