2013-08-20 8 views
5

カバールでユニットテストを実行するのに驚くほどの難しさがあります。私はテストを構築しようとすると、私は次のメッセージを取得し、しかしカバールテストでdetailed-0.9を使用する方法

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

をモジュール名を変更した以外は、the cabal documentationからそのままテストコードをコピーした:

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から直接インポートしようとしましたが、エクスポートされていないと言いました。これは私が何か愚かなことをしなければならないほど簡単ですが、私はそれが何かを見ることができません。

+0

'TestOptions'らはquickcheckの古い古いバージョンを参照するように見えます。現代のテストフレームワークを使用することをお勧めします(あなたが見ているのは、カバールを介してテストスイートを実行するためのフレームワークであり、実際のスイートを構築するのではなく、おいしいフレームやテストフレームワークを学ぶことです)。 –

答えて

5

しかし、それは価値がある何のために、ここで働くいくつかのコードは次のとおりです。

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 
     } 
3

detailed-0.9はあまりサポートされていません。既存のテストライブラリを使用してそれを使用することは可能ですが、それでもテストが成功すると進捗情報は得られません。

開発中にexitcode-stdio-1.0インターフェイスと既存のテストフレームワーク+ GHCiを使用することをお勧めします。

Hspecの完全な例は、https://github.com/sol/hspec-exampleです。

関連する問題