[PATCH 06/17] test-ls: add interactive (isatty) test

0 views
Skip to first unread message

Rob Browning

unread,
Nov 8, 2025, 4:39:01 PM (6 days ago) Nov 8
to bup-...@googlegroups.com
When script is available (which appears likely, since it's a native
bsd command and in the essential bsdutils package for debian
derivatives) check that when run interactively, ls output isn't
truncated.

Taken from 0.33.x:

92ccb6a01a3bb20ffe4c2353bd84e74f6722cfd5
filter_output: don't truncate stdout or stderr when isatty

Even though that code is gone now, keep the test to guard against
regressions.

Thanks to Christian Wolf for reporting the problem (in 0.33.x), and
Greg Troxel for help making dev/with-tty more portable.

Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
dev/with-tty | 25 +++++++++++++++++++++++++
test/ext/test-ls | 15 +++++++++++++++
2 files changed, 40 insertions(+)
create mode 100755 dev/with-tty

diff --git a/dev/with-tty b/dev/with-tty
new file mode 100755
index 00000000..c65aa1d4
--- /dev/null
+++ b/dev/with-tty
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+set -ueo pipefail
+
+# Callers can test for support via "with-tty true".
+
+usage() { echo 'Usage: with-tty command [arg ...]'; }
+misuse() { usage 1>&2; exit 2; }
+
+if script -qec true /dev/null; then
+ # linux flavor
+ script -qec "$(printf ' %q' "$@")" /dev/null
+elif script -q /dev/null true; then
+ # bsd flavor
+ script -q /dev/null "$@"
+else
+ rc=0
+ cmd="$(command -v script)" || rc=$?
+ if test "$rc" -eq 0; then
+ printf 'Unsupported script command: %q\n' "$cmd" 1>&2
+ else
+ echo 'No script command' 1>&2
+ fi
+ exit 2
+fi
diff --git a/test/ext/test-ls b/test/ext/test-ls
index a7bf35ed..b011015a 100755
--- a/test/ext/test-ls
+++ b/test/ext/test-ls
@@ -17,6 +17,7 @@ else
fi

bup() { "$top/bup" "$@"; }
+with-tty() { "$top/dev/with-tty" "$@"; }

bup-ls() {
if test "$BUP_TEST_REMOTE_REPO"; then
@@ -299,5 +300,19 @@ WVPASSEQ "$(bup-ls -l src/latest/bad-symlink | tr -s ' ' ' ')" \
"$bad_symlink_mode $user/$group $bad_symlink_size $bad_symlink_date src/latest/bad-symlink -> not-there"


+if ! with-tty true; then
+ WVSKIP 'Skipping interactive ouput truncation test (no supported script command)'
+else
+ WVSTART "output isn't truncated when isatty"
+ WVPASS rm -rf src
+ WVPASS mkdir src
+ echo src/some-longer-name-{1..3000} | WVPASS xargs touch
+ WVPASS bup index src
+ WVPASS bup save -n src --strip src
+ WVPASS with-tty "$top/bup" ls -l src/latest | WVPASS wc -l > ls-rows
+ WVPASSEQ 3000 $(<ls-rows)
+fi
+
+
WVPASS cd "$top"
WVPASS rm -rf "$tmpdir"
--
2.47.3

Reply all
Reply to author
Forward
0 new messages