From 3e0147b7e9acdedc4f1ef224adc4d2a5c8b1a19c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 3 Aug 2018 00:50:50 +0100 Subject: [PATCH] test: don't try to read the journal --- hledger/Hledger/Cli/Commands.hs | 6 +++++- hledger/Hledger/Cli/Main.hs | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index d3d4a8b39..fabb7f670 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -230,8 +230,12 @@ testmode = (defCommandMode ["test"]) { } -- | Run some or all hledger-lib and hledger unit tests, and exit with success or failure. +-- +-- Unlike other hledger commands, this one does not operate on the user's Journal. +-- For ease of implementation the Journal parameter remains in the type signature, +-- but it will not be valid and should not be used. testcmd :: CliOpts -> Journal -> IO () -testcmd opts _ = do +testcmd opts _donotuse = do let ts = (if tree_ $ reportopts_ opts then matchedTestsTree else matchedTestsFlat) opts tests_Hledger_Cli_Commands diff --git a/hledger/Hledger/Cli/Main.hs b/hledger/Hledger/Cli/Main.hs index 37a9adb93..13a804d2d 100644 --- a/hledger/Hledger/Cli/Main.hs +++ b/hledger/Hledger/Cli/Main.hs @@ -169,14 +169,17 @@ main = do | isBadCommand = badCommandError -- builtin commands - | Just (cmdmode, cmdaction) <- findCommand cmd = do - if cmd=="add" -- add command does extra work before reading journal - then (do - journalFilePathFromOpts opts >>= (ensureJournalFileExists . head) - withJournalDo opts cmdaction) - `orShowHelp` cmdmode - else - withJournalDo opts cmdaction `orShowHelp` cmdmode + | Just (cmdmode, cmdaction) <- findCommand cmd = + (case cmd of + "test" -> -- should not read the journal + cmdaction opts (error "journal-less command tried to use the journal") + "add" -> -- should create the journal if missing + (ensureJournalFileExists =<< (head <$> journalFilePathFromOpts opts)) >> + withJournalDo opts cmdaction + _ -> -- all other commands: read the journal or fail if missing + withJournalDo opts cmdaction + ) + `orShowHelp` cmdmode -- addon commands | isExternalCommand = do