dev: consolidate/expand include tests

This commit is contained in:
Simon Michael 2025-07-14 09:56:14 -07:00
parent 28f60bcf92
commit 42b9c8b0fb
23 changed files with 114 additions and 106 deletions

View File

@ -41,7 +41,7 @@ $ hledger print -f personal.journal -f business.journal -f alias.journal -f pers
# ** 3. files can be of different formats
$ hledger print -f personal.journal -f ../journal/a.timeclock -f ../journal/b.timedot
$ hledger print -f personal.journal -f a.timeclock -f b.timedot
2014-01-02
expenses:food $1
assets:cash

View File

@ -1,105 +0,0 @@
# * include directive
# ** 1. nested includes in subdirectories
$ mkdir -p b/c/d ; printf '2010/1/1\n (D) 1\n' >b/c/d/d.journal ; printf '2010/1/1\n (C) 1\ninclude d/d.journal\n' >b/c/c.journal ; printf '2010/1/1\n (B) 1\ninclude c/c.journal\n' >b/b.journal ; printf '2010/1/1\n (A) 1\ninclude b/b.journal\n' >a.journal ; hledger -f a.journal print; rm -rf a.journal bG
2010-01-01
(A) 1
2010-01-01
(B) 1
2010-01-01
(C) 1
2010-01-01
(D) 1
>= 0
# ** 2. Including other formats.
<
2016/1/1
(x) 1
include a.timeclock
include b.timedot
$ hledger -f - print
2016-01-01
(x) 1
2016-01-01 * 12:00-16:00
(a:aa) 4.00h
2016-01-01 *
(b.bb) 1.00
>=
# ** 3. include glob patterns
<
include *b.journal
$ printf '2018/01/01\n (A) 1\n' >ab.journal; printf '2018/01/01\n (B) 1' >bb.journal; hledger -f - print; rm -f ab.journal bb.journal
2018-01-01
(A) 1
2018-01-01
(B) 1
>=
# ** 4. include invalid glob patterns
<
include [.journal
$ hledger -f - print
>2 //
>= 1
# ** 5. include nonexistent file
<
include doesnotexist.journal
$ hledger -f - print
>2 //
>= 1
# ** 6. trailing whitespace after the filename is ignored
<
include a.timeclock
$ hledger -f - check
# ** 7. a same-line or multi-line following comment is ignored
<
include a.timeclock ; comment
; comment
; comment
$ hledger -f - check
# ** 8. include relative to home
<
include ~/included.journal
$ printf '2018/01/01\n (A) 1\n' >included.journal; HOME="$PWD" hledger -f - print; rm -rf included.journal
2018-01-01
(A) 1
>= 0
# The next tests require hard coded file names, so are not concurrent-safe.
# They use different file names so a single concurrent shelltest invocation will be fine.
# ** 9. test that order of include files is maintained
$ printf 'include _b\n' >_a; touch _b; hledger -f _a stats -v | grep _ | sed -e 's%.*/%%'; rm -rf _a _b
_a
_b
# ** 10. and with --auto code path
$ printf 'include _d\n=\n' >_c; touch _d; hledger -f _c stats -v --auto | grep _ | sed -e 's%.*/%%'; rm -rf _c _d
_c
_d
# ** 11. include using old !include directive
<
!include f.journal
$ printf '2018/01/01\n (A) 1\n' >f.journal; hledger -f - print; rm -f f.journal
2018-01-01
(A) 1
>=

View File

@ -0,0 +1 @@
include cycle2/cycle2.j

View File

@ -0,0 +1 @@
include ../cycle.j

View File

View File

@ -0,0 +1,2 @@
2016-01-01
(a) 1

View File

@ -0,0 +1,2 @@
i 2016-01-01 12:00:00 a:aa
o 2016-01-01 16:00:00

View File

View File

@ -0,0 +1,3 @@
2016/1/1
b.bb ....

View File

View File

View File

View File

@ -0,0 +1 @@
include **

View File

@ -0,0 +1 @@
include **.j

View File

@ -0,0 +1 @@
include */**.j

View File

@ -0,0 +1 @@
include **/*.j

View File

@ -0,0 +1 @@
include */**/*.j

View File

@ -0,0 +1,98 @@
# * include directive
# ** 1. journal, timeclock, and timedot files can be included.
# Trailing whitespace or comments are ignored.
# The order of includes is respected.
include a.j
include b.timedot ; comment
include a.timeclock
; comment
$ hledger -f - print
2016-01-01
(a) 1
2016-01-01 *
(b.bb) 1.00
2016-01-01 * 12:00-16:00
(a:aa) 4.00h
>=
# ** 2. The old !include spelling still works.
<
!include f.journal
$ printf '2018/01/01\n (A) 1\n' >f.journal; hledger -f - print; rm -f f.journal
2018-01-01
(A) 1
>=
# ** 3. include with no argument: argument error
<
include
$ hledger -f- files
>2 /include needs a.*argument/
>=1
# ** 4. include a nonexistent file: no files matched error
<
include nosuchfile
$ hledger -f- files
>2 /No files were matched/
>=1
# # ** 5. include a directory: no files matched error
# <
# include b
# $ hledger -f- files
# >2 /No files were matched/
# >=1
# ** 6. Including the current file is harmless, it's ignored automatically.
$ hledger -f self.j files
> /self\.j$/
# # ** 7. Including a cycle is harmless, the cycle is pruned automatically.
# $ hledger -f .cycle/cycle.j files
# > /cyc/
# >=1
# ** 8. A leading tilde is expanded to $HOME.
<
include ~/included.journal
$ printf '2018/01/01\n (A) 1\n' >included.journal; HOME="$PWD" hledger -f - print; rm -rf included.journal
2018-01-01
(A) 1
>= 0
# # ** 9. Glob patterns. Include a malformed glob -> glob error
# <
# include ***
# $ hledger -f- files
# >2 /malformed/
# >=1
# ** 10. Include invalid glob patterns
<
include [.journal
$ hledger -f - print
>2 //
>= 1
# # ** 11. Include ** -> all files
# $ hledger -f glob1.j files
# # ** 12. Include **.EXT -> ?
# $ hledger -f glob2.j files
# # ** 13. Include */**.EXT -> ?
# $ hledger -f glob3.j files
# # ** 14. Include **/*.EXT -> all files in or below cwd with .EXT
# $ hledger -f glob4.j files
# # ** 15. Include */**/*.EXT -> all files below cwd with .EXT
# $ hledger -f glob5.j files

View File

@ -0,0 +1 @@
include self.j