hledger/tests
Simon Michael c23fc8b671 speed up -V/--value by converting reports, not the journal (#999)
Instead of converting all journal amounts to value early on, we now
convert just the report amounts to value, before rendering.

This was basically how it originally worked (for the balance command),
but now it's built in to the four basic reports used by print,
register, balance and their variants - Entries, Postings, Balance,
MultiBalance - each of which now has its own xxValue helper.

This should mostly fix -V's performance when there are many
transactions and prices (the price lookups could still be optimised),
and allow more flexibility for report-specific value calculations.

+------------------------------------------++-----------------+-------------------+--------------------------+
|                                          || hledger.999.pre | hledger.999.1sort | hledger.999.after-report |
+==========================================++=================+===================+==========================+
| -f examples/1000x1000x10.journal bal -V  ||            1.08 |              0.96 |                     0.76 |
| -f examples/2000x1000x10.journal bal -V  ||            1.65 |              1.05 |                     0.73 |
| -f examples/3000x1000x10.journal bal -V  ||            2.43 |              1.58 |                     0.84 |
| -f examples/4000x1000x10.journal bal -V  ||            4.39 |              1.96 |                     0.93 |
| -f examples/5000x1000x10.journal bal -V  ||            7.75 |              2.99 |                     1.07 |
| -f examples/6000x1000x10.journal bal -V  ||           11.21 |              3.72 |                     1.16 |
| -f examples/7000x1000x10.journal bal -V  ||           16.91 |              4.72 |                     1.19 |
| -f examples/8000x1000x10.journal bal -V  ||           27.10 |              9.83 |                     1.40 |
| -f examples/9000x1000x10.journal bal -V  ||           39.73 |             15.00 |                     1.51 |
| -f examples/10000x1000x10.journal bal -V ||           50.72 |             25.61 |                     2.15 |
+------------------------------------------++-----------------+-------------------+--------------------------+

There's one new limitation, not yet resolved: -V once again can pick a
valuation date in the future, if no report end date is specified and
the journal has future-dated transactions. We prefer to avoid that,
but reports currently are pure and don't have access to today's date.
2019-04-23 17:39:01 -07:00
..
0unittests lib: fix journalApplyValue test (#999) 2019-04-23 07:20:10 -07:00
accounts accounts: filtering by anything other than account name was broken 2018-10-10 20:32:19 -07:00
add tests: make functional tests use "hledger" again 2015-07-12 12:29:53 -07:00
addons update addons tests, note a todo 2017-03-29 08:21:30 -07:00
balance cli: added --transpose to "balance" command 2019-01-24 15:06:35 -08:00
balancesheet cli: compoundbalancecommand keeps zero-balance accounts with children 2018-10-17 16:59:53 -07:00
budget lib, cli: merge --show-unbudgeted into --empty 2019-01-25 12:53:09 -08:00
cashflow update functional tests for new monthly headings 2018-03-29 14:54:36 +01:00
cli fix functional test breakage 2019-01-28 20:25:59 -08:00
csv lib: csv parser support for 'balance2', 'balance' renamed to 'balance1' 2019-03-15 16:18:43 -07:00
i18n tests: update i18n test journals, i18n tests 2019-04-20 08:34:08 -07:00
incomestatement update functional tests for new monthly headings 2018-03-29 14:54:36 +01:00
journal speed up -V/--value by converting reports, not the journal (#999) 2019-04-23 17:39:01 -07:00
misc cli: if abs(return on investment)<0.01% display it as zero 2019-01-24 13:36:11 -08:00
print tests: move, consolidate auto posting tests (#893) 2019-02-01 15:31:36 -08:00
register reg: test and fix for --average, broken since 1.12 (#1003) 2019-04-06 11:00:38 -07:00
stats lib: simplify parsers; cleanups (#275) 2016-05-23 00:44:19 -07:00
timeclock lib: keep amounts aligned when rendering a transaction with posting flags 2017-06-04 21:26:18 -07:00
README.md doc: add a README for the functional tests, linked from contrib guide 2019-04-19 09:56:33 -07:00

hledgers functional tests. See also Contributor Guide: Tests.

These mainly test the hledger CLI and (indirectly) hledger-lib. They are organised roughly by component.

Running these requires shelltestrunner. Older test files are in format 1; newer ones use format 3 (preferred). Some tests invoke unix commands so will not run in a Windows CMD shell.

Run them all (also builds hledger):

make functest

See how the Makefile is invoking shelltestrunner:

$ make functest -n
stack build --fast hledger
(COLUMNS=80 stack exec -- shelltest --execdir -j16 --hide-successes --exclude=/_ -w `stack exec -- which hledger` tests \
        && echo functest PASSED) || (echo functest FAILED; false)

These are the most important:

  • COLUMNS=80 makes output independent of your terminal width.
  • --execdir runs each test within its own directory.
  • -w `stack exec -- which hledger` ensures you are testing the hledger executable that was just built.
  • -j16 runs tests in parallel which is much faster.

Run only the tests matching a regular expression:

$ COLUMNS=80 shelltest --execdir -w `stack exec -- which hledger` tests -i balance-assertions.*19
:tests/journal/balance-assertions.test:19: [OK]

         Test Cases  Total      
 Passed  1           1          
 Failed  0           0          
 Total   1           1          

Run only the tests in one file:

$ COLUMNS=80 shelltest --execdir -w `stack exec -- which hledger` tests/cli/query-args.test
:tests/cli/query-args.test:1: [OK]
:tests/cli/query-args.test:2: [OK]
:tests/cli/query-args.test:3: [OK]

         Test Cases  Total      
 Passed  3           3          
 Failed  0           0          
 Total   3           3          

Run a test repeatedly as its file is changed:

$ ls tests/cli/query-args.test | entr bash -c "COLUMNS=80 shelltest --execdir -w `stack exec -- which hledger` tests/cli/query-args.test -i1"
:tests/cli/query-args.test:1: [OK]

         Test Cases  Total      
 Passed  1           1          
 Failed  0           0          
 Total   1           1          
:tests/cli/query-args.test:1: [OK]

         Test Cases  Total      
 Passed  1           1          
 Failed  0           0          
 Total   1           1          
  C-c C-c

More shelltestrunner options:

$ shelltest --help