Files
httrack/tests/01_engine-cache.test
Xavier Roche 13207a92fc Make the cache and manpage tests POSIX-shell portable
Running the suite on macOS surfaced two GNU/Linux assumptions. The test
harness there resolves $(BASH) to /bin/sh (POSIX mode), and macOS ships
BSD userland, so:

- 01_engine-cache used "du -sb"; the -b (apparent bytes) flag is GNU-only
  and BSD/macOS du rejects it, leaving an empty size and an "integer
  expression expected" error. Switch to portable "du -sk" (1024-byte
  units); block-allocated size is an upper bound, fine for a ceiling.

- 02_manpage-regen used diff with process substitution, which a POSIX
  /bin/sh does not parse. Stage the stripped inputs in temp files instead.

Both now pass under dash as well as bash, on Linux and macOS.

Signed-off-by: Xavier Roche <roche@httrack.com>
2026-06-14 22:05:31 +02:00

53 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
#
# Keep this POSIX-portable: the harness runs it via $(BASH), which is a plain
# POSIX /bin/sh on some platforms (e.g. macOS), so avoid bashisms and GNU-only
# tool flags despite the #!/bin/bash above.
# Cache create/read/update logic (driven by 'httrack -#A <dir>').
#
# The in-process self-test stores several hand-crafted edge entries (normal
# HTML, an empty redirect with a near-limit location, a non-HTML body kept via
# all-in-cache, a binary body with embedded NUL/high bytes), a few thousand
# small entries (index/lookup scale), and a few large compressible and
# incompressible bodies (zlib deflate/inflate). It reads everything back
# asserting every header field and the body round-trip byte for byte, then
# updates one entry and confirms the new value is read back. It exits non-zero
# on the first mismatch.
set -eu
dir=$(mktemp -d)
trap 'rm -rf "$dir"' EXIT
# Like the other -# debug modes, a trailing token (the working directory) is
# required; a bare '-#A' falls through to the usage screen.
out=$(httrack -#A "$dir")
# Match the exact success line, so the test cannot pass for an unrelated reason
# (e.g. the -#A mode being gone and falling through to the usage screen, which
# also exits non-zero but never prints this).
test "$out" = "cache-selftest: OK" || {
echo "expected 'cache-selftest: OK', got: $out" >&2
exit 1
}
# The self-test must have actually produced a ZIP cache on disk.
test -e "$dir/hts-cache/new.zip" || {
echo "no ZIP cache was written by the self-test" >&2
exit 1
}
# Sanity-check the cache footprint: the few-thousand-entry pass is expected to
# weigh ~1-2 MB. Fail if it balloons well past that (e.g. a per-entry overhead
# regression or runaway growth), so the cache size stays bounded.
# du -sk (1024-byte units) is portable; GNU's -b (apparent bytes) is rejected
# by BSD/macOS du. Block-allocated size is an upper bound on apparent size,
# which is all a ceiling check needs.
ceiling=$((4 * 1024)) # KiB
kbytes=$(du -sk "$dir/hts-cache" | cut -f1)
test "$kbytes" -le "$ceiling" || {
echo "cache footprint ${kbytes} KiB exceeds ${ceiling} KiB ceiling" >&2
exit 1
}