| 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
|
|---|
| 19 | print_ver_ sed
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | # create multiple uniquely-named input files
|
|---|
| 23 | # (the content does not matter for the first few)
|
|---|
| 24 | touch a b c d e || framework_failure_
|
|---|
| 25 | echo z > z || framework_failure_
|
|---|
| 26 | printf "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.
|
|---|
| 31 | cat <<\EOF >exp-err-rename || framework_failure_
|
|---|
| 32 | sed: cannot rename ./e: No such file or directory
|
|---|
| 33 | EOF
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | # simple backup suffix
|
|---|
| 37 | sed -i.bak = a || fail=1
|
|---|
| 38 | test -e a.bak || fail=1
|
|---|
| 39 |
|
|---|
| 40 | # backup suffix with explicit wildcard
|
|---|
| 41 | sed -i'*.foo' = b || fail=1
|
|---|
| 42 | test -e b.foo || fail=1
|
|---|
| 43 |
|
|---|
| 44 | sed -i'==*==' = c || fail=1
|
|---|
| 45 | test -e ==c== || fail=1
|
|---|
| 46 |
|
|---|
| 47 | # abuse the suffix-name resolver
|
|---|
| 48 | sed -i'*=*' = d || fail=1
|
|---|
| 49 | test -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.
|
|---|
| 54 | returns_ 4 sed -i'***' = ./e 2>err-rename || fail=1
|
|---|
| 55 | compare_ 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() ).
|
|---|
| 59 | sed -i'*' = z || fail=1
|
|---|
| 60 | # ensure the input file was modified in-place
|
|---|
| 61 | compare_ exp-z z || fail=1
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | Exit $fail
|
|---|