我遇到了奇怪的HUnit
行爲。如果Nothing == Nothing
條件存在於測試中,則不允許編譯測試用例。這裏是我的代碼再現這種行爲:如果在測試中存在`Nothing == Nothing`條件,則HUnit不允許編譯測試用例
module TestTest where
import Control.Exception
import Control.Monad
import Test.HUnit
import Test.AssertError
testTests = test [
"test A01" ~: "x == x" ~: True ~=? Nothing == Nothing,
"test _" ~: "empty test" ~: True ~=? True
]
runTests :: IO Counts
runTests = do
runTestTT testTests
嘗試將文件與下面的錯誤此內容ghci
回報加載:
[2 of 2] Compiling TestTest (Test/TestTest.hs, interpreted)
Test/TestTest.hs:9:49:
No instance for (Eq a0) arising from a use of ‘==’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Eq Counts -- Defined in ‘Test.HUnit.Base’
instance Eq Node -- Defined in ‘Test.HUnit.Base’
instance Eq State -- Defined in ‘Test.HUnit.Base’
...plus 53 others
In the second argument of ‘(~=?)’, namely ‘Nothing == Nothing’
In the second argument of ‘(~:)’, namely
‘True ~=? Nothing == Nothing’
In the second argument of ‘(~:)’, namely
‘"x == x" ~: True ~=? Nothing == Nothing’
Failed, modules loaded: Test.AssertError.
注意在同一測試用例條件Just 2 == Just 2
工作正常。如果我在ghci
中輸入Nothing == Nothing
,則按預期返回True
。
任何想法爲什麼HUnit
可能會這樣?這是一個錯誤還是預期的行爲?
您應該指定'Maybe a'的類型。 –