summaryrefslogtreecommitdiffstats
path: root/tests/cat
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 16:58:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 16:58:41 +0000
commite1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe (patch)
treef5cc731bedcac0fb7fe14d952e4581e749f8bb87 /tests/cat
parentInitial commit. (diff)
downloadcoreutils-upstream.tar.xz
coreutils-upstream.zip
Adding upstream version 9.4.upstream/9.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/cat')
-rwxr-xr-xtests/cat/cat-E.sh42
-rwxr-xr-xtests/cat/cat-buf.sh47
-rwxr-xr-xtests/cat/cat-proc.sh38
-rwxr-xr-xtests/cat/cat-self.sh33
4 files changed, 160 insertions, 0 deletions
diff --git a/tests/cat/cat-E.sh b/tests/cat/cat-E.sh
new file mode 100755
index 0000000..28c02c1
--- /dev/null
+++ b/tests/cat/cat-E.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+# Copyright (C) 2021-2023 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cat
+
+# \r followed by \n is displayed as ^M$
+# Up to and including 8.32 the $ would have displayed at the start of the line
+# overwriting the first character
+printf 'a\rb\r\nc\n\r\nd\r' > 'in' || framework_failure_
+printf 'a\rb^M$\nc$\n^M$\nd\r' > 'exp' || framework_failure_
+cat -E 'in' > out || fail=1
+compare exp out || fail=1
+
+# Ensure \r\n spanning files (or buffers) is handled
+printf '1\r' > in2 || framework_failure_
+printf '\n2\r\n' > in2b || framework_failure_
+printf '1^M$\n2^M$\n' > 'exp' || framework_failure_
+cat -E 'in2' 'in2b' > out || fail=1
+compare exp out || fail=1
+
+# Ensure \r at end of buffer is handled
+printf '1\r' > in2 || framework_failure_
+printf '2\r\n' > in2b || framework_failure_
+printf '1\r2^M$\n' > 'exp' || framework_failure_
+cat -E 'in2' 'in2b' > out || fail=1
+compare exp out || fail=1
+
+Exit $fail
diff --git a/tests/cat/cat-buf.sh b/tests/cat/cat-buf.sh
new file mode 100755
index 0000000..c8bd697
--- /dev/null
+++ b/tests/cat/cat-buf.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Ensure that cat outputs processed data immediately.
+
+# Copyright (C) 2009-2023 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cat
+
+# Use a fifo rather than a pipe in the tests below
+# so that the producer (cat) will wait until the
+# consumer (dd) opens the fifo therefore increasing
+# the chance that dd will read the data from each
+# write separately.
+mkfifo_or_skip_ fifo
+
+# Terminate any background cp process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
+echo 1 > exp
+
+cat_buf_1()
+{
+ local delay="$1"
+
+ > out || framework_failure_
+ dd count=1 if=fifo > out & pid=$!
+ (echo 1; sleep $delay; echo 2) | cat -v > fifo
+ wait $pid
+ compare exp out
+}
+
+retry_delay_ cat_buf_1 .1 6 || fail=1
+
+Exit $fail
diff --git a/tests/cat/cat-proc.sh b/tests/cat/cat-proc.sh
new file mode 100755
index 0000000..b5b0e57
--- /dev/null
+++ b/tests/cat/cat-proc.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Ensure that cat -E produces same output as cat, modulo '$'s,
+# even when applied to a file in /proc.
+
+# Copyright (C) 2006-2023 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cat
+
+
+f=/proc/cpuinfo
+test -f $f \
+ || skip_ "no $f"
+
+
+# Yes, parts of /proc/cpuinfo might change between cat runs.
+# If that happens, consider choosing a file that's less likely to change,
+# or just filter out the changing lines. The sed filter should help
+# to avoid any spurious numeric differences.
+cat -E $f | sed 's/[0-9][0-9]*/D/g' | tr -d '$' > out || fail=1
+cat $f | sed 's/[0-9][0-9]*/D/g' | tr -d '$' > exp || fail=1
+
+compare exp out || fail=1
+
+Exit $fail
diff --git a/tests/cat/cat-self.sh b/tests/cat/cat-self.sh
new file mode 100755
index 0000000..ff2afdc
--- /dev/null
+++ b/tests/cat/cat-self.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Check that cat operates correctly when the input is the same as the output.
+
+# Copyright 2014-2023 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cat
+
+echo x >out || framework_failure_
+echo x >out1 || framework_failure_
+returns_ 1 cat out >>out || fail=1
+compare out out1 || fail=1
+
+# This example is taken from the POSIX spec for 'cat'.
+echo x >doc || framework_failure_
+echo y >doc.end || framework_failure_
+cat doc doc.end >doc || fail=1
+compare doc doc.end || fail=1
+
+Exit $fail