VirtualBox

source: kBuild/vendor/sed/current/testsuite/panic-tests.sh@ 3611

Last change on this file since 3611 was 3611, checked in by bird, 7 months ago

vendor/sed/current: GNU sed 4.9 (sed-4.9.tar.xz sha256:6e226b732e1cd739464ad6862bd1a1aba42d7982922da7a53519631d24975181)

File size: 2.7 KB
Line 
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
19print_ver_ sed
20
21#
22# failure to create temp file
23#
24
25# inplace with an unwritable directory
26mkdir a || framework_failure_
27touch a/a || framework_failure_
28chmod a-w a || framework_failure_
29
30# Expected error message, with actual filename/errno trimmed
31cat <<\EOF >exp-err-temp || framework_failure_
32sed: couldn't open temporary file
33EOF
34
35# TODO: why exit-code 4 (currently hard-coded)
36returns_ 4 sed -i = a/a 2>err-temp || fail=1
37
38# trim the filename/errno message (using sed itself...)
39sed -i 's/file.*$/file/' err-temp || framework_failure_
40compare_ exp-err-temp err-temp || fail=1
41
42# restore writability, to ensure it can be deleted
43chmod a+w a || framework_failure_
44
45
46#
47# no input files (with inplace)
48#
49
50# Expected error message
51cat <<\EOF> exp-err-no-files || framework_failure_
52sed: no input files
53EOF
54
55# /dev/null to ensure it doesn't hang if panic is not invoked
56returns_ 4 sed -i = </dev/null 2>err-no-files || fail=1
57compare_ exp-err-no-files err-no-files || fail=1
58
59
60#
61# Not a regular file (with inplace)
62#
63cat <<\EOF >exp-err-not-reg-file || framework_failure_
64sed: couldn't edit f: not a regular file
65EOF
66
67mkfifo 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.
71printf a > f &
72
73# TODO: add a timeout in case of bug leading to a blocking fifo?
74returns_ 4 sed -i = f 2>err-not-reg-file || fail=1
75compare_ 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
84cat <<\EOF >exp-err-tty || framework_failure_
85sed: couldn't edit X: is a terminal
86EOF
87
88ttydev=no-such-file
89type tty >/dev/null 2>&1 && ttydev=$(tty 2>/dev/null)
90if 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
97fi
98
99
100
101Exit $fail
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette