source: trunk/src/sed/testsuite/posix-mode-s.sh@ 3670

Last change on this file since 3670 was 3613, checked in by bird, 10 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.3 KB
Line 
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
19print_ver_ sed
20
21cat <<\EOF >exp-err || framework_failure_
22sed: -e expression #1, char 7: unknown option to `s'
23EOF
24
25# substitution command options (
26# TODO: conditionally test sSxX in perl mode
27for opt in i I m M ;
28do
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
38done
39
40
41# test s//e (execute pattern-space as shell)
42printf "A\n" > in1 || framework_failure_
43
44printf "hello\n" >exp-gnu-e || framework_failure_
45sed 's/./printf hello/e' in1 > out-gnu-e || fail=1
46compare exp-gnu-e out-gnu-e || fail=1
47
48
49# s///e rejected in POSIX mode
50cat <<\EOF >exp-err-psx-e || framework_failure_
51sed: -e expression #1, char 10: unknown option to `s'
52EOF
53returns_ 1 sed --posix 's/./echo/e' in1 2>err-posix-e || fail=1
54compare_ 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()
59printf "a\n" > exp-gnu || framework_failure_
60printf "lA\n" > exp-posix || framework_failure_
61
62# gnu-extension: turn the next character to lowercase
63sed 's/./\l&/' in1 > out-gnu || fail=1
64compare_ exp-gnu out-gnu || fail=1
65
66# posix: '\l' is just 'l'
67sed --posix 's/./\l&/' in1 > out-posix || fail=1
68compare_ exp-posix out-posix || fail=1
69
70
71Exit $fail
Note: See TracBrowser for help on using the repository browser.