source: trunk/src/sed/testsuite/in-place-suffix-backup.sh@ 3618

Last change on this file since 3618 was 3613, checked in by bird, 14 months ago

src/sed: Merged in changes between 4.1.5 and 4.9 from the vendor branch. (svn merge /vendor/sed/4.1.5 /vendor/sed/current .)

File size: 2.0 KB
Line 
1#!/bin/sh
2# Test -i/--inplace with backup suffixes
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# create multiple uniquely-named input files
23# (the content does not matter for the first few)
24touch a b c d e || framework_failure_
25echo z > z || framework_failure_
26printf "1\nz\n" >> exp-z || framework_failure_
27
28
29# TODO: misleading error: the problem is the target filename of rename(2),
30# not the source filename.
31cat <<\EOF >exp-err-rename || framework_failure_
32sed: cannot rename ./e: No such file or directory
33EOF
34
35
36# simple backup suffix
37sed -i.bak = a || fail=1
38test -e a.bak || fail=1
39
40# backup suffix with explicit wildcard
41sed -i'*.foo' = b || fail=1
42test -e b.foo || fail=1
43
44sed -i'==*==' = c || fail=1
45test -e ==c== || fail=1
46
47# abuse the suffix-name resolver
48sed -i'*=*' = d || fail=1
49test -e d=d || fail=1
50
51# This fails (as expected, with the backup name resolving './e./e./e').
52# TODO: improve error message;
53# document why exit code is 4.
54returns_ 4 sed -i'***' = ./e 2>err-rename || fail=1
55compare_ exp-err-rename err-rename || fail=1
56
57# backup filename resolving to the same as the input filename,
58# silently ignored, backup not created (in execute.c:closedown() ).
59sed -i'*' = z || fail=1
60# ensure the input file was modified in-place
61compare_ exp-z z || fail=1
62
63
64Exit $fail
Note: See TracBrowser for help on using the repository browser.