hledger/hledger/test
Stephen Morgan 8eedbbbe87 imp: cost: Generate totally balanced conversion postings for amounts with costs.
Introduce --infer-equity option which will generate conversion postings.
--cost will override --infer-equity.

This means there will no longer be unbalanced transactions, but will be
offsetting conversion postings to balance things out. For example.

2000-01-01
  a   1 AAA @@ 2 BBB
  b  -2 BBB

When converting to cost, this is treated the same as before.
When used with --infer-equity, this is now treated as:

2000-01-01
  a                               1 AAA
  equity:conversion:AAA-BBB:AAA  -1 AAA
  equity:conversion:AAA-BBB:BBB   2 BBB
  b                              -2 BBB

There is a new account type, Conversion/V, which is a subtype of Equity/E.
The first account declared with this type, if any, is used as the base account
for inferred equity postings in conversion transactions, overriding the default
"equity:conversion".

API changes:

Costing has been changed to ConversionOp with three options:
NoConversionOp, ToCost, and InferEquity.
The first correspond to the previous NoCost and Cost options, while the
third corresponds to the --infer-equity flag.  This converts transactions with costs
(one or more transaction prices) to transactions with equity:conversion postings.
It is in ConversionOp because converting to cost with -B/--cost and inferring conversion
equity postings with --infer-equity are mutually exclusive.

Correspondingly, the cost_ record of ReportOpts has been changed to
conversionop_.

This also removes show_costs_ option in ReportOpts, as its functionality
has been replaced by the richer cost_ option.
2021-12-21 10:50:13 -10:00
..
addons cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
balance fix: bal: --declared now respects not:ACCT (fix #1783) 2021-12-09 12:58:22 -10:00
cli fix: extend application of commodity style to prices (except precision) and make --commodity-style a general flag 2021-09-20 08:55:55 -10:00
i18n lib,cli: Use Text Builder for Balance commands. 2021-01-02 15:08:09 +11:00
import cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
journal imp: cost: Generate totally balanced conversion postings for amounts with costs. 2021-12-21 10:50:13 -10:00
print imp: csv: Do not display thousands separators when outputting csv. 2021-12-06 15:17:46 -10:00
register imp: csv: Do not display thousands separators when outputting csv. 2021-12-06 15:17:46 -10:00
0unittests.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
account-aliases.test lib,cli: Use Text Builder for Balance commands. 2021-01-02 15:08:09 +11:00
accounts-sorting.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
accounts.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
add.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
amount-rendering.test lib: Remove unused optional width argument for StringFormat. 2021-01-02 15:08:09 +11:00
aregister.test areg: begin respecting --date2: show txns' date2 (#1731) 2021-10-10 10:34:45 -10:00
balancesheet.test imp: csv: Do not display thousands separators when outputting csv. 2021-12-06 15:17:46 -10:00
cashflow.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
check-accounts.test ;check: add tests for all on-demand checks 2020-12-31 10:27:50 -08:00
check-balancednoautoconversion.test lib,cli,ui,web: Add check balancednoautoconversion command, which checks that 2021-06-07 18:58:58 -10:00
check-commodities.test ;check: add tests for all on-demand checks 2020-12-31 10:27:50 -08:00
check-ordereddates.test check: ordereddates: test --date2, clarify --unique and QUERY dropped 2020-12-31 11:43:51 -08:00
check-payees.test ;check: add tests for all on-demand checks 2020-12-31 10:27:50 -08:00
check-uniqueleafnames.test check: uniqueleafnames: fancy error message like the others 2021-01-09 18:54:33 -08:00
close.test imp: close: clarify date logic, use journal last day if later (#1604) 2021-07-12 18:50:06 -10:00
codes.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
csv.test fix: csv: Handle multiple zero amounts in postings in csv files. (#1733) 2021-11-18 20:48:55 -10:00
csvtest.sh ;csv: csvtest.sh: add history note (#1434) 2021-01-15 13:19:24 -08:00
descriptions.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
forecast.test imp!: forecast: Implements more intuitive logic for the forecast interval. (#1648) 2021-08-26 20:32:30 -10:00
incomestatement.test imp: balcmds: support --declared on bs/cf/is also (#1765) 2021-11-25 11:55:58 -10:00
json.test lib!: lib: Remove aismultiplier from Amount. 2021-07-22 19:06:33 -10:00
notes.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
payees.test payees: add --used/--declared flags, like accounts 2021-01-17 16:37:38 -08:00
pivot.test fix!: register: Tighten up spacing around the date in register reports. (#1655) 2021-08-22 08:15:22 -10:00
prices.test fix: prices: Do not try to generate prices when there would be a zero 2021-11-18 20:59:52 -10:00
query-desc.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
query-tag.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
README.md cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
related.test imp: balance: Allow --related flag for balance reports. (#1469) 2021-11-08 14:03:50 -10:00
rewrite.test print: always show all decimal places (#931) 2021-02-04 08:13:55 -08:00
roi.test imp: cli: --infer-market-price renamed to --infer-market-prices 2021-09-18 12:12:31 -10:00
sample.journal cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
stats.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
tags.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
timeclock.test timeclock: print shows timeclock amounts with just 2 decimals, like pre-1.21 (#1527) 2021-04-12 18:40:33 -10:00
timedot.test csv, timedot, timeclock: respect --alias options (fix #859) 2020-11-24 09:17:01 -08:00
unittest.hs ;ci: use --pedantic for all; fix a warning with unit test suites 2020-03-07 14:43:50 -08:00

hledger test-related files. See also Contributor Guide: Tests.

unittest.hs - main file for a cabal test suite in the hledger package (run by “cabal test” or “stack test”). Runs the unit tests built in to all hledger modules. Not used much, we usually run them via hledgers builtin “test” command instead.

doctest.hs - main file for another cabal test suite. Runs the doctests embedded in haddock comments in some hledger modules.

The rest of the files here are functional tests, run with shelltestrunner. These test the hledger CLI and (indirectly) the hledger-lib package. They are organised roughly by component.

Older test files are in shelltestrunners 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
:hledger/test/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` hledger/test/cli/query-args.test
:hledger/test/cli/query-args.test:1: [OK]
:hledger/test/cli/query-args.test:2: [OK]
:hledger/test/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 hledger/test/cli/query-args.test | entr bash -c "COLUMNS=80 shelltest --execdir -w `stack exec -- which hledger` hledger/test/cli/query-args.test -i1"
:hledger/test/cli/query-args.test:1: [OK]

         Test Cases  Total      
 Passed  1           1          
 Failed  0           0          
 Total   1           1          
:hledger/test/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