From 2b696b8f0d0a56706bd013dfaa0e7bc0efeaa22b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 12 Mar 2007 09:38:02 +0000 Subject: [PATCH] define/run tests anywhere --- TODO | 1 - Tests.hs | 27 +++++++++------------------ Utils.hs | 12 ++++++++---- hledger.hs | 17 ++++++----------- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/TODO b/TODO index f2b6316dc..654b72b83 100644 --- a/TODO +++ b/TODO @@ -13,7 +13,6 @@ speed profile, refactor, optimize basic features - -f - print !include , in thousands diff --git a/Tests.hs b/Tests.hs index 61cd79f5b..3e0de2602 100644 --- a/Tests.hs +++ b/Tests.hs @@ -3,15 +3,11 @@ module Tests where import qualified Data.Map as Map import Text.ParserCombinators.Parsec -import Test.QuickCheck -import Test.HUnit --- trying to make "*Tests> test" work --- hiding (test) ---import qualified Test.HUnit (Test.HUnit.test) import Options import Models import Parse +import Utils -- sample data @@ -260,20 +256,15 @@ parseEquals parsed other = -- hunit tests -tests = let t l f = TestLabel l $ TestCase f in TestList - [ - t "test_ledgertransaction" test_ledgertransaction - , t "test_ledgerentry" test_ledgerentry - , t "test_autofillEntry" test_autofillEntry - , t "test_expandAccountNames" test_expandAccountNames - , t "test_ledgerAccountNames" test_ledgerAccountNames +tests = runTestTT $ test [ + test_ledgertransaction + , test_ledgerentry + , test_autofillEntry + , test_expandAccountNames + , test_ledgerAccountNames + , 2 @=? 2 ] -tests2 = Test.HUnit.test - [ - "test1" ~: assertEqual "2 equals 2" 2 2 - ] - test_ledgertransaction :: Assertion test_ledgertransaction = assertParseEqual transaction1 (parse' ledgertransaction transaction1_str) @@ -300,7 +291,7 @@ test_ledgerAccountNames = -- quickcheck properties -props = +props = mapM quickCheck [ parse' ledgertransaction transaction1_str `parseEquals` (Transaction "expenses:food:dining" (Amount "$" 10)) diff --git a/Utils.hs b/Utils.hs index 76ab6d351..dc59d0c83 100644 --- a/Utils.hs +++ b/Utils.hs @@ -2,18 +2,20 @@ module Utils ( module Utils, module Data.List, module Data.Tree, - module Debug.Trace, module Text.Printf, module Text.Regex, - quickCheck, + module Debug.Trace, + module Test.QuickCheck, + module Test.HUnit ) where import Data.List import Data.Tree -import Debug.Trace -import Test.QuickCheck (quickCheck) import Text.Printf import Text.Regex +import Debug.Trace +import Test.QuickCheck hiding (test, Testable) +import Test.HUnit splitAtElement :: Eq a => a -> [a] -> [[a]] @@ -24,6 +26,8 @@ splitAtElement e l = where (first,rest) = break (e==) l' +-- testing support + -- tree tools diff --git a/hledger.hs b/hledger.hs index d545d3484..4640665d3 100644 --- a/hledger.hs +++ b/hledger.hs @@ -28,11 +28,7 @@ hledger module Main where import System -import System.Environment (withArgs) -- for testing in old hugs -import Test.HUnit (runTestTT) -import Test.QuickCheck (quickCheck) import Text.ParserCombinators.Parsec (ParseError) -import Debug.Trace import Options import Models @@ -49,7 +45,7 @@ main = do where run cmd opts acctpats descpats | cmd `isPrefixOf` "register" = register opts acctpats descpats | cmd `isPrefixOf` "balance" = balance opts acctpats descpats - | cmd `isPrefixOf` "test" = test + | cmd `isPrefixOf` "test" = selftest | otherwise = putStr usage -- commands @@ -75,13 +71,12 @@ balance opts acctpats _ = do ([],False) -> 1 otherwise -> 9999 -test :: IO () -test = do - hcounts <- runTestTT tests - qcounts <- mapM quickCheck props +selftest :: IO () +selftest = do + Tests.tests + Tests.props + -- Amount.tests return () - where showHunitCounts c = - reverse $ tail $ reverse ("passed " ++ (unwords $ drop 5 $ words (show c))) -- utils