cli: generate/update tests and readme from error test journals
This commit is contained in:
		
							parent
							
								
									1130ad1abd
								
							
						
					
					
						commit
						1ff0f76524
					
				
							
								
								
									
										33
									
								
								hledger/test/errors/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								hledger/test/errors/Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| # Check error messages of hledger in $PATH against current error tests.
 | ||||
| test: | ||||
| 	@printf "Running error message tests with hledger $$(hledger --version | awk '{print $$2}'):\n" | ||||
| 	shelltest *.test | ||||
| 
 | ||||
| TESTJOURNALS=*.j | ||||
| 
 | ||||
| # Update error message tests and readme based on the latest test journals
 | ||||
| # and error output of hledger in $PATH.
 | ||||
| update: tests readme | ||||
| 
 | ||||
| tests: | ||||
| 	@printf "Updating *.test with the error messages of hledger $$(hledger --version | awk '{print $$2}')\n" | ||||
| 	@read -p "ok ? Press enter: " | ||||
| 	for f in $(TESTJOURNALS); do make -s $$(basename $$f .j).test; done | ||||
| 	make -s test | ||||
| 
 | ||||
| %.test: %.j | ||||
| 	head -1 $< | sed -E 's%#!/usr/bin/env -S (.*)%$$$$$$ \1 $<%' >$@ | ||||
| 	echo ">>>2" >>$@ | ||||
| 	shelltest $@ | awk '/Got stderr/{f=1;next}/Expected exit code/{f=0}f' >>$@ | ||||
| 	echo ">>>=1" >>$@ | ||||
| 
 | ||||
| readme: $(TESTJOURNALS) | ||||
| 	@printf "Updating README.md with the error messages of hledger $$(hledger --version | awk '{print $$2}')\n" | ||||
| 	@read -p "ok ? Press enter: " | ||||
| 	sed '/<!-- GENERATED: -->/q' <README.md >README.md.tmp | ||||
| 	echo "$$(hledger --version | cut -d, -f1) error messages:" >>README.md.tmp | ||||
| 	for f in $(TESTJOURNALS); do \
 | ||||
| 		printf '\n### %s\n```\n%s\n```\n\n' "$$(basename "$$f" .j)" "$$(./"$$f" 2>&1)"; \
 | ||||
| 	done >>README.md.tmp | ||||
| 	mv README.md.tmp README.md | ||||
| 
 | ||||
