Files
httrack/tests/76_cli-resize.test
Xavier Roche 3e4b131456 tests: share one port-discovery helper instead of 17 fragile copies (#869)
local-crawl.sh waits 30s for local-server.py's "PORT <n>" line and matches it
anywhere, because a cold Python start under a parallel make check lags past a
second and a warning merged via 2>&1 can precede the line. Seventeen tests that
launch the server directly carried an older copy of that loop: 5s, and only the
first line of the log. macos-15 exposed it, failing 15 of them where macos-14
passed on margin, but nothing about the bug is macOS-specific.

Move the proven idiom into testlib.sh next to stop_server and call it from all
seventeen, which also gets them the log dump on failure that local-crawl.sh has
and the inline copies did not -- the reason the CI failure said only "could not
discover server port" with no way to tell a slow start from a dead server.

Signed-off-by: Xavier Roche <roche@httrack.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 08:07:08 +00:00

56 lines
1.7 KiB
Bash

#!/bin/bash
# #97: a terminal resize must repaint the whole screen, and the frame must
# follow the new geometry instead of the hardcoded 80x24 one.
set -eu
: "${top_srcdir:=..}"
testdir=$(cd "$(dirname "$0")" && pwd)
# shellcheck source=tests/testlib.sh
. "${testdir}/testlib.sh"
server=$(nativepath "${testdir}/local-server.py")
root=$(nativepath "${testdir}/server-root")
driver=$(nativepath "${testdir}/pty-resize.py")
if is_windows; then
echo "no pty on Windows; skipping" >&2
exit 77
fi
python=$(find_python) || ! echo "python3 not found; skipping" >&2 || exit 77
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/httrack_resize.XXXXXX") || exit 1
serverpid=
cleanup() {
stop_server "$serverpid"
rm -rf "$tmpdir"
}
trap 'set +e; cleanup' EXIT
trap cleanup HUP INT QUIT PIPE TERM
serverlog="${tmpdir}/server.log"
: >"$serverlog"
"$python" "$server" --root "$root" >"$serverlog" 2>&1 &
serverpid=$!
port=$(discover_server_port "$serverlog" "$serverpid") || exit 1
which httrack >/dev/null || {
echo "could not find httrack"
exit 1
}
# Trickled pages under a long path: the display keeps animating while the pty is
# resized under it, and the URL is truncated at 80 columns but not at 200.
deep="127.0.0.1:${port}/trickle/deep/a-long-directory-segment/another-long-segment"
out="${tmpdir}/crawl"
mkdir "$out"
rc=0
# The in-progress rows show host:port, not the scheme.
"$python" "$driver" "${tmpdir}/pty.raw" "${deep}/p" -- \
httrack "http://${deep}/index.html" \
-O "$out" -%v --robots=0 --disable-security-limits \
--timeout=30 --retries=1 -c4 --max-time 60 || rc=$?
test "$rc" -eq 0 || {
echo "pty capture tail:"
tail -c 600 "${tmpdir}/pty.raw" | cat -v
exit 1
}