From 7f8a352c0c9ca9f2aeb379d15d65121b0f14e30f Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 8 Jul 2010 14:04:54 +0000 Subject: [PATCH] stats: don't break on an empty file --- Hledger/Cli/Commands/Stats.hs | 6 ++++-- tests/stats-empty-file.test | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 tests/stats-empty-file.test diff --git a/Hledger/Cli/Commands/Stats.hs b/Hledger/Cli/Commands/Stats.hs index 43d6b5a31..4db849037 100644 --- a/Hledger/Cli/Commands/Stats.hs +++ b/Hledger/Cli/Commands/Stats.hs @@ -72,7 +72,9 @@ showStats _ _ l today = tnum7 = length $ filter withinlast7 ts withinlast7 t = d >= addDays (-7) today && (d<=today) where d = tdate t txnrate7 = fromIntegral tnum7 / 7 :: Double - acctnum = length $ accounts l - acctdepth = maximum $ map (accountNameLevel.aname) $ accounts l + acctnum = length as + acctdepth | null as = 0 + | otherwise = maximum $ map (accountNameLevel.aname) as + as = accounts l cs = Map.elems $ commodities l diff --git a/tests/stats-empty-file.test b/tests/stats-empty-file.test new file mode 100644 index 000000000..ba06eb8a4 --- /dev/null +++ b/tests/stats-empty-file.test @@ -0,0 +1,3 @@ +bin/hledger -f- stats +<<< +>>> /Accounts.* 0 \(depth 0\)/