source: trunk/src/sed/testsuite/posix-mode-addr.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.5 KB
Line 
1#!/bin/sh
2# Ensure GNU address 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-addr0 || framework_failure_
22sed: -e expression #1, char 6: invalid usage of line address 0
23EOF
24
25cat <<\EOF >exp-err-bad-addr || framework_failure_
26sed: -e expression #1, char 3: unexpected `,'
27EOF
28
29printf "%s\n" A B A C D E F G H I J >in1 || framework_failure_
30
31# The expected output with zero-line address '0,/A/'
32# the regex will match the first line
33printf "A\n" >exp-l0 || framework_failure_
34
35# The expected output with one-line address '1,/A/'
36# the regex will not be checked against the first line,
37# will match the third line
38printf "%s\n" A B A >exp-l1 || framework_failure_
39
40# The expected output with address '2,+1'
41# (from line 2, count 1 addition line = line 3)
42printf "%s\n" B A >exp-plus || framework_failure_
43
44# The expected output with address '5,~4'
45# (from line 5 till a multiple of 4 = line 8)
46printf "%s\n" D E F G >exp-mult || framework_failure_
47
48
49#
50# Addressing extension: 0,/regexp/
51#
52
53# sanity check: address line=1 is valid for both posix and gnu
54sed -n '1,/A/p' in1 > out-l1 || fail=1
55compare_ exp-l1 out-l1 || fail=1
56
57# address line=0 is a gnu extension
58sed -n '0,/A/p' in1 > out-gnu-l0 || fail=1
59compare_ exp-l0 out-gnu-l0 || fail=1
60# rejected in posix mode
61returns_ 1 sed --posix -n '0,/A/p' in1 2>err-posix-l0 || fail=1
62compare_ exp-err-addr0 err-posix-l0 || fail=1
63
64
65
66#
67# Addressing extension: addr,+N
68#
69sed -n '2,+1p' in1 > out-plus || fail=1
70compare_ exp-plus out-plus || fail=1
71
72returns_ 1 sed --posix -n '2,+1p' in1 2> err-plus || fail=1
73compare_ exp-err-bad-addr err-plus || fail=1
74
75
76
77#
78# Addressing extension: addr,~N
79#
80
81sed -n '5,~4p' in1 > out-mult || fail=1
82compare_ exp-mult out-mult || fail=1
83
84returns_ 1 sed --posix -n '5,~4p' in1 2> err-mult || fail=1
85compare_ exp-err-bad-addr err-mult || fail=1
86
87
88
89Exit $fail
Note: See TracBrowser for help on using the repository browser.