| 1 | #!/bin/sh
|
|---|
| 2 | # Ensure GNU extensions are rejected in posix mode
|
|---|
| 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 | cat <<\EOF >exp-err || framework_failure_
|
|---|
| 22 | sed: -e expression #1, char 7: unknown option to `s'
|
|---|
| 23 | EOF
|
|---|
| 24 |
|
|---|
| 25 | # substitution command options (
|
|---|
| 26 | # TODO: conditionally test sSxX in perl mode
|
|---|
| 27 | for opt in i I m M ;
|
|---|
| 28 | do
|
|---|
| 29 | # These options should fail in strict POSIX mode
|
|---|
| 30 | returns_ 1 sed --posix "s/a/b/$opt" </dev/null 2>err || fail=1
|
|---|
| 31 | compare_ exp-err err || fail=1
|
|---|
| 32 |
|
|---|
| 33 | # These options are allowed otherwise
|
|---|
| 34 | sed "s/a/b/$opt" </dev/null || fail=1
|
|---|
| 35 |
|
|---|
| 36 | # POSIXLY_CORRECT alone does not disable them
|
|---|
| 37 | POSIXLY_CORRECT=y sed "s/a/b/$opt" </dev/null || fail=1
|
|---|
| 38 | done
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | # test s//e (execute pattern-space as shell)
|
|---|
| 42 | printf "A\n" > in1 || framework_failure_
|
|---|
| 43 |
|
|---|
| 44 | printf "hello\n" >exp-gnu-e || framework_failure_
|
|---|
| 45 | sed 's/./printf hello/e' in1 > out-gnu-e || fail=1
|
|---|
| 46 | compare exp-gnu-e out-gnu-e || fail=1
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | # s///e rejected in POSIX mode
|
|---|
| 50 | cat <<\EOF >exp-err-psx-e || framework_failure_
|
|---|
| 51 | sed: -e expression #1, char 10: unknown option to `s'
|
|---|
| 52 | EOF
|
|---|
| 53 | returns_ 1 sed --posix 's/./echo/e' in1 2>err-posix-e || fail=1
|
|---|
| 54 | compare_ exp-err-psx-e err-posix-e || fail=1
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | # substitution special commands (e.g \l \L \U \u \E).
|
|---|
| 58 | # see compile.c:setup_replacement()
|
|---|
| 59 | printf "a\n" > exp-gnu || framework_failure_
|
|---|
| 60 | printf "lA\n" > exp-posix || framework_failure_
|
|---|
| 61 |
|
|---|
| 62 | # gnu-extension: turn the next character to lowercase
|
|---|
| 63 | sed 's/./\l&/' in1 > out-gnu || fail=1
|
|---|
| 64 | compare_ exp-gnu out-gnu || fail=1
|
|---|
| 65 |
|
|---|
| 66 | # posix: '\l' is just 'l'
|
|---|
| 67 | sed --posix 's/./\l&/' in1 > out-posix || fail=1
|
|---|
| 68 | compare_ exp-posix out-posix || fail=1
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | Exit $fail
|
|---|