1 | #!/bin/sh
|
---|
2 | # Exercise some panic stops
|
---|
3 |
|
---|
4 | # Copyright (C) 2016-2022 Free Software Foundation, Inc.
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
---|
19 | print_ver_ sed
|
---|
20 |
|
---|
21 | #
|
---|
22 | # failure to create temp file
|
---|
23 | #
|
---|
24 |
|
---|
25 | # inplace with an unwritable directory
|
---|
26 | mkdir a || framework_failure_
|
---|
27 | touch a/a || framework_failure_
|
---|
28 | chmod a-w a || framework_failure_
|
---|
29 |
|
---|
30 | # Expected error message, with actual filename/errno trimmed
|
---|
31 | cat <<\EOF >exp-err-temp || framework_failure_
|
---|
32 | sed: couldn't open temporary file
|
---|
33 | EOF
|
---|
34 |
|
---|
35 | # TODO: why exit-code 4 (currently hard-coded)
|
---|
36 | returns_ 4 sed -i = a/a 2>err-temp || fail=1
|
---|
37 |
|
---|
38 | # trim the filename/errno message (using sed itself...)
|
---|
39 | sed -i 's/file.*$/file/' err-temp || framework_failure_
|
---|
40 | compare_ exp-err-temp err-temp || fail=1
|
---|
41 |
|
---|
42 | # restore writability, to ensure it can be deleted
|
---|
43 | chmod a+w a || framework_failure_
|
---|
44 |
|
---|
45 |
|
---|
46 | #
|
---|
47 | # no input files (with inplace)
|
---|
48 | #
|
---|
49 |
|
---|
50 | # Expected error message
|
---|
51 | cat <<\EOF> exp-err-no-files || framework_failure_
|
---|
52 | sed: no input files
|
---|
53 | EOF
|
---|
54 |
|
---|
55 | # /dev/null to ensure it doesn't hang if panic is not invoked
|
---|
56 | returns_ 4 sed -i = </dev/null 2>err-no-files || fail=1
|
---|
57 | compare_ exp-err-no-files err-no-files || fail=1
|
---|
58 |
|
---|
59 |
|
---|
60 | #
|
---|
61 | # Not a regular file (with inplace)
|
---|
62 | #
|
---|
63 | cat <<\EOF >exp-err-not-reg-file || framework_failure_
|
---|
64 | sed: couldn't edit f: not a regular file
|
---|
65 | EOF
|
---|
66 |
|
---|
67 | mkfifo f || framework_failure_
|
---|
68 |
|
---|
69 | # NOTE: the file-mode check is not performed until the first line is read.
|
---|
70 | # an empty/blocking fifo will hang forever.
|
---|
71 | printf a > f &
|
---|
72 |
|
---|
73 | # TODO: add a timeout in case of bug leading to a blocking fifo?
|
---|
74 | returns_ 4 sed -i = f 2>err-not-reg-file || fail=1
|
---|
75 | compare_ exp-err-not-reg-file err-not-reg-file || fail=1
|
---|
76 |
|
---|
77 |
|
---|
78 | #
|
---|
79 | # inplace on a terminal device
|
---|
80 | # (if available)
|
---|
81 | #
|
---|
82 |
|
---|
83 | #NOTE: device name is replaced later
|
---|
84 | cat <<\EOF >exp-err-tty || framework_failure_
|
---|
85 | sed: couldn't edit X: is a terminal
|
---|
86 | EOF
|
---|
87 |
|
---|
88 | ttydev=no-such-file
|
---|
89 | type tty >/dev/null 2>&1 && ttydev=$(tty 2>/dev/null)
|
---|
90 | if test -w "$ttydev" && test -r "$ttydev" ; then
|
---|
91 | returns_ 4 sed -i = "$ttydev" 2>err-tty || fail=1
|
---|
92 |
|
---|
93 | # remove the actual terminal device name (using sed itself...)
|
---|
94 | sed -i 's/edit.*:/edit X:/' err-tty || framework_failure_
|
---|
95 |
|
---|
96 | compare_ exp-err-tty err-tty || fail=1
|
---|
97 | fi
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | Exit $fail
|
---|