2013-08-20 11 views
5

Sto avendo una sorprendente quantità di difficoltà a ottenere i test di unità per l'esecuzione in cabala. Ho copiato il codice di prova testualmente the cabal documentation, con l'eccezione di cambiare il nome del moduloCome utilizzare dettagliata-0,9 nei test cabala

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

Tuttavia, quando provo a costruire i test, ottengo i seguenti messaggi:

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 provato a importarli direttamente da Distribution.TestSuite, ma ha affermato che non sono stati esportati. Questo è abbastanza semplice da dover fare qualcosa di stupido, ma non riesco a vedere cosa sia.

+0

'TestOptions' et al sembrano essere riferimento a una vecchia versione vecchia QuickCheck. Vi suggerisco di utilizzare un moderno framework di test (sembra che quello che state guardando sia solo un framework per far funzionare la suite di test via cabal, non costruire la suite attuale - imparare un framework gustoso o di test). –

risposta

5

Ma per quello che vale, qui è un codice che funziona:

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

non c'è molto supporto per detailed-0.9 là fuori. È possibile collegare le librerie di test esistenti per usarle, ma anche in questo caso non si otterranno informazioni sullo stato di avanzamento del test.

vi consiglio di utilizzare l'interfaccia exitcode-stdio-1.0 insieme ad un framework di test esistente + usare GHCi durante lo sviluppo.

Un esempio completo per Hspec è qui https://github.com/sol/hspec-example.

Problemi correlati