在遇到一些麻烦之后,我设法配置了我的 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