HUnit在cabal沙箱内进行测试

时间:2014-10-05 09:12:12

标签: haskell cabal hunit

遇到麻烦后,我设法配置我的Cabal项目,以便它运行一个简单的存根测试True @=? True。如果我用测试包中的常量替换一个值,它仍然有用。但是,当我尝试创建要测试的自定义数据类型的实例时,我收到链接错误。

目前该项目包含两个模块:

module TestedModule where

data MyDataType = MyData String Char Int deriving Show

boolVal = True

________________________________
module TestTestedModule where

import Test.HUnit
import TestedModule
import qualified Distribution.TestSuite as C
import qualified Distribution.TestSuite.HUnit as H

tests :: IO [C.Test]                                                            
tests = return $ map (uncurry H.test) testModule                              

testModule :: [(String, Test)]                                                
testModule = [{- ("Test Show", testShow), -}                        
                ("Test True", testTrue)
             ]

testTrue = TestCase $ boolVal @? "False!"

-- testShow = TestCase $ "blabla" @=? show (MyData "blabla" 'a' 1)

现在当testShow被注释掉时,一切都很好,但当我取消注释时,我得到:

$ cabal test
Building argparse-0.1.0.0...
Preprocessing library argparse-0.1.0.0...
[1 of 1] Compiling TestedModule         ( TestedModule.hs, dist/build/TestedModule.o )
In-place registering package-0.1.0.0...
Preprocessing test suite 'test-module' for package-0.1.0.0...
[1 of 2] Compiling TestedModule         ( TestedModule.hs, dist/build/TestedModule.o )
[2 of 2] Compiling TestArgparse     ( TestTestedModule.hs, dist/build/TestTestedModule.o ) [TestedModule changed]
In-place registering test-module-0.1.0.0...
[1 of 1] Compiling Main             ( dist/build/test-moduleStub/test-moduleStub-tmp/test-moduleStub.hs, dist/build/test-moduleStub/test-moduleStub-tmp/Main.o )
Linking dist/build/test-moduleStub/test-moduleStub ...
/home/sven/Haskell/lib/package/dist/build/libtest-package.a(TestTestedModule.o):(.data+0x50): undefined reference to `testzmargparsezm0zi1zi0zi0_TestedModule_MyData_static_info'
collect2: error: ld returned 1 exit status

即使在testShow列表中仍然注释掉testModule,也会发生错误。 package.cabal看起来像这样:

$ cat package.cabal 
-- Initial package.cabal generated by cabal init.  For further
-- documentation, see http://haskell.org/cabal/users-guide/

name:                   package
version:                0.1.0.0
synopsis:               Some description
-- description:
license:                Apache-2.0
license-file:           LICENSE
author:                 Sventimir
maintainer:             xxx@yyyy.com
-- copyright:
-- category:
build-type:             Simple
-- extra-source-files:
cabal-version:          >=1.10

library
    exposed-modules:        TestedModule
    -- other-modules:
    -- other-extensions:
    -- hs-source-dirs:
    default-language:       Haskell2010
    build-depends:          base >=4.7 && <4.8,
                        HUnit >=1.2 && <1.3,
                        containers  >=0.5 && <0.6

Test-Suite test-module
    type:                   detailed-0.9
    test-module:            TestTestedModule
    default-language:       Haskell2010
    build-depends: base >=4.7 && <4.8,
               Cabal >=1.20.0,
               HUnit >=1.2 && <1.3,
               cabal-test-hunit,
               containers >=0.5

文件全部位于:

$ ls -la /home/sven/Haskell/lib/package
drwxr-xr-x 6 sven users  4096 Oct  5 10:57 .
drwxrwxrwx 6 sven users  4096 Sep 28 11:13 ..
drwxr-xr-x 7 sven users  4096 Oct  5 10:47 .cabal-sandbox
drwxr-xr-x 8 sven users  4096 Oct  5 09:27 .git
-rw-r--r-- 1 sven users    57 Oct  4 19:06 .gitignore
-rw-r--r-- 1 sven users   546 Oct  5 10:57 TestedModule.hs
-rw-r--r-- 1 sven users 11358 Oct  4 09:27 LICENSE
-rw-r--r-- 1 sven users    46 Oct  4 09:27 Setup.hs
-rw-r--r-- 1 sven users   650 Oct  5 10:56 TestTestedModule.hs
-rw-r--r-- 1 sven users  1190 Oct  5 09:39 package.cabal
-rw r--r-- 1 sven users   990 Oct  4 18:02 cabal.sandbox.config
drwxr-xr-x 5 sven users  4096 Oct  5 11:03 dist
drwxr-xr-x 2 sven users  4096 Oct  4 09:19 orid

0 个答案:

没有答案