tests: add test for locale decimal processing
[coreutils.git] / tests / misc / csplit-io-err.sh
bloba1a17f971ca5a03d50b786a6d140f645b7399f01
1 #!/bin/sh
2 # Ensure we handle i/o errors correctly in csplit
4 # Copyright (C) 2015-2019 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_ csplit
21 require_gcc_shared_
23 if ! test -w /dev/full || ! test -c /dev/full; then
24 skip_ '/dev/full is required'
27 # Ensure error messages are in English
28 LC_ALL=C
29 export LC_ALL
31 # Replace fwrite and ferror, always returning an error
32 cat > k.c <<'EOF' || framework_failure_
33 #include <stdio.h>
34 #include <errno.h>
36 #undef fwrite
37 #undef fwrite_unlocked
39 size_t
40 fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream)
42 fclose (fopen ("preloaded","w")); /* marker for preloaded interception */
43 errno = ENOSPC;
44 return 0;
47 size_t
48 fwrite_unlocked (const void *ptr, size_t size, size_t nitems, FILE *stream)
50 return fwrite (ptr, size, nitems, stream);
52 EOF
54 # Get the wording of the OS-dependent ENOSPC message
55 returns_ 1 seq 1 >/dev/full 2>msgt || framework_failure_
56 sed 's/seq: write error: //' msgt > msg || framework_failure_
58 # Create the expected error message
59 { printf "%s" "csplit: write error for 'xx01': " ; cat msg ; } > exp \
60 || framework_failure_
62 # compile/link the interception shared library:
63 gcc_shared_ k.c k.so \
64 || skip_ 'failed to build forced-fwrite-failure shared library'
66 # Split the input, and force fwrite() failure -
67 # the 'csplit' command should fail with exit code 1
68 # (checked with 'returns_ 1 ... || fail=1')
69 seq 10 |
70 (export LD_PRELOAD=$LD_PRELOAD:./k.so
71 returns_ 1 csplit - 1 4 2>out) || fail=1
73 test -e preloaded || skip_ 'LD_PRELOAD interception failed'
75 # Ensure we got the expected error message
76 compare exp out || fail=1
78 Exit $fail