| [3611] | 1 | #!/bin/sh
|
|---|
| 2 | # Test command separators and endings
|
|---|
| 3 |
|
|---|
| 4 | # Copyright (C) 2017-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 | # Allowed endings/separators after most commands:
|
|---|
| 22 | # newline, comment, closing brace, semicolon, EOF
|
|---|
| 23 | # they are also allowed after opening and closing braces themselves.
|
|---|
| 24 | #
|
|---|
| 25 | # Not tested here:
|
|---|
| 26 | # r/R/w/R/e and s///[we] which use read_filename() and do not
|
|---|
| 27 | # accept comments or semicolons.
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | # Test commands and braces followed by:
|
|---|
| 32 | # closing braces, comment, semicolons, EOF (newlines are tested later).
|
|---|
| 33 | #
|
|---|
| 34 | # sed-4.3 wrongly rejected y/// followed by '}' or '#' (bug#22460).
|
|---|
| 35 | #
|
|---|
| 36 | # Implementation notes (see compile.c):
|
|---|
| 37 | # Simple commands, '}', and 'y///' commands use read_end_of_cmd().
|
|---|
| 38 | #
|
|---|
| 39 | # q/Q/l/L have additional check for optional integer,
|
|---|
| 40 | # then call read_end_of_cmd().
|
|---|
| 41 | #
|
|---|
| 42 | # labels use 'read_label()'.
|
|---|
| 43 | #
|
|---|
| 44 | # 's///' has special handling, depending on additional flags
|
|---|
| 45 | # (with 's///[we]' commands and semicolons are not allowed).
|
|---|
| 46 | # Implemented in mark_subst_opts().
|
|---|
| 47 | #
|
|---|
| 48 | for p in \
|
|---|
| 49 | 'h' \
|
|---|
| 50 | 'h;' \
|
|---|
| 51 | 'h ;' \
|
|---|
| 52 | 'h# foo' \
|
|---|
| 53 | 'h # foo' \
|
|---|
| 54 | '{h}' \
|
|---|
| 55 | '{h } ' \
|
|---|
| 56 | '{ h } ' \
|
|---|
| 57 | \
|
|---|
| 58 | '{h}# foo' \
|
|---|
| 59 | '{h} # foo' \
|
|---|
| 60 | '{h};' \
|
|---|
| 61 | '{h} ;' \
|
|---|
| 62 | '{;h;} ' \
|
|---|
| 63 | '{{h}}' \
|
|---|
| 64 | '{;{h};}' \
|
|---|
| 65 | \
|
|---|
| 66 | 'y/1/a/' \
|
|---|
| 67 | 'y/1/a/;d' \
|
|---|
| 68 | 'y/1/a/ ;d' \
|
|---|
| 69 | '{y/1/a/}' \
|
|---|
| 70 | 'y/1/a/#foo'\
|
|---|
| 71 | 'y/1/a/ #fo'\
|
|---|
| 72 | \
|
|---|
| 73 | 's/1/a/' \
|
|---|
| 74 | 's/1/a/;d' \
|
|---|
| 75 | 's/1/a/ ;d' \
|
|---|
| 76 | '{s/1/a/}' \
|
|---|
| 77 | 's/1/a/#foo'\
|
|---|
| 78 | 's/1/a/ #fo'\
|
|---|
| 79 | \
|
|---|
| 80 | 's/1/a/i ;' \
|
|---|
| 81 | 's/1/a/i #foo' \
|
|---|
| 82 | '{ s/1/a/i }' \
|
|---|
| 83 | \
|
|---|
| 84 | 'bx; :x' \
|
|---|
| 85 | 'bx; :x;' \
|
|---|
| 86 | 'bx; :x ;' \
|
|---|
| 87 | 'bx; :x#foo' \
|
|---|
| 88 | 'bx; :x #foo' \
|
|---|
| 89 | '{ bx; :x }' \
|
|---|
| 90 | \
|
|---|
| 91 | 'l' \
|
|---|
| 92 | 'l;' \
|
|---|
| 93 | 'l ;' \
|
|---|
| 94 | 'l#foo' \
|
|---|
| 95 | 'l #foo' \
|
|---|
| 96 | '{l}' \
|
|---|
| 97 | '{l }' \
|
|---|
| 98 | 'l1' \
|
|---|
| 99 | 'l1;' \
|
|---|
| 100 | 'l1 ;' \
|
|---|
| 101 | 'l1#foo' \
|
|---|
| 102 | 'l1 #foo' \
|
|---|
| 103 | '{l1}' \
|
|---|
| 104 | '{l1 }' \
|
|---|
| 105 | ;
|
|---|
| 106 | do
|
|---|
| 107 | sed -n "$p" < /dev/null >out 2>err || fail=1
|
|---|
| 108 | compare /dev/null err || fail=1
|
|---|
| 109 | compare /dev/null out || fail=1
|
|---|
| 110 | done
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | # Create files to test newlines after commands
|
|---|
| 114 | # (instead of having to embed newlines in shell variables in a portable way)
|
|---|
| 115 | printf 'd\n' > nl1 || framework_failure_
|
|---|
| 116 | printf '{\nd}' > nl2 || framework_failure_
|
|---|
| 117 | printf '{d\n}' > nl3 || framework_failure_
|
|---|
| 118 | printf '{d}\n' > nl4 || framework_failure_
|
|---|
| 119 | printf 'y/1/a/\n' > nl5 || framework_failure_
|
|---|
| 120 | printf 's/1/a/\n' > nl6 || framework_failure_
|
|---|
| 121 | printf 'bx\n:x\n' > nl7 || framework_failure_
|
|---|
| 122 | printf 'l\n' > nl8 || framework_failure_
|
|---|
| 123 | printf 'l1\n' > nl9 || framework_failure_
|
|---|
| 124 | # s/// has special allowance for \r in mark_subst_opts(),
|
|---|
| 125 | # even if not on windows.
|
|---|
| 126 | # TODO: should other commands allow it ?
|
|---|
| 127 | printf 's/1/a/\r\n' > nl10 || framework_failure_
|
|---|
| 128 |
|
|---|
| 129 | for i in 1 2 3 4 5 6 7 8 9 10 ;
|
|---|
| 130 | do
|
|---|
| 131 | sed -n -f "nl$i" </dev/null >out 2>err || fail=1
|
|---|
| 132 | compare /dev/null err || fail=1
|
|---|
| 133 | compare /dev/null out || fail=1
|
|---|
| 134 | done
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 | Exit $fail
|
|---|