test: don't try to read the journal

This commit is contained in:
Simon Michael 2018-08-03 00:50:50 +01:00
parent 40d70ad10b
commit 3e0147b7e9
2 changed files with 16 additions and 9 deletions

View File

@ -230,8 +230,12 @@ testmode = (defCommandMode ["test"]) {
} }
-- | Run some or all hledger-lib and hledger unit tests, and exit with success or failure. -- | 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 :: CliOpts -> Journal -> IO ()
testcmd opts _ = do testcmd opts _donotuse = do
let ts = let ts =
(if tree_ $ reportopts_ opts then matchedTestsTree else matchedTestsFlat) (if tree_ $ reportopts_ opts then matchedTestsTree else matchedTestsFlat)
opts tests_Hledger_Cli_Commands opts tests_Hledger_Cli_Commands

View File

@ -169,14 +169,17 @@ main = do
| isBadCommand = badCommandError | isBadCommand = badCommandError
-- builtin commands -- builtin commands
| Just (cmdmode, cmdaction) <- findCommand cmd = do | Just (cmdmode, cmdaction) <- findCommand cmd =
if cmd=="add" -- add command does extra work before reading journal (case cmd of
then (do "test" -> -- should not read the journal
journalFilePathFromOpts opts >>= (ensureJournalFileExists . head) cmdaction opts (error "journal-less command tried to use the journal")
withJournalDo opts cmdaction) "add" -> -- should create the journal if missing
`orShowHelp` cmdmode (ensureJournalFileExists =<< (head <$> journalFilePathFromOpts opts)) >>
else withJournalDo opts cmdaction
withJournalDo opts cmdaction `orShowHelp` cmdmode _ -> -- all other commands: read the journal or fail if missing
withJournalDo opts cmdaction
)
`orShowHelp` cmdmode
-- addon commands -- addon commands
| isExternalCommand = do | isExternalCommand = do