From c7574b8005a84c6116a2871313ce8417b492a823 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 29 Nov 2019 06:06:36 -0800 Subject: [PATCH] ;lib, cli: test suite cleanups, don't run hledger-lib tests twice --- hledger-lib/package.yaml | 18 ++++++++---------- hledger-lib/test/unittests.hs | 11 ++++++----- hledger/Hledger/Cli.hs | 7 +------ hledger/Hledger/Cli/Commands.hs | 28 +++++++++++++++------------- hledger/test/test.hs | 13 +++++++++---- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/hledger-lib/package.yaml b/hledger-lib/package.yaml index e2ff724d3..c20737868 100644 --- a/hledger-lib/package.yaml +++ b/hledger-lib/package.yaml @@ -152,6 +152,14 @@ library: tests: + unittests: + buildable: true + source-dirs: test + main: unittests.hs + other-modules: [] # prevent double compilation, https://github.com/sol/hpack/issues/188 + dependencies: + - hledger-lib + doctests: buildable: true source-dirs: test @@ -173,18 +181,8 @@ tests: # - condition: os(darwin) && impl(ghc >= 8.4) # buildable: false - # ghc 7.10 on linux: - # doctests: : Can't parse package flag: package-db /home/simon/.stack/snapshots/i386-linux/026d718ac4d5f70d983bbeebb712f79d402a8e7003bbfe787f9e853573ed7ed6/7.10.3/pkgdb # ghc 8.0 on linux: # Hledger/Read/JournalReader.hs:126: failure in expression `rejp (journalp <* eof) "2015/1/1\n a 0\n"' ... Variable not in scope: rejp :: f0 a0 -> [Char] -> t when: - condition: (impl(ghc < 8.2)) buildable: false - - unittests: - buildable: true - source-dirs: test - main: unittests.hs - other-modules: [] # prevent double compilation, https://github.com/sol/hpack/issues/188 - dependencies: - - hledger-lib diff --git a/hledger-lib/test/unittests.hs b/hledger-lib/test/unittests.hs index 42d4f586b..34bb6cd46 100644 --- a/hledger-lib/test/unittests.hs +++ b/hledger-lib/test/unittests.hs @@ -1,10 +1,11 @@ -{-# LANGUAGE PackageImports #-} {- -Run hledger-lib's unit tests using tasty's test runner. -Note that we use package-qualified import to overcome -Cabal heuristic missing-home-modules. +Run the hledger-lib package's unit tests using the tasty test runner. -} -import "hledger-lib" Hledger + +-- package-qualified import to avoid cabal missing-home-modules warning (and double-building ?) +{-# LANGUAGE PackageImports #-} +import "hledger-lib" Hledger (tests_Hledger) + import Test.Tasty (defaultMain) main = defaultMain tests_Hledger diff --git a/hledger/Hledger/Cli.hs b/hledger/Hledger/Cli.hs index 13a7791e4..dc4083ca1 100644 --- a/hledger/Hledger/Cli.hs +++ b/hledger/Hledger/Cli.hs @@ -16,7 +16,6 @@ module Hledger.Cli ( module Hledger.Cli.Utils, module Hledger.Cli.Version, module Hledger, - tests_Cli, module System.Console.CmdArgs.Explicit ) where @@ -29,8 +28,4 @@ import Hledger.Cli.DocFiles import Hledger.Cli.Utils import Hledger.Cli.Version --- unit tests for code under Hledger.Cli (hledger-lib tests not included) -tests_Cli = tests "Hledger.Cli" [ - tests_Cli_Utils - ,tests_Commands - ] +-- unit tests (tests_Hledger_Cli) are defined in Hledger.Cli.Commands diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index 3e1b0d723..b6092e3b0 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -16,7 +16,7 @@ module Hledger.Cli.Commands ( ,builtinCommands ,builtinCommandNames ,printCommandsList - ,tests_Commands + ,tests_Hledger_Cli ,module Hledger.Cli.Commands.Accounts ,module Hledger.Cli.Commands.Activity ,module Hledger.Cli.Commands.Add @@ -261,32 +261,35 @@ testmode = hledgerCommandMode [] ([], Just $ argsFlag "[-- TASTYOPTS]") --- | The test command. +-- | The test command, which runs the hledger and hledger-lib +-- packages' unit tests. This command also accepts tasty test runner +-- options, written after a -- (double hyphen). +-- -- Unlike most hledger commands, this one does not read the user's journal. -- A 'Journal' argument remains in the type signature, but it should -- not be used (and would raise an error). -- --- This command also accepts tasty test runner options, --- written after a -- (double hyphen). --- testcmd :: CliOpts -> Journal -> IO () testcmd opts _undefined = do withArgs (words' $ query_ $ reportopts_ opts) $ Test.Tasty.defaultMain $ tests "hledger" [ tests_Hledger - ,tests "Hledger.Cli" [ - tests_Cli_Utils - ,tests_Commands - ] + ,tests_Hledger_Cli ] +-- All unit tests for Hledger.Cli, defined here rather than +-- Hledger.Cli so testcmd can use them. +tests_Hledger_Cli = tests "Hledger.Cli" [ + tests_Cli_Utils + ,tests_Commands + ] tests_Commands = tests "Commands" [ tests_Balance ,tests_Register -- some more tests easiest to define here: - + ,tests "apply account directive" [ test "works" $ do let @@ -315,7 +318,7 @@ tests_Commands = tests "Commands" [ paccount p @?= "test:from" ptype p @?= VirtualPosting ] - + ,test "alias directive" $ do j <- readJournal def Nothing "!alias expenses = equity:draw:personal\n1/1\n (expenses:food) 1\n" >>= either error' return let p = head $ tpostings $ head $ jtxns j @@ -347,8 +350,7 @@ tests_Commands = tests "Commands" [ ,test "show hours" $ showAmount (hrs 1) @?= "1.00h" - ] - + ] -- test data diff --git a/hledger/test/test.hs b/hledger/test/test.hs index 24da64dee..d08ad8fdd 100644 --- a/hledger/test/test.hs +++ b/hledger/test/test.hs @@ -1,8 +1,13 @@ {- -Run hledger's (and hledger-lib's) unit tests as a cabal test suite, -by running the test command with no options. +Run the hledger package's unit tests using the tasty test runner +(by running the test command limited to Hledger.Cli tests). -} -import Hledger.Cli +-- cabal missing-home-modules workaround from hledger-lib, seems not needed here +-- {-# LANGUAGE PackageImports #-} +-- import "hledger" Hledger.Cli (tests_Hledger_Cli) +import Hledger.Cli (tests_Hledger_Cli) -main = testcmd defcliopts (error "journal-less command tried to use the journal") +import Test.Tasty (defaultMain) + +main = defaultMain tests_Hledger_Cli