tweak journal file auto-creation, add tests

This commit is contained in:
Simon Michael 2010-07-17 00:45:12 +00:00
parent aaf14ffda1
commit 2f6b82122f
2 changed files with 13 additions and 3 deletions

View File

@ -96,15 +96,15 @@ ensureJournalFile :: FilePath -> IO ()
ensureJournalFile f = do
exists <- doesFileExist f
when (not exists) $ do
printf "No journal file at %s, creating...\n" f
printf "Edit this file or use hledger add or hledger web to add transactions.\n"
hPrintf stderr "No journal file \"%s\", creating it.\n" f
hPrintf stderr "Edit this file or use \"hledger add\" or \"hledger web\" to add transactions.\n"
emptyJournal >>= writeFile f
-- | Give the content for a new auto-created journal file.
emptyJournal :: IO String
emptyJournal = do
d <- getCurrentDay
return $ printf "; journal created by hledger on %s\n; see http://hledger.org/MANUAL.html#file-format\n\n" (show d)
return $ printf "; journal created %s; see http://hledger.org/MANUAL.html#journal-file\n\n" (show d)
-- | Read a Journal from this string, using the specified data format or
-- trying all known formats, or give an error string.

10
tests/no-such-file.test Normal file
View File

@ -0,0 +1,10 @@
# commands should generally autocreate an empty journal when missing, see also add*.test
# $$ used for safe concurrent test running, may be a bash-ism
#
rm -f $$; bin/hledger register -f $$; rm -f $$
>>>
>>>2 /No journal file.*creating it/
#
rm -f $$; bin/hledger balance --no-total -f $$; rm -f $$
>>>
>>>2 /No journal file.*creating it/