testing - 如何在 cabal 测试中使用 detailed-0.9

标签 testing haskell cabal

我在让单元测试在 cabal 下运行时遇到了很多困难。我从 the cabal documentation 中逐字复制了测试代码, 除了更改模块名称之外

{-# LANGUAGE FlexibleInstances #-}
module Test.Integral ( tests ) where

import Distribution.TestSuite

instance TestOptions (String, Bool) where
    name = fst
    options = const []
    defaultOptions _ = return (Options [])
    check _ _ = []

instance PureTestable (String, Bool) where
    run (name, result) _ | result == True = Pass
                         | result == False = Fail (name ++ " failed!")

test :: (String, Bool) -> Test
test = pure

-- In actual usage, the instances 'TestOptions (String, Bool)' and
-- 'PureTestable (String, Bool)', as well as the function 'test', would be
-- provided by the test framework.

tests :: [Test]
tests =
    [ test ("bar-1", True)
    , test ("bar-2", False)
    ]

但是,当我尝试构建测试时,我收到以下消息:

Test/Integral.hs:6:10:
    Not in scope: type constructor or class `TestOptions'

Test/Integral.hs:12:10:
    Not in scope: type constructor or class `PureTestable'

我尝试直接从 Distribution.TestSuite 导入它们,但它说它们没有导出。这很简单,我必须做一些愚蠢的事情,但我看不出它是什么。

最佳答案

但对于它的值(value),这里有一些有效的代码:

module Main (tests) where

import Distribution.TestSuite

tests :: IO [Test]
tests = do
  return [   
      test "foo" Pass
    , test "bar" (Fail "It did not work out!")
    ]

test :: String -> Result -> Test
test name r = Test t
  where          
    t = TestInstance {
        run = return (Finished r)
      , name = name
      , tags = []
      , options = []
      , setOption = \_ _ -> Right t
      }

关于testing - 如何在 cabal 测试中使用 detailed-0.9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18343249/

相关文章:

testing - 使用 Composer 要求包含测试的包

php - 代码接收中的扫描输入

haskell - 我可以获得有关过度限制类型签名的警告吗?

haskell - 是否可以从 Hackage 查看软件包下载统计信息?

非开发人员测试 (QA)

testing - 在Specification.cleanup()中查找测试的结果/状态

haskell - Rank2Types 的目的是什么?

list - Data.List.Split 的 `chunksOf` 值为 0

haskell - 从 Cabal 安装时覆盖 -Werror

haskell - GHC cabal install hamlet 失败并出现一个模糊的错误