hledger/hledger/test
g. nicholas d'andrea e678e09704 feat: accounts: add Gain (G) account type as subtype of Revenue [#2522]
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
2026-01-08 19:18:13 -10:00
..
balance fix: balance: Don't display zero rows with --no-elide (#2454) 2025-09-15 15:40:32 -07:00
cli dev: consolidate/expand include tests 2025-07-14 17:12:24 -07:00
errors ;dev:test:errors: make csvnoinclude test more robust 2025-11-18 09:16:15 -10:00
i18n ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
import imp:import: show info output on stderr, not stdout 2025-08-14 14:23:53 +01:00
journal feat: accounts: add Gain (G) account type as subtype of Revenue [#2522] 2026-01-08 19:18:13 -10:00
ledger-compat ;dev: tests: ledger-compat tests cleanup 2023-10-29 00:16:47 +01:00
print imp:print: --invert now also negates balance assertion/assignment amounts [#2314] 2025-01-29 09:47:29 -10:00
register imp: fully support quarter syntax in smart dates and period expressions 2025-06-23 18:37:08 -07:00
_move.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
_perf.test dev:test: exclude perf tests from func tests more robustly 2025-12-01 12:12:42 -08:00
0unittests.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
account-aliases.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
accounts-sorting.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
accounts.test dev:accounts: fix test 2025-09-21 12:53:32 -07:00
activity.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
add-2478.j ;dev:add: add missing test file 2025-11-18 08:36:58 -10:00
add.test fix:add: check balance assertions more accurately; allow balance assignments [#2478] 2025-11-17 18:49:56 -10:00
amount-rendering.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
aregister.test imp!:aregister, journal: same-day txns respect order of -f options 2025-12-07 17:21:36 -10:00
balancesheet.test imp: bs,cf,is: show interval in report title 2024-07-17 08:26:43 +01:00
cashflow.test imp: bs,cf,is: show interval in report title 2024-07-17 08:26:43 +01:00
check-accounts.test imp: run checks in a well-defined order; and tweak that order 2024-04-26 18:59:45 -10:00
check-balanced.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
check-commodities.test imp: check: check ordereddates before balance assertions, when both are enabled 2024-05-02 21:11:04 -10:00
check-ordereddates.test imp: check: check ordereddates before balance assertions, when both are enabled 2024-05-02 21:11:04 -10:00
check-payees.test dev: number the payees tests 2025-06-14 17:36:28 -10:00
check-tags.test imp:print: clean up special tags; show them more often with --verbose-tags 2024-11-16 14:40:03 -10:00
check-uniqueleafnames.test imp: check: uniqueleafnames: use the standard error format (#1436) 2022-04-25 02:56:59 -10:00
close.test feat: accounts: add Gain (G) account type as subtype of Revenue [#2522] 2026-01-08 19:18:13 -10:00
codes.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
commands.test feat: commands, an explicit command to show the commands list; refactor 2025-03-05 11:10:42 -10:00
commodities.test imp: commodities/payees/tags: used/declared flags, like accounts 2025-06-15 07:32:40 -10:00
csv-encoding.test fix:csv: respect encoding rule when rules file is input file [#2465] 2025-09-26 00:34:01 -10:00
csv.test ;dev: tests: be more robust when testing a "hledger-VER" executable 2025-05-13 10:48:16 -10:00
csvtest.sh ;dev: csvtest.sh: note need for 1+ lines above RULES 2023-01-11 21:38:04 -10:00
descriptions.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
forecast.test ;dev: tests: be more robust when testing a "hledger-VER" executable 2025-05-13 10:48:16 -10:00
incomestatement.test fix: balance: Clip account names in generateMultiBalanceAccount, not before (#2434) 2025-08-28 05:26:42 +01:00
json.test dev: rename AmountDisplayOpts -> AmountFormat, and related constants 2024-01-23 21:35:06 -10:00
needs-old.timeclock fix:timeclock: --old-timeclock also affects included files [#2417] 2025-09-01 08:26:44 +01:00
notes.test cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
payees.test dev: number the payees tests 2025-06-14 17:36:28 -10:00
pivot.test lib: showAmountCost(B): drop leading whitespace 2025-01-15 16:28:43 -10:00
prices.test imp: more precision handling fixes, debug output, test updates (precisiongeddon) 2023-11-08 13:59:18 -08:00
query-desc.test dev: tests: convert remaining format 1 tests to format 3 (or 2) 2023-02-16 11:55:15 -10:00
query-expr.test imp: the all: query now requires at least one posting 2025-08-03 06:34:00 +01:00
query-tag.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
query-type.test feat: accounts: add Gain (G) account type as subtype of Revenue [#2522] 2026-01-08 19:18:13 -10:00
README.md ;dev: rename assertions.test 2025-04-27 08:30:18 -10:00
related.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
rewrite.test imp:print: clean up special tags; show them more often with --verbose-tags 2024-11-16 14:40:03 -10:00
roi.test ;roi: more input sanity checks (fixes #2505) 2025-12-27 09:43:53 -10:00
run_cmds.txt run: added run.test 2025-03-06 11:54:00 -10:00
run.args run: added run.test 2025-03-06 11:54:00 -10:00
run.test ;dev: tests: be more robust when testing a "hledger-VER" executable 2025-05-13 10:48:16 -10:00
sample2.journal ;dev: tests for boolean queries involving amt:/cur: [#2371] 2025-05-17 00:04:41 -10:00
sample.journal cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
ssvtest.sh imp: Support tsv and ssv prefixes (#2164) 2024-02-08 06:44:44 -10:00
stats.test imp:stats: be more private by default; update doc 2024-03-01 09:03:57 -10:00
t.iso8859-1.csv fix:csv: respect encoding rule when rules file is input file [#2465] 2025-09-26 00:34:01 -10:00
t.iso8859-1.csv.rules fix:csv: respect encoding rule when rules file is input file [#2465] 2025-09-26 00:34:01 -10:00
tags.test imp: commodities/payees/tags: used/declared flags, like accounts 2025-06-15 07:32:40 -10:00
timeclock.test fix:timeclock: process in parse order; fully support overlapping sessions [#2417] 2025-09-01 08:27:08 +01:00
timedot.test dev: comment parsing tests/refactoring, fix indented timedot comments 2024-06-25 18:37:54 +01:00
unittest.hs ;cln: unittest.hs: remove bothersome PackageImports (#2337) 2025-02-26 11:54:59 -10:00

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 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.

shelltestrunners 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 wont run in a Windows CMD shell.

2024-09-30 Note: tests of error output must use regexps for now to work around ghc 9.10s 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).
  • --execdir executes tests within their test files directory.
  • --exclude=/_ excludes top-level test files whose names begin with underscore.
  • --threads=N runs tests in parallel which is much faster.
  • -x is 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