From 6081fead114af28cd9be133d10a96e57e97ba5f6 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 18 Aug 2018 15:13:04 +0100 Subject: [PATCH] lib: clarify package test suites, run all easytests --- hledger-lib/test/doctests.hs | 27 +++++++++++++--------- hledger-lib/test/easytests.hs | 41 ++++------------------------------ hledger-lib/test/hunittests.hs | 8 +++++-- 3 files changed, 27 insertions(+), 49 deletions(-) mode change 100755 => 100644 hledger-lib/test/easytests.hs diff --git a/hledger-lib/test/doctests.hs b/hledger-lib/test/doctests.hs index beb18e3c4..349959989 100644 --- a/hledger-lib/test/doctests.hs +++ b/hledger-lib/test/doctests.hs @@ -1,14 +1,19 @@ {- -Runs hledger doctests. -Usage examples: in hledger source dir, -make ghci-doctest, :main [--verbose] [--slow] [CIFILEPATHSUBSTRINGS] -or: -stack test hledger-lib:test:doctests [--test-arguments '[--verbose] [--slow] [CIFILEPATHSUBSTRINGS]'] +Run doctests in Hledger source files under the current directory +(./Hledger.hs, ./Hledger/**, ./Text/**) using the doctest runner. -Arguments are case-insensitive file path substrings. +Arguments are case-insensitive file path substrings, to limit the files searched. --verbose shows files being searched for doctests and progress while running. --slow reloads ghci between each test (https://github.com/sol/doctest#a-note-on-performance). +Eg, in hledger source dir: + +$ make ghci-doctest, :main [--verbose] [--slow] [CIFILEPATHSUBSTRINGS] + +or: + +$ stack test hledger-lib:test:doctests [--test-arguments '[--verbose] [--slow] [CIFILEPATHSUBSTRINGS]'] + -} {-# LANGUAGE PackageImports #-} @@ -28,10 +33,12 @@ main = do pats = filter (not . ("-" `isPrefixOf`)) args -- find source files - sourcefiles1 <- glob "Hledger/**/*.hs" - sourcefiles2 <- glob "Text/**/*.hs" - let sourcefiles = filter (not . isInfixOf "/.") $ ["Hledger.hs"] ++ sourcefiles1 ++ sourcefiles2 - + sourcefiles <- filter (not . isInfixOf "/.") <$> mconcat [ + glob "Hledger.hs" + ,glob "Hledger/**/*.hs" + ,glob "Text/**/*.hs" + ] + -- filter by patterns (case insensitive infix substring match) let fs | null pats = sourcefiles diff --git a/hledger-lib/test/easytests.hs b/hledger-lib/test/easytests.hs old mode 100755 new mode 100644 index 212391265..0b4d96a98 --- a/hledger-lib/test/easytests.hs +++ b/hledger-lib/test/easytests.hs @@ -1,38 +1,5 @@ -#!/usr/bin/env stack exec -- ghcid -Tmain --- Run tests using project's resolver, whenever ghcid is happy. --- --- Experimental tests using easytest, an alternative to hunit (eg). --- https://hackage.haskell.org/package/easytest - -{-# LANGUAGE OverloadedStrings #-} - +{- +Run hledger-lib's easytest tests using the easytest runner. +-} import Hledger - -main :: IO () -main = do - run - -- rerun "journal.standard account types.queries.assets" - -- rerunOnly 2686786430487349354 "journal.standard account types.queries.assets" - $ tests [ - - test "journal.standard account types.queries" $ - let - j = samplejournal - journalAccountNamesMatching :: Query -> Journal -> [AccountName] - journalAccountNamesMatching q = filter (q `matchesAccount`) . journalAccountNames - namesfrom qfunc = journalAccountNamesMatching (qfunc j) j - in - tests - [ test "assets" $ - expectEq (namesfrom journalAssetAccountQuery) ["assets","assets:bank","assets:bank:checking","assets:bank:saving","assets:cash"] - , test "liabilities" $ - expectEq (namesfrom journalLiabilityAccountQuery) ["liabilities","liabilities:debts"] - , test "equity" $ - expectEq (namesfrom journalEquityAccountQuery) [] - , test "income" $ - expectEq (namesfrom journalIncomeAccountQuery) ["income","income:gifts","income:salary"] - , test "expenses" $ - expectEq (namesfrom journalExpenseAccountQuery) ["expenses","expenses:food","expenses:supplies"] - ] - - ] +main = run easytests diff --git a/hledger-lib/test/hunittests.hs b/hledger-lib/test/hunittests.hs index 711c87d47..4dda7be37 100644 --- a/hledger-lib/test/hunittests.hs +++ b/hledger-lib/test/hunittests.hs @@ -1,9 +1,13 @@ -import Hledger (tests_Hledger) +{- +Run hledger-lib's HUnit tests using the test-framework test runner, +passing --hide-successes and any additional command line args. +-} + import System.Environment (getArgs) import Test.Framework.Providers.HUnit (hUnitTestToTests) import Test.Framework.Runners.Console (defaultMainWithArgs) +import Hledger (tests_Hledger) -main :: IO () main = do args <- getArgs let args' = "--hide-successes" : args