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.
--
-- 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

View File

@ -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