maint: silence deprecated module warning
[coreutils.git] / tests / head / head-c.sh
blob664e3d56b0830e24da169e4871c2d93d1ce9f122
1 #!/bin/sh
2 # exercise head -c
4 # Copyright (C) 2001-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ head
21 getlimits_
23 # exercise the fix of 2001-08-18, based on test case from Ian Bruce
24 echo abc > in || framework_failure_
25 (head -c1; head -c1) < in > out || fail=1
26 case "$(cat out)" in
27 ab) ;;
28 *) fail=1 ;;
29 esac
31 # Test for a bug in coreutils 5.0.1 through 8.22.
32 printf 'abc\ndef\n' > in1 || framework_failure_
33 (dd bs=1 skip=1 count=0 status=none && head -c-4) < in1 > out1 || fail=1
34 case "$(cat out1)" in
35 bc) ;;
36 *) fail=1 ;;
37 esac
39 # Only allocate memory as needed.
40 # Coreutils <= 8.21 would allocate memory up front
41 # based on the value passed to -c
42 vm=$(get_min_ulimit_v_ head -c1 /dev/null) && {
43 (ulimit -v $(($vm+8000)) && head --bytes=-$SSIZE_MAX < /dev/null) || fail=1
46 # Make sure it works on funny files in /proc and /sys.
48 for file in /proc/version /sys/kernel/profiling; do
49 if test -r $file; then
50 cp -f $file copy &&
51 head -c -1 copy > exp1 || framework_failure_
53 head -c -1 $file > out1 || fail=1
54 compare exp1 out1 || fail=1
56 done
58 Exit $fail