I debugged this and it seems this is indeed a bug (which crops up when
total is used in a value expression that's evaluated before all
transactions have been parsed): when I change account_t::add_post in
account.cc to null out xdata_->family_details.total, things seem to
behave more or less how I expected.

I think there's no way to print the value of a value expression, so I
added a directive for that.  I named it 'debug', but probably it should
be called 'print'?

I'll post my patches when bugzilla is back (but they need cleaning up,
adding docs etc).

On Thu, 19 Oct 2017, at 23:43, John Lee wrote:
> An example that currently has me puzzled: the first assert below passes,
> and the second fails.  I'm interested both in learning why in this
> particular case, and more important, learning how to use ledger to debug
> problems like this in general.
> 
> 2017-10-01 * Opening Balance
>     Assets:CurrentAccount   $1000
>     Equity:OpeningBalance
> 
> 2017-10-02 * Savings
>     Assets:CurrentAccount:Savings   $100
>     Assets:CurrentAccount
> 
> assert account("Assets:CurrentAccount").total == $1000
> 
> 2017-10-03 * Savings
>     Assets:CurrentAccount:Savings   $100
>     Assets:CurrentAccount
> 
> assert account("Assets:CurrentAccount").total == $1000
> 
> 
> This surprises me because if I comment that last assert out and run
> ledger b '^Assets:CurrentAccount$' I get $800, and ledger b
> '^Assets:CurrentAccount:Savings$' prints $200 -- which adds to $1000,
> and indeed ledger b '^Assets:CurrentAccount' prints $1000.  Bug??  How
> can I see what ledger *thinks* the total is when it evaluates the
> assert?
> 
> 
> On Thu, 19 Oct 2017, at 23:13, John Lee wrote:
> > Sometimes the assert expressions I'm adding to my ledger file fail and I
> > don't immediately know why.  If I have something like this:
> > 
> > assert account("Assets:CurrentAccount").total == $123.45
> > 
> > and I'm wrong about the total, then I'll just be told that I'm wrong,
> > and not what the correct value is.  What's the easiest way to get ledger
> > to compute and print the correct value?
> > 
> > Maybe there's a way to print out account values at a given point in a
> > ledger file?  In particular, maybe there's a way to print the values of
> > value expressions as the ledger file is evaluated by a command like
> > balance?
> > 
> > I realize it's good to be able to see what the answer is before one
> > writes it down, but sometimes it just saves time to have the computer
> > work it out so you can see quickly what you did wrong.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to