2013-08-20 8 views
5

मुझे कैबल के तहत यूनिट परीक्षण चलाने में आश्चर्यजनक मात्रा में समस्या आ रही है। मैं the cabal documentation से शब्दशः परीक्षण कोड कॉपी किया है, मॉड्यूल का नाम बदलने केकैबेल परीक्षण में विस्तृत-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) 
    ] 

हालांकि, जब मैं परीक्षण बनाने की कोशिश के अपवाद के साथ, मैं निम्न संदेश मिलता है:

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' 

मैं उन्हें वितरण से सीधे आयात करने का प्रयास किया। टेस्टसुइट, लेकिन यह कहा गया कि उन्हें निर्यात नहीं किया गया था। यह इतना आसान है कि मुझे कुछ बेवकूफ करना है, लेकिन मैं नहीं देख सकता कि यह क्या है।

+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 इंटरफेस का उपयोग करने की सलाह देता हूं + विकास के दौरान जीएचसीआई का उपयोग करें।

Hspec के लिए एक पूर्ण उदाहरण https://github.com/sol/hspec-example है।

संबंधित मुद्दे