tests: move tests to a directory per utility

* cfg.mk: Adjust syntax check exclusion paths.
* tests/local.mk: Adjust for renamed tests.
This commit is contained in:
Sylvestre Ledru
2023-06-11 11:55:56 +02:00
committed by Pádraig Brady
parent d53190ed46
commit 15925d0e5b
204 changed files with 204 additions and 204 deletions

42
tests/cat/cat-E.sh Executable file
View File

@@ -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

47
tests/cat/cat-buf.sh Executable file
View File

@@ -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

38
tests/cat/cat-proc.sh Executable file
View File

@@ -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

33
tests/cat/cat-self.sh Executable file
View File

@@ -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