如何在cabal测试中使用detailed-0.9 [英] How to use detailed-0.9 in cabal testing

查看:72
本文介绍了如何在cabal测试中使用detailed-0.9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单元测试在cabal下运行出现了令人惊讶的难度。我已经从 cabal文档中逐字拷贝了测试代码,但更改模块名称除外

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

import Distribution.TestSuite

实例TestOptions(String,Bool)其中
name = fst
options = const []
defaultOptions _ = return(Options [])
check _ _ = []

实例PureTestable(String,Bool)其中
run(name,result)_ |结果== True =通过
|结果== False =失败(名称++失败!)

test ::(String,Bool) - >测试
test =纯

- 在实际使用中,实例'TestOptions(String,Bool)'和
- 'PureTestable(String,Bool)'作为'测试'功能,将是
- 由测试框架提供。

测试:: [测试]
测试=
[test(bar-1,True)
,test(bar-2,False)
]

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

  Test / Integral.hs:6:10:
不在范围内:类型构造函数或类TestOptions

Test / Integral.hs:12:10:
不在范围内:类型构造函数或类`PureTestable'

我试着直接从Distribution.TestSuite中导入它们,但它表示它们没有被导出。这很简单,我必须做一些愚蠢的事情,但我不明白它是什么。

但是对于 什么是值得的,下面是一些可用的代码:

  module Main(tests)其中

import Distribution.TestSuite

tests :: IO [Test]
tests = do
return [
testfooPass
,testbar(失败它没有成功!)
]

test :: String - >结果 - >测试
测试名称r =测试t
其中
t = TestInstance {
run = return(Finished r)
,name = name
,tags = ]
,options = []
,setOption = \ _ _ - >右t
}


I'm having a surprising amount of difficulty getting the unit tests to run under cabal. I've copied the test code verbatim from the cabal documentation, with the exception of changing the module name

{-# 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)
    ]

However, when I try to build the tests, I get the following messages:

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'

I tried importing them directly from Distribution.TestSuite, but it said that they weren't exported. This is simple enough that I have to be doing something stupid, but I can't see what it is.

解决方案

But for what it's worth, here is some code that works:

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
      }

这篇关于如何在cabal测试中使用detailed-0.9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