Files
kenjreno 128ddcb4df v0.1.0: thread-safe pub/sub event bus
Verbatim port of Fastway-Server's TFWEventBus from fw_plugin_host.pas
per feedback_copy_dont_reinterpret.md.  Adjustments limited to:

  - Type renames (TFW* -> T*).
  - uses clause: drop fw_log; add log.types from fpc-log so the
    optional Logger property uses the canonical ecosystem-wide
    TLogProc shape, matching every other fpc-* library.
  - Per-handler exception logging now calls Logger with
    Level=llError, Category='events', and includes the source
    plugin (ASourcePlugin parameter) in the message text so the
    canonical signature stays meaningful.

Behaviours preserved verbatim: APluginName bulk-Unsubscribe key,
wildcard '*' subscriber, OnBroadcast external-listener tap,
snapshot-iterate-outside-lock pattern, per-handler exception
isolation, TCriticalSection.

docs/DEVELOPER_GUIDE.md added covering threading, payload
ownership, recursive Fire, OnBroadcast, logger plumbing, and
the relationship between fpc-events (ecosystem-wide pub/sub)
and per-library typed observer callbacks (bp.events / cm.events
pattern).

Tests: 44 assertions across 14 scenarios pass on x86_64-linux.
Pre-tag -vh audit on src/ev.bus.pas reports zero hints/warnings.
2026-05-05 18:13:10 -07:00

73 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# run_tests.sh -- compile and run every test in tests/, then
# compile every example in examples/. Each test program exits
# non-zero on any failure.
set -e
cd "$(dirname "$0")"
FPC=/opt/fpcup/fpc/bin/x86_64-linux/fpc
OUT=build
mkdir -p "$OUT"
bash build.sh > /dev/null
TESTS=$(find tests -maxdepth 1 -name 'test_*.pas' 2>/dev/null | sort)
PASS=0
FAIL=0
for f in $TESTS; do
name=$(basename "$f" .pas)
printf " %-32s " "$name"
if $FPC -O2 -Sh -B \
-Fusrc \
-Fu../fpc-log/src \
-FE"$OUT" \
-FU"$OUT" \
-o"$OUT/$name" \
"$f" > "$OUT/$name.compile.log" 2>&1; then
if "$OUT/$name" > "$OUT/$name.run.log" 2>&1; then
echo "PASS"
PASS=$((PASS+1))
else
echo "FAIL (runtime)"
sed 's/^/ /' < "$OUT/$name.run.log"
FAIL=$((FAIL+1))
fi
else
echo "FAIL (compile)"
cat "$OUT/$name.compile.log"
FAIL=$((FAIL+1))
fi
done
echo
echo "Tests: $PASS passed, $FAIL failed."
EX_PASS=0
EX_FAIL=0
echo
echo "Examples (compile-only):"
for f in examples/*.pas; do
[ -e "$f" ] || continue
name=$(basename "$f" .pas)
printf " %-32s " "$name"
if $FPC -O2 -Sh -B \
-Fusrc \
-Fu../fpc-log/src \
-FE"$OUT" \
-FU"$OUT" \
-o"$OUT/$name" \
"$f" > "$OUT/$name.compile.log" 2>&1; then
echo "OK"
EX_PASS=$((EX_PASS+1))
else
echo "FAIL (compile)"
cat "$OUT/$name.compile.log"
EX_FAIL=$((EX_FAIL+1))
fi
done
echo
echo "Examples: $EX_PASS built, $EX_FAIL failed."
[ $FAIL -eq 0 ] && [ $EX_FAIL -eq 0 ]