我遇到了奇怪的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'的类型。 –