From f5ded57fbd87b08a7e7cabd206520ae34a8ee108 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 8 Nov 2026 22:33:33 +0100 Subject: [PATCH] tests: tail: check output appended to the input stops at its end * tests/tail/append-to-input.sh: New test. * tests/local.mk (all_tests): Reference it. https://github.com/uutils/coreutils/pull/15066 Link: https://github.com/coreutils/coreutils/pull/455 --- tests/local.mk | 1 + tests/tail/append-to-input.sh | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 tests/tail/append-to-input.sh diff --git a/tests/local.mk b/tests/local.mk index 926ac1514..a065bcb17 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -195,6 +195,7 @@ all_tests = \ tests/misc/uname-labeled.sh \ tests/misc/warning-errors.sh \ tests/misc/write-errors.sh \ + tests/tail/append-to-input.sh \ tests/tail/basic-seek.sh \ tests/tail/inotify-hash-abuse.sh \ tests/tail/inotify-hash-abuse2.sh \ diff --git a/tests/tail/append-to-input.sh b/tests/tail/append-to-input.sh new file mode 100755 index 000000000..ea7fa7fbb --- /dev/null +++ b/tests/tail/append-to-input.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Ensure tail stops at the original end of a file appended to its output + +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail seq + +# Cap the file size so a runaway tail cannot fill the file system. +(ulimit -f 10000) 2>/dev/null || skip_ 'unable to limit file size' + +# A file larger than a buffer, read from the end. +for opt in -n1 -c4; do + seq 100000 > in || framework_failure_ + cp in exp || framework_failure_ + tail $opt in >> exp || framework_failure_ + (ulimit -f 10000; timeout 10 tail $opt in >> in) || fail=1 + compare exp in || fail=1 +done + +# A small file, read from the start. +for opt in -n+2 -c+3; do + printf 'a\nb\nc\n' > in || framework_failure_ + printf 'a\nb\nc\nb\nc\n' > exp || framework_failure_ + (ulimit -f 10000; timeout 10 tail $opt in >> in) || fail=1 + compare exp in || fail=1 +done + +Exit $fail