dev: errors: test generation improvements

This commit is contained in:
Simon Michael 2022-07-15 09:05:21 +01:00
parent 90c41529ef
commit d0a7154b4a
2 changed files with 11 additions and 5 deletions

View File

@ -1,8 +1,10 @@
HLEDGER ?= hledger
ERRORSCRIPTS=*.j *.timeclock # *.timedot *.csv
# j, csv, timeclock, timedot files which are executable
ERRORSCRIPTS := $$(find . -perm +rwx \( -name '*.j' -or -name '*.csv' -or -name '*.timeclock' -or -name '*.timedot' -or -name '*.sh' \))
# Check error messages of hledger in $PATH against current error tests.
# Check error messages of $HLEDGER against current error tests.
# A few tests (csvstdinrules.sh) may use "hledger" in $PATH instead of $HLEDGER.
test:
@printf "Running error message tests with hledger $$($(HLEDGER) --version | awk '{print $$2}'):\n"
shelltest -w $(HLEDGER) *.test

View File

@ -21,14 +21,18 @@ TEST=$(echo "$SCRIPT" | sed -E 's/\.[^.]+$//').test
{
head -1 "$SCRIPT" | sed -E "s%#!/usr/bin/env -S (.*)%\$\$\$ \1 $SCRIPT%"
printf ">>>2 /"
"./$SCRIPT" 2>&1 | sed -E \
-e 's%(hledger: Error: ).*/\./(.*)%\1.*\2%' \
-e 's%/%\\/%g' \
./"$SCRIPT" 2>&1 | sed -E \
-e 's/\^/\\^/g' \
-e 's/\$/\\$/g' \
-e 's/\+/\\+/g' \
-e 's/\*/\\*/g' \
-e 's/\[/\\[/g' \
-e 's/\]/\\]/g' \
-e 's/\(/\\(/g' \
-e 's/\)/\\)/g' \
-e 's/\|/\\|/g' \
-e 's%(hledger: Error: ).*/\./(.*)%\1.*\2%' \
-e 's%/%\\/%g' \
| head -c 300
printf "/\n>>>= 1\n"
} >"$TEST"