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
|
---|
19 | print_ver_ sed
|
---|
20 |
|
---|
21 | cat <<\EOF> exp-err-addr0 || framework_failure_
|
---|
22 | sed: -e expression #1, char 6: invalid usage of line address 0
|
---|
23 | EOF
|
---|
24 |
|
---|
25 | cat <<\EOF >exp-err-bad-addr || framework_failure_
|
---|
26 | sed: -e expression #1, char 3: unexpected `,'
|
---|
27 | EOF
|
---|
28 |
|
---|
29 | printf "%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
|
---|
33 | printf "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
|
---|
38 | printf "%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)
|
---|
42 | printf "%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)
|
---|
46 | printf "%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
|
---|
54 | sed -n '1,/A/p' in1 > out-l1 || fail=1
|
---|
55 | compare_ exp-l1 out-l1 || fail=1
|
---|
56 |
|
---|
57 | # address line=0 is a gnu extension
|
---|
58 | sed -n '0,/A/p' in1 > out-gnu-l0 || fail=1
|
---|
59 | compare_ exp-l0 out-gnu-l0 || fail=1
|
---|
60 | # rejected in posix mode
|
---|
61 | returns_ 1 sed --posix -n '0,/A/p' in1 2>err-posix-l0 || fail=1
|
---|
62 | compare_ exp-err-addr0 err-posix-l0 || fail=1
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | #
|
---|
67 | # Addressing extension: addr,+N
|
---|
68 | #
|
---|
69 | sed -n '2,+1p' in1 > out-plus || fail=1
|
---|
70 | compare_ exp-plus out-plus || fail=1
|
---|
71 |
|
---|
72 | returns_ 1 sed --posix -n '2,+1p' in1 2> err-plus || fail=1
|
---|
73 | compare_ exp-err-bad-addr err-plus || fail=1
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 | #
|
---|
78 | # Addressing extension: addr,~N
|
---|
79 | #
|
---|
80 |
|
---|
81 | sed -n '5,~4p' in1 > out-mult || fail=1
|
---|
82 | compare_ exp-mult out-mult || fail=1
|
---|
83 |
|
---|
84 | returns_ 1 sed --posix -n '5,~4p' in1 2> err-mult || fail=1
|
---|
85 | compare_ exp-err-bad-addr err-mult || fail=1
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | Exit $fail
|
---|