[英]HUnit testing with file dependent tests
我有一個詞法分析器,希望對一組已知的良好測試用例進行測試。 這些子目錄中的./test_src/舉行,每個人都有一個擴展測試名 .TXT
我想做的是獲取所有相關測試用例的路徑:
getTestFiles :: IO [FilePath]
find always (extension ==? ".txt") "/path/to/test_src/"
並創建一個包含HUnit TestCases的HUnit TestList,每個HCas TestCases都具有通過函數沿以下行創建的聲明
testMyLexer :: IO FilePath -> Assertion
類似於
myTest :: [IO FilePath] -> Test
myTest = TestList $ fmap TestCase $ fmap testMyLexer
我的方法似乎失敗的地方在於,這似乎首先需要以下功能,然后映射其結果:
unableToDoThis :: IO [FilePath] -> [IO FilePath]
我非常懷疑我所遵循的方法是不可能的,因為它似乎需要轉義IO Monad,所以我要問的是:
通常,如果將IO a
值包裝在參數中,那么您可能做錯了。 testMyLexer
和myTest
都可以是純myTest
,因此可以代替
testMyLexer :: IO FilePath -> Assertion
myTest :: [IO FilePath] -> Test
做
testMyLexer :: FilePath -> Assertion
myTest :: [FilePath] -> Test
然后,只需使用getTestFiles
來提取您的[FilePath]
:
do
files <- getTestFiles
runTestTT $ myTest files
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.