aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimon Reinold <tirei+aerc@agon.one>2024-07-19 20:20:21 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-04 17:48:46 +0200
commiteeacf0ca2feb4c5b631e9e40f5955500fddeb73c (patch)
treeffb757a4a4ae47b9405b4dea6691a1f6ec220200
parenta794349a40f13da676928e5793e823bbb6912234 (diff)
downloadaerc-eeacf0ca2feb4c5b631e9e40f5955500fddeb73c.tar.gz
filters: test calendar filter also with POSIX-Awk
The builtin "calendar" filter is written in the Awk language, for which multiple interpreters exist. The most common is probably GNU Awk (aka "gawk"), which also implements some features that other interpreters do not support. That means that the calendar filter could run fine in gawk, but fail in another interpreter (compare e.g. commit a604acceac0f "calendar: fix error with non-gnu awk"). Using the "-W posix" option, gawk can be put into a POSIX-compatibility mode, which attempts to stay as close as possible to the POSIX-specified version of Awk, which should then hopefully also be supported by other Awk interpreters. Running the filter's tests using "gawk -W posix" should help identify potential incompatibilities with other interpreters. Other interpreters also support "-W posix" (e.g. mawk, or ignore it like busybox awk). Using "awk -W posix" allows these to be used as well. If "-W posix" causes the interpreter to fail, skip this test. This new test in POSIX-compatibility mode runs in addition the existing test, which directly executes the filter, using the Awk interpreter's default mode ("-W posix" cannot just be added to the filter's shebang line, as only a single argument may be supported, and "-f" is also needed). The later is the mode most users will actually be using, so I don't want to remove that test. I'm not doing this for the other Awk-filters (hldiff and plaintext), as they have ben obsoleted by the colorize filter. Besides, they don't have any test vectors. Signed-off-by: Timon Reinold <tirei+aerc@agon.one> Acked-by: Robin Jarry <robin@jarry.cc>
-rwxr-xr-xfilters/test.sh38
1 files changed, 31 insertions, 7 deletions
diff --git a/filters/test.sh b/filters/test.sh
index dc5ac265..cd4aeb88 100755
--- a/filters/test.sh
+++ b/filters/test.sh
@@ -33,13 +33,12 @@ EOF
export AERC_STYLESET=$style
export AERC_OSC8_URLS=1
-for vec in $here/vectors/*.in; do
- expected=${vec%%.in}.expected
- tool=$(basename $vec | sed 's/-.*//')
- tool_bin=$here/../$tool
- prefix="$FILTERS_TEST_PREFIX $FILTERS_TEST_BIN_PREFIX"
- # execute source directly (and omit $...BIN_PREFIX) for interpreted filters
- [ -f $tool_bin ] || { tool_bin=$here/$tool; prefix="$FILTERS_TEST_PREFIX"; }
+do_test() {
+ prefix="$1"
+ tool_bin="$2"
+ tool="$3"
+ vec="$4"
+ expected="$5"
tmp=$(mktemp)
status=0
$prefix $tool_bin < $vec > $tmp || status=$?
@@ -50,6 +49,31 @@ for vec in $here/vectors/*.in; do
fail=1
fi
rm -f -- "$tmp"
+}
+
+for vec in $here/vectors/*.in; do
+ expected=${vec%%.in}.expected
+ tool=$(basename $vec | sed 's/-.*//')
+ tool_bin=$here/../$tool
+ prefix="$FILTERS_TEST_PREFIX $FILTERS_TEST_BIN_PREFIX"
+ # execute source directly (and omit $...BIN_PREFIX) for interpreted filters
+ if ! [ -f "$tool_bin" ]; then
+ tool_bin=$here/$tool
+ prefix="$FILTERS_TEST_PREFIX"
+ fi
+ do_test "$prefix" "$tool_bin" "$tool" "$vec" "$expected"
+
+ case $tool in # additional test runs
+ calendar) # Awk
+ if awk -W posix -- '' >/dev/null 2>&1; then
+ # test POSIX-compatibility
+ do_test "$prefix" "awk -W posix -f $tool_bin" \
+ "$tool (posix)" "$vec" "$expected"
+ else # "-W posix" is not supported and not ignored, skip test
+ echo "? $tool < $vec > $tmp [no '-W posix' support]"
+ fi
+ ;;
+ esac
done
exit $fail