[英]“Could not find module ‘Test.HUnit’” Error when executing Haskell's unittest (HUnit) in CodeRunner
I have simple unit test code for Haskell's HUnit. 我有Haskell的HUnit的简单单元测试代码。 I use Mac OS X 10.10, and I installed HUnit with cabal install hunit
. 我使用Mac OS X 10.10,并通过cabal install hunit
。
module TestSafePrelude where
import SafePrelude( safeHead )
import Test.HUnit
testSafeHeadForEmptyList :: Test
testSafeHeadForEmptyList =
TestCase $ assertEqual "Should return Nothing for empty list"
Nothing (safeHead ([]::[Int]))
testSafeHeadForNonEmptyList :: Test
testSafeHeadForNonEmptyList =
TestCase $ assertEqual "Should return (Just head) for non empty list" (Just 1)
(safeHead ([1]::[Int]))
main :: IO Counts
main = runTestTT $ TestList [testSafeHeadForEmptyList, testSafeHeadForNonEmptyList]
I can execute it with runhaskell TestSafePrelude.hs
to get the results: 我可以使用runhaskell TestSafePrelude.hs
执行它以获取结果:
Cases: 2 Tried: 2 Errors: 0 Failures: 0
Counts {cases = 2, tried = 2, errors = 0, failures = 0}
However, when I run it in Code Runner , I have error message that can't find the HUnit module. 但是,当我在Code Runner中运行它时,出现错误消息,找不到HUnit模块。
CodeRunner launches the test on a different shell environment, and this seems to be the issue. CodeRunner在不同的Shell环境上启动测试,这似乎是问题所在。 If so, what environment variables need to be added? 如果是这样,需要添加哪些环境变量? If not, what might be causing the problem? 如果没有,可能是什么原因引起的?
I also find that ghc-pkg list
from the CodeRunner does not search for the directories in ~/.ghc
which contains the HUnit. 我还发现CodeRunner的ghc-pkg list
未在~/.ghc
中搜索包含HUnit的目录。
/usr/local/Cellar/ghc/7.8.3/lib/ghc-7.8.3/package.conf.d:
Cabal-1.18.1.4
array-0.5.0.0
...
xhtml-3000.2.1
This is the results when executed in shell: 这是在shell中执行时的结果:
/usr/local/Cellar/ghc/7.8.3/lib/ghc-7.8.3/package.conf.d
Cabal-1.18.1.4
array-0.5.0.0
...
/Users/smcho/.ghc/x86_64-darwin-7.8.3/package.conf.d
...
HUnit-1.2.5.2
...
zlib-0.5.4.2
I added both ~/.cabal
and ~/.ghc
in the path, but it doesn't work. 我在路径中同时添加了~/.cabal
和~/.ghc
,但是它不起作用。
The problem was the $HOME
setup change. 问题是$HOME
设置更改。 I used different $HOME for CodeRunner, but Haskell searches for $HOME/.cabal and $HOME/.ghc for installed package. 我为CodeRunner使用了不同的$ HOME,但是Haskell搜索$ HOME / .cabal和$ HOME / .ghc作为已安装的软件包。
After my resetting $HOME to correct location, everything works fine. 将$ HOME重置为正确的位置后,一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.