hledger/hledger/test
Jonathan Dowland 8b14022d97 ;test:import: update matchgroup functest for #2158
Also re-format the comments. Some of the comments within the conditional
blocks were actually being parsed as case-insensitive regexes to match
against each record. Luckily this didn't impact the results.

Signed-off-by: Jonathan Dowland <jon@dow.land>
2024-02-29 21:44:38 +00:00
..
addons ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
balance fix:bal:budget: don't omit necessary parent accounts in tree mode (#2071) 2024-02-25 01:23:39 -10:00
cli dev: update failing test 2024-02-28 09:11:49 -10:00
errors imp: balance assertions error: clarify wording 2024-01-23 22:18:34 -10:00
i18n ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
import ;test:import: update matchgroup functest for #2158 2024-02-29 21:44:38 +00:00
journal feat:allow other kinds of unicode space as digit group separators 2024-02-28 09:12:17 -10:00
ledger-compat ;dev: tests: ledger-compat tests cleanup 2023-10-29 00:16:47 +01:00
print imp: more precision handling fixes, debug output, test updates (precisiongeddon) 2023-11-08 13:59:18 -08:00
register feat: cli: Add tsv output (#869) 2023-11-06 16:46:04 -08:00
_move.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01: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: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
activity.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
add.test fix:add: rethink adding default commodity symbol; fix doc instead (part 2) [#815] 2024-01-04 21:13:40 -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 ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
balancesheet.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
cashflow.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
check-accounts.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01: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 ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
check-ordereddates.test imp: errors: more error prettification 2022-07-13 03:59:44 +01:00
check-payees.test imp: errors: more error prettification 2022-07-13 03:59:44 +01:00
check-tags.test fix:check:tags: add date and date2 to the implicitly-declared special tags 2024-02-17 13:06:10 -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:close: support --round, like print 2024-02-25 17:37:59 -10:00
codes.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
csv.test imp: Support tsv and ssv prefixes (#2164) 2024-02-08 06:44:44 -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: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
incomestatement.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
json.test dev: rename AmountDisplayOpts -> AmountFormat, and related constants 2024-01-23 21:35:06 -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 ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
prices.test imp: more precision handling fixes, debug output, test updates (precisiongeddon) 2023-11-08 13:59:18 -08:00
query-bool.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01: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-tag.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
query-type.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
README.md ;doc:tests:readme 2023-11-01 06:53:25 +00:00
related.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
rewrite.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
roi.test imp: roi: limit large decimals to 8 digits by default (precisiongeddon) 2023-11-08 13:59:18 -08: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:journal: use a symlink's target's directory for relative include paths 2024-02-22 08:48:31 -10:00
tags.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
timeclock.test ;dev: tests: add outshine headings for more readability (in emacs) 2023-10-29 00:16:47 +01:00
timedot.test fix:timedot: accept numbers beginning with a decimal point again [#2130] 2023-12-08 15:08:35 -10: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 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.

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 (balance-assertions:.*19 in this case):)

$ make functest-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