2

我正在尝试使用带有 doctests 的“data-binary-ieee754”来测试我的项目。

我使用 cabal-dev 而不是 cabal 来管理包依赖关系。我可以构建项目,但 doctest 似乎无法识别该包。

.cabal 中的 doctests 定义:

test-suite doctests
  type:            exitcode-stdio-1.0
  hs-source-dirs:  test
  main-is:         doctests.hs
  ghc-options:     -Wall -threaded
  build-depends:   base,
                   doctest >= 0.7,
                   data-binary-ieee754

测试/doctests.hs:

module Main where

import Test.DocTest

main :: IO ()
main = doctest ["src/Pattern.hs"]

的错误消息cabal-dev test doctests是:

Running 1 test suites...
Test suite doctests: RUNNING...

src/Pattern.hs:13:8:
    Could not find module `Data.Binary.IEEE754'
    Use -v to see a list of the files searched for.
Test suite doctests: FAIL
Test suite logged to: dist/test/othello-0.1.0-doctests.log
0 of 1 test suites (0 of 1 test cases) passed.

我尝试向 doctests.hs 添加一些选项,例如

main = doctest ["--optghc=-Lcabal-dev/lib",
                "--optghc=-packagedata-binary-ieee754",
                "src/Pattern.hs"]

但结果是

Running 1 test suites...
Test suite doctests: RUNNING...
doctests: <command line>: cannot satisfy -package data-binary-ieee754
    (use -v for more information)
Test suite doctests: FAIL
Test suite logged to: dist/test/othello-0.1.0-doctests.log
0 of 1 test suites (0 of 1 test cases) passed.

告诉我如何正确地做到这一点。谢谢。

4

2 回答 2

3

我自己找到了答案。

http://hackage.haskell.org/trac/ghc/ticket/6133很有帮助。

main :: IO ()
main = doctest ["--optghc=-Lcabal-dev/lib",
                "--optghc=-packagedata-binary-ieee754",
                "--optghc=-package-conf=cabal-dev/packages-7.4.1.conf",
                "src/Pattern.hs"]
于 2012-08-10T02:07:58.020 回答
0

只是为了稍微更新一下这个答案,doctest 现在允许您直接调用 ghc 选项。
您还可以加载沙盒包数据库并从 cabal 调用。

doctest [ "-package-db .cabal-sandbox/x86_64-linux-ghc-7.10.3-packages.conf.d"
        , "-isrc"
        , "src/<path-to-file>"]

这为我解决了丢失的包裹问题。

于 2016-02-09T17:45:36.047 回答