测试通过GHCI但在cabal测试中失败

时间:2013-12-18 07:19:49

标签: haskell ghc cabal

更新我添加了haskeline依赖项后,测试通过了。

即使cabal test运行良好,cabal build似乎无法找到我的测试用例。下面是cabal test(失败)的输出,然后是GHCI(通过)中运行测试可执行文件main的输出。

cabal test
Running 1 test suites...
Test suite test-one: RUNNING...
test-one: <stdin>: hGetLine: end of file
Test suite test-one: FAIL
Test suite logged to: dist/test/one-0.1.0.0-test-one.log
0 of 1 test suites (0 of 1 test cases) passed.

main
Cases: 3  Tried: 3  Errors: 0  Failures: 0
Counts {cases = 3, tried = 3, errors = 0, failures = 0}

以下是产生这些输出的测试代码:

module Tests (
    main
) where

import Data.Char
import Control.Monad
import System.IO
import System.Directory
import Test.HUnit
import Test.QuickCheck
import Main (four)


test1 = TestCase $ assertEqual "test upCase" "FOO" (map toUpper "foo")
test2 = TestCase $ assertEqual "testing that the result is 4" 4 4 
test3 = TestCase $ assertEqual "testing that 4 is 4" four 4

tests = TestList [TestLabel "test1" test1, TestLabel "test2" test2, TestLabel "test3" test3]

main = runTestTT $ tests

我应该改变什么来取悦cabal?

我的.cabal文件包含:

executable one
  main-is:             Main.hs
  other-modules:       Utils
  build-depends:       base ==4.6.*, mongoDB ==1.4.*, mtl ==2.1.*, directory ==1.2.*, text ==0.11.*, HUnit ==1.2.*, QuickCheck ==2.6.*
  hs-source-dirs:      src, tests

Test-Suite test-one
    type:              exitcode-stdio-1.0
    main-is:           Tests.hs
    hs-source-dirs:    src, tests
    build-depends:     base ==4.6.*, mongoDB ==1.4.*, mtl ==2.1.*, directory ==1.2.*, text ==0.11.*, HUnit ==1.2.*, QuickCheck ==2.6.*

1 个答案:

答案 0 :(得分:2)

您应该将模块Tests重命名为Main,否则将无法构建测试可执行文件。引用Haskell Report

  

Haskell 程序是模块的集合,其中之一是   惯例,必须调用Main并且必须导出值main

否则我没有看到任何明显的错误。以下是基于您的代码的工作示例:https://gist.github.com/23Skidoo/8019225

也许你正在使用cabal的旧版本?考虑升级到1.18。