我得到單元測試在cabal下運行的難度令人驚訝。我從the cabal documentation逐字複製測試代碼,以更改模塊名稱如何在cabal測試中使用detailed-0.9
{-# LANGUAGE FlexibleInstances #-}
module Test.Integral (tests) where
import Distribution.TestSuite
instance TestOptions (String, Bool) where
name = fst
options = const []
defaultOptions _ = return (Options [])
check _ _ = []
instance PureTestable (String, Bool) where
run (name, result) _ | result == True = Pass
| result == False = Fail (name ++ " failed!")
test :: (String, Bool) -> Test
test = pure
-- In actual usage, the instances 'TestOptions (String, Bool)' and
-- 'PureTestable (String, Bool)', as well as the function 'test', would be
-- provided by the test framework.
tests :: [Test]
tests =
[ test ("bar-1", True)
, test ("bar-2", False)
]
但是,當我嘗試建立測試外,我得到了以下信息:
Test/Integral.hs:6:10:
Not in scope: type constructor or class `TestOptions'
Test/Integral.hs:12:10:
Not in scope: type constructor or class `PureTestable'
我嘗試直接從Distribution.TestSuite中導入它們,但它表示它們未被導出。這很簡單,我必須做一些愚蠢的事情,但我看不到它是什麼。
'TestOptions'等人似乎指的是快速檢查的一個古老的舊版本。我建議你使用一個現代測試框架(看起來你正在看的只是一個通過cabal運行測試套件的框架,而不是構建實際套件 - 學習美味或測試框架)。 –