| @ -99,60 +99,18 @@ Notes (see also [#1436][]): | ||||
| ## Current journal errors | ||||
| 
 | ||||
| <!-- to update: erase the below then C-u M-! ./showall --> | ||||
| hledger 1.25.99-gb8d78661e-20220422 error messages, last updated 2022-04-22: | ||||
| <!-- GENERATED: --> | ||||
| hledger 1.25.99-gc5e159574-20220422 error messages: | ||||
| 
 | ||||
| ### parseable | ||||
| ### accounts | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/parseable.j:3:2: | ||||
|   | | ||||
| 3 | 1 | ||||
|   |  ^ | ||||
| unexpected newline | ||||
| expecting date separator or digit | ||||
| 
 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./accounts.j:4:6: | ||||
|   | 2022-01-01 | ||||
| 4 |     (a)               1 | ||||
|   |      ^ | ||||
| undeclared account "a" | ||||
| ``` | ||||
| 
 | ||||
| ### parseable-dates | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/parseable-dates.j:3:1: | ||||
|   | | ||||
| 3 | 2022/1/32 | ||||
|   | ^^^^^^^^^ | ||||
| well-formed but invalid date: 2022/1/32 | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| ### parseable-regexps | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./parseable-regexps.j:3:8: | ||||
|   | | ||||
| 3 | alias /(/ = a | ||||
|   |        ^ | ||||
| this regular expression could not be compiled: ( | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| ### balanced | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./balanced.j:3-4 | ||||
| could not balance this transaction: | ||||
| real postings' sum should be 0 but is: 1 | ||||
| 2022-01-01 | ||||
|     a               1 | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| ### balancednoautoconversion | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./balancednoautoconversion.j:6-8 | ||||
| could not balance this transaction: | ||||
| real postings' sum should be 0 but is:  1 A | ||||
| -1 B | ||||
| 2022-01-01 | ||||
|     a             1 A | ||||
|     b            -1 B | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| ### assertions | ||||
| ``` | ||||
| @ -168,38 +126,40 @@ commodity: | ||||
| calculated: 0 | ||||
| asserted:   1 | ||||
| difference: 1 | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| ### accounts | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/accounts.j:4:6: | ||||
|   | 2022-01-01 | ||||
| 4 |     (a)               1 | ||||
|   |      ^ | ||||
| undeclared account "a" | ||||
| 
 | ||||
| ### balanced | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./balanced.j:3-4 | ||||
| could not balance this transaction: | ||||
| real postings' sum should be 0 but is: 1 | ||||
| 2022-01-01 | ||||
|     a               1 | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ### balancednoautoconversion | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./balancednoautoconversion.j:6-8 | ||||
| could not balance this transaction: | ||||
| real postings' sum should be 0 but is:  1 A | ||||
| -1 B | ||||
| 2022-01-01 | ||||
|     a             1 A | ||||
|     b            -1 B | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ### commodities | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/commodities.j:6: | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./commodities.j:6: | ||||
|   | 2022-01-01 | ||||
| 6 |     (a)             A 1 | ||||
|   |                     ^ | ||||
|   |                     ^^^ | ||||
| undeclared commodity "A" | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| ### payees | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/payees.j:6:12: | ||||
| 6 | 2022-01-01 p | ||||
|   |            ^ | ||||
|   |     (a)             A 1 | ||||
| undeclared payee "p" | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| ### ordereddates | ||||
| ``` | ||||
| @ -212,9 +172,50 @@ at /Users/simon/src/hledger/hledger/test/errors/./ordereddates.j:10-11: | ||||
| > 2022-01-01 p | ||||
|       (a)               1 | ||||
|    | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ### parseable-dates | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./parseable-dates.j:3:1: | ||||
|   | | ||||
| 3 | 2022/1/32 | ||||
|   | ^^^^^^^^^ | ||||
| well-formed but invalid date: 2022/1/32 | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ### parseable-regexps | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./parseable-regexps.j:3:8: | ||||
|   | | ||||
| 3 | alias /(/ = a | ||||
|   |        ^ | ||||
| this regular expression could not be compiled: ( | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ### parseable | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./parseable.j:3:2: | ||||
|   | | ||||
| 3 | 1 | ||||
|   |  ^ | ||||
| unexpected newline | ||||
| expecting date separator or digit | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ### payees | ||||
| ``` | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./payees.j:6:12: | ||||
| 6 | 2022-01-01 p | ||||
|   |            ^ | ||||
|   |     (a)             A 1 | ||||
| undeclared payee "p" | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ### uniqueleafnames | ||||
| ``` | ||||
| hledger: Error: account leaf names are not unique | ||||
| @ -223,5 +224,5 @@ seen in "a:c" in transaction at: /Users/simon/src/hledger/hledger/test/errors/./ | ||||
| 
 | ||||
| > 2022-01-01 p | ||||
| >     (a:c)               1 | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										9
									
								
								hledger/test/errors/accounts.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								hledger/test/errors/accounts.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| $$$ hledger check accounts -f accounts.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/accounts.j:4:6: | ||||
|   | 2022-01-01 | ||||
| 4 |     (a)               1 | ||||
|   |      ^ | ||||
| undeclared account "a" | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										16
									
								
								hledger/test/errors/assertions.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								hledger/test/errors/assertions.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| $$$ hledger check -f assertions.j | ||||
| >>>2 | ||||
| hledger: Error: balance assertion: /Users/simon/src/hledger/hledger/test/errors/assertions.j:4:8 | ||||
| transaction: | ||||
| 2022-01-01 | ||||
|     a               0 = 1 | ||||
| 
 | ||||
| assertion details: | ||||
| date:       2022-01-01 | ||||
| account:    a | ||||
| commodity:   | ||||
| calculated: 0 | ||||
| asserted:   1 | ||||
| difference: 1 | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										9
									
								
								hledger/test/errors/balanced.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								hledger/test/errors/balanced.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| $$$ hledger check -f balanced.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/balanced.j:3-4 | ||||
| could not balance this transaction: | ||||
| real postings' sum should be 0 but is: 1 | ||||
| 2022-01-01 | ||||
|     a               1 | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										11
									
								
								hledger/test/errors/balancednoautoconversion.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								hledger/test/errors/balancednoautoconversion.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| $$$ hledger check balancednoautoconversion -f balancednoautoconversion.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/balancednoautoconversion.j:6-8 | ||||
| could not balance this transaction: | ||||
| real postings' sum should be 0 but is:  1 A | ||||
| -1 B | ||||
| 2022-01-01 | ||||
|     a             1 A | ||||
|     b            -1 B | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										9
									
								
								hledger/test/errors/commodities.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								hledger/test/errors/commodities.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| $$$ hledger check commodities -f commodities.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/commodities.j:6: | ||||
|   | 2022-01-01 | ||||
| 6 |     (a)             A 1 | ||||
|   |                     ^^^ | ||||
| undeclared commodity "A" | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										13
									
								
								hledger/test/errors/ordereddates.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								hledger/test/errors/ordereddates.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| $$$ hledger check ordereddates -f ordereddates.j | ||||
| >>>2 | ||||
| hledger: Error: transaction date is out of order | ||||
| at /Users/simon/src/hledger/hledger/test/errors/ordereddates.j:10-11: | ||||
| 
 | ||||
|   2022-01-02 p | ||||
|       (a)               1 | ||||
|    | ||||
| > 2022-01-01 p | ||||
|       (a)               1 | ||||
|    | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										9
									
								
								hledger/test/errors/parseable-dates.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								hledger/test/errors/parseable-dates.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| $$$ hledger check -f parseable-dates.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/parseable-dates.j:3:1: | ||||
|   | | ||||
| 3 | 2022/1/32 | ||||
|   | ^^^^^^^^^ | ||||
| well-formed but invalid date: 2022/1/32 | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										9
									
								
								hledger/test/errors/parseable-regexps.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								hledger/test/errors/parseable-regexps.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| $$$ hledger check -f parseable-regexps.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/parseable-regexps.j:3:8: | ||||
|   | | ||||
| 3 | alias /(/ = a | ||||
|   |        ^ | ||||
| this regular expression could not be compiled: ( | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										10
									
								
								hledger/test/errors/parseable.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								hledger/test/errors/parseable.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| $$$ hledger check -f parseable.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/parseable.j:3:2: | ||||
|   | | ||||
| 3 | 1 | ||||
|   |  ^ | ||||
| unexpected newline | ||||
| expecting date separator or digit | ||||
| 
 | ||||
| >>>=1 | ||||
							
								
								
									
										9
									
								
								hledger/test/errors/payees.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								hledger/test/errors/payees.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| $$$ hledger check payees -f payees.j | ||||
| >>>2 | ||||
| hledger: Error: /Users/simon/src/hledger/hledger/test/errors/payees.j:6:12: | ||||
| 6 | 2022-01-01 p | ||||
|   |            ^ | ||||
|   |     (a)             A 1 | ||||
| undeclared payee "p" | ||||
| 
 | ||||
| >>>=1 | ||||
| @ -1,28 +0,0 @@ | ||||
| #!/usr/bin/env sh | ||||
| # Execute all test journals, showing their error messages | ||||
| # (as README-ready markdown). | ||||
| 
 | ||||
| # All test journals in this directory, in preferred test/display order | ||||
| testfiles="\ | ||||
|   parseable.j \ | ||||
|   parseable-dates.j \ | ||||
|   parseable-regexps.j \ | ||||
|   balanced.j \ | ||||
|   balancednoautoconversion.j \ | ||||
|   assertions.j \ | ||||
|   accounts.j \ | ||||
|   commodities.j \ | ||||
|   payees.j \ | ||||
|   ordereddates.j \ | ||||
|   uniqueleafnames.j \ | ||||
|   " | ||||
| 
 | ||||
| printf '%s error messages, last updated %s:\n\n' \ | ||||
|        "$(hledger --version | cut -d, -f1)" \ | ||||
|        "$(date +%Y-%m-%d)" | ||||
| 
 | ||||
| for f in $testfiles; do | ||||
|     printf '### %s\n```\n' "$(echo "$f" | cut -d. -f1)" | ||||
|     ./"$f" || true | ||||
|     printf '```\n\n' | ||||
| done | ||||
							
								
								
									
										10
									
								
								hledger/test/errors/uniqueleafnames.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								hledger/test/errors/uniqueleafnames.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| $$$ hledger check uniqueleafnames -f uniqueleafnames.j | ||||
| >>>2 | ||||
| hledger: Error: account leaf names are not unique | ||||
| leaf name "c" appears in account names: "a:c", "b:c" | ||||
| seen in "a:c" in transaction at: /Users/simon/src/hledger/hledger/test/errors/uniqueleafnames.j:8-9 | ||||
| 
 | ||||
| > 2022-01-01 p | ||||
| >     (a:c)               1 | ||||
| 
 | ||||
| >>>=1 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user