Add a new account type Gain with single-letter code G as a subtype of Revenue, similar to how Cash is a subtype of Asset and Conversion is a subtype of Equity. This enables tracking capital gains/losses separately while still including them in income statements and close --retain. Usage: account revenues:capital ; type: G - type:G matches only Gain accounts - type:R matches both Revenue and Gain (subtype matching) - Auto-detection from account names matching: ^(income|revenue)s?:(capital[- ]?)?(gains?|loss(es)?)(:|$) e.g. income:gains, revenue:capital-gains, income:losses |
||
|---|---|---|
| .. | ||
| balance | ||
| cli | ||
| errors | ||
| i18n | ||
| import | ||
| journal | ||
| ledger-compat | ||
| register | ||
| _move.test | ||
| _perf.test | ||
| 0unittests.test | ||
| account-aliases.test | ||
| accounts-sorting.test | ||
| accounts.test | ||
| activity.test | ||
| add-2478.j | ||
| add.test | ||
| amount-rendering.test | ||
| aregister.test | ||
| balancesheet.test | ||
| cashflow.test | ||
| check-accounts.test | ||
| check-balanced.test | ||
| check-commodities.test | ||
| check-ordereddates.test | ||
| check-payees.test | ||
| check-tags.test | ||
| check-uniqueleafnames.test | ||
| close.test | ||
| codes.test | ||
| commands.test | ||
| commodities.test | ||
| csv-encoding.test | ||
| csv.test | ||
| csvtest.sh | ||
| descriptions.test | ||
| forecast.test | ||
| incomestatement.test | ||
| json.test | ||
| needs-old.timeclock | ||
| notes.test | ||
| payees.test | ||
| pivot.test | ||
| prices.test | ||
| query-desc.test | ||
| query-expr.test | ||
| query-tag.test | ||
| query-type.test | ||
| README.md | ||
| related.test | ||
| rewrite.test | ||
| roi.test | ||
| run_cmds.txt | ||
| run.args | ||
| run.test | ||
| sample2.journal | ||
| sample.journal | ||
| ssvtest.sh | ||
| stats.test | ||
| t.iso8859-1.csv | ||
| t.iso8859-1.csv.rules | ||
| tags.test | ||
| timeclock.test | ||
| timedot.test | ||
| unittest.hs | ||
hledger test-related files. See also Developer docs > 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 hledger’s 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.
shelltestrunner’s latest format
3 is preferred, though some tests may still be using the older format
1. Each command line (beginning with $) is a single
test, which usually reads input from a preceding <
section, and is followed by expected output, and any non-standard error
output (>2) or exit code (>=).
Additionally, each test is preceded by a descriptive comment
(#). This should begin with an Emacs outshine heading
marker (**), useful for folding and browsing tests in
Emacs, and a test number (1.), useful for running
individual tests.
A few tests invoke unix commands; these won’t run in a Windows CMD shell.
2024-09-30 Note: tests of error output must use regexps for now to work around ghc 9.10’s extra newline in error output: https://gitlab.haskell.org/ghc/ghc/-/issues/25116
Run them all (also builds hledger):
just functest
See the commands being run:
$ just -v functest
===> Running recipe `functest`...
$STACK build --ghc-options=-Werror hledger
time ((stack exec -- shelltest --execdir --exclude=/_ --threads=32 hledger/test/ bin/ -x ledger-compat/ledger-baseline -x ledger-compat/ledger-regress -x ledger-compat/ledger-extra && echo $@ PASSED) || (echo $@ FAILED; false))
Some explanation:
stack exec -- ...ensures you are testing the hledger executable that was just built (it will be first in PATH).--execdirexecutes tests within their test file’s directory.--exclude=/_excludes top-level test files whose names begin with underscore.--threads=Nruns tests in parallel which is much faster.-xis another spelling of –exclude
Run only the tests matching a regular expression (here, the 19th test in the assertions.test file):
$ just functest -i balance-assertions.*19
:hledger/test/journal/assertions.test:19: [OK]
Test Cases Total
Passed 1 1
Failed 0 0
Total 1 1
Run a specific test repeatedly as its file is changed:
$ watchexec -w hledger/test/journal/assertions.test just functest -i balance-assertions.*19
: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