为 Github 自动评分器实现 I/O Tasty-Hunit 测试

问题描述 投票:0回答:1

我接到的任务是为 GitHub 的自动评分器和 Tasty 的 IO 函数实现测试。功能代码如下:

countLetters :: IO [Int]
countLetters = do 
               putStr "First entry: "
               x <- getLine
               putStr "Second entry: "
               y <- getLine
               putStr "Third entry: "
               z <- getLine
               return [length x, length y, length z]

到目前为止我尝试过使用以下代码:

testCase "test_countLetters" $ do
         h <- openFile "/dev/null" ReadMode
         System.IO.hDuplicateTo h stdin
         
         hPutStrLn stdin "Haskell Is Fun"
         result <- countLetters
         assertEqual "Count letters" [7,2,3] result
   
         hClose h

但是,我不断收到 System.IO 未导出 hDuplicateTo 的错误。我已确保在代码顶部导入 System.IO。如果有人想要包含所有其他测试的完整代码文件,我很乐意附上它。

haskell testing io tasty
1个回答
0
投票

因@cafce25 提供答案而关闭!

© www.soinside.com 2019 - 2024. All rights reserved.