1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
#!/bin/sh
# Test compilation errors
# Copyright (C) 2016-2017 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
print_ver_ sed
fail=0
#
# Excess P modifier to s// (EXCESS_P_OPT)
#
cat <<\EOF >exp-exs-p || framework_failure_
sed: -e expression #1, char 8: multiple `p' options to `s' command
EOF
returns_ 1 sed 's/./x/pp' </dev/null 2>err-exs-p || fail=1
compare_ exp-exs-p err-exs-p || fail=1
#
# Excess G modifier to s// (EXCESS_G_OPT)
#
cat <<\EOF >exp-exs-g || framework_failure_
sed: -e expression #1, char 8: multiple `g' options to `s' command
EOF
returns_ 1 sed 's/./x/gg' </dev/null 2>err-exs-g || fail=1
compare_ exp-exs-g err-exs-g || fail=1
#
# zero numeric modifier to s// (ZERO_N_OPT)
#
cat <<\EOF >exp-exs-0 || framework_failure_
sed: -e expression #1, char 7: number option to `s' command may not be zero
EOF
returns_ 1 sed 's/./x/0' </dev/null 2>err-exs-0 || fail=1
compare_ exp-exs-0 err-exs-0 || fail=1
#
# Multiple number modifiers to s// (EXCESS_N_OPT)
#
cat <<\EOF >exp-exs-n || framework_failure_
sed: -e expression #1, char 9: multiple number options to `s' command
EOF
returns_ 1 sed 's/./x/2p3' </dev/null 2>err-exs-n || fail=1
compare_ exp-exs-n err-exs-n || fail=1
#
# Unknown s/// modifier letter
#
cat << \EOF >exp-unk-s-opt || framework_failure_
sed: -e expression #1, char 7: unknown option to `s'
EOF
returns_ 1 sed 's/./x/Q' </dev/null 2>err-unk-s-opt || fail=1
compare_ exp-unk-s-opt err-unk-s-opt || fail=1
#
# Special case: s/// followed by \r alone
#
printf "s/./x/\r" > s-opt-r-in || framework_failure_
cat << \EOF >exp-s-opt-r || framework_failure_
sed: file s-opt-r-in line 1: unknown option to `s'
EOF
returns_ 1 sed -f s-opt-r-in </dev/null 2>err-s-opt-r || fail=1
compare_ exp-s-opt-r err-s-opt-r || fail=1
#
# Step-address as first address (BAD_STEP)
# (both +N and ~N addresses)
cat <<\EOF >exp-step-addr || framework_failure_
sed: -e expression #1, char 2: invalid usage of +N or ~N as first address
EOF
returns_ 1 sed '~1d' </dev/null 2>err-step-addr1 || fail=1
compare_ exp-step-addr err-step-addr1 || fail=1
returns_ 1 sed '+1d' </dev/null 2>err-step-addr2 || fail=1
compare_ exp-step-addr err-step-addr2 || fail=1
#
# Multiple '!' (BAD_BANG)
#
cat <<\EOF >exp-bad-bang || framework_failure_
sed: -e expression #1, char 3: multiple `!'s
EOF
returns_ 1 sed '1!!d' </dev/null 2>err-bad-bang || fail=1
compare_ exp-bad-bang err-bad-bang || fail=1
#
# GNU extension commands, not accepted in --posix mode
# (bad_command(OPT))
for opt in e F v z L Q T R W ;
do
cat <<EOF >exp-posix-cmd-$opt || framework_failure_
sed: -e expression #1, char 2: unknown command: \`$opt'
EOF
returns_ 1 sed --posix "1$opt" </dev/null 2>err-posix-cmd-$opt || fail=1
compare_ exp-posix-cmd-$opt err-posix-cmd-$opt || fail=1
done
#
# GNU extension commands, accepting only one address in --posix mode
# (ONE_ADDR)
cat <<\EOF >exp-one-addr || framework_failure_
sed: -e expression #1, char 4: command only uses one address
EOF
for opt in a i l = r ;
do
returns_ 1 sed --posix "1,2$opt" </dev/null 2>err-posix-cmd-$opt || fail=1
compare_ exp-one-addr err-posix-cmd-$opt || fail=1
done
# q/Q always accept one address (Q is gnu extension, can't use --posix, above)
for opt in q Q ;
do
returns_ 1 sed "1,2$opt" </dev/null 2>err-posix-cmd-$opt || fail=1
compare_ exp-one-addr err-posix-cmd-$opt || fail=1
done
#
# Comment with address (NO_CLOSE_BRACE_ADDR)
#
cat <<\EOF >exp-no-sharp || framework_failure_
sed: -e expression #1, char 2: comments don't accept any addresses
EOF
returns_ 1 sed '1#foo' </dev/null 2>err-no-sharp || fail=1
compare_ exp-no-sharp err-no-sharp || fail=1
#
# Unexpected closing braces (EXCESS_CLOSE_BRACE)
#
cat <<\EOF >exp-unexp-brace || framework_failure_
sed: -e expression #1, char 2: unexpected `}'
EOF
returns_ 1 sed '1}' </dev/null 2>err-unexp-brace || fail=1
compare_ exp-unexp-brace err-unexp-brace || fail=1
#
# Umatched opening braces (EXCESS_OPEN_BRACE)
# TODO: why 'char 0' ?
cat <<\EOF >exp-unmatched-braces || framework_failure_
sed: -e expression #1, char 0: unmatched `{'
EOF
returns_ 1 sed '1{' </dev/null 2>err-unmatched-braces || fail=1
compare_ exp-unmatched-braces err-unmatched-braces || fail=1
#
# '}' with address (NO_CLOSE_BRACE_ADDR)
#
cat <<\EOF >exp-brace-addr || framework_failure_
sed: -e expression #1, char 3: `}' doesn't want any addresses
EOF
returns_ 1 sed '{1}' </dev/null 2>err-brace-addr || fail=1
compare_ exp-brace-addr err-brace-addr || fail=1
#
# Too new version requested (ANCIENT_VERSION)
# (i.e. this version of SED is too old)
cat <<\EOF >exp-anc-ver || framework_failure_
sed: -e expression #1, char 4: expected newer version of sed
EOF
returns_ 1 sed 'v9.0' </dev/null 2>err-anc-ver || fail=1
compare_ exp-anc-ver err-anc-ver || fail=1
#
# Junk after command (EXCESS_JUNK)
# notes: EOF, \n or ';' are allowed after a command.
# multiple places abort with EXCESS_JUNK, check them all.
# dummy addresses ensure the offending char is the same.
cat <<\EOF >exp-junk || framework_failure_
sed: -e expression #1, char 7: extra characters after command
EOF
returns_ 1 sed '11111=d' </dev/null 2>err-junk || fail=1
compare_ exp-junk err-junk || fail=1
returns_ 1 sed 'y/a/b/d' </dev/null 2>err-junk-y || fail=1
compare_ exp-junk err-junk-y || fail=1
returns_ 1 sed '1111{}d' </dev/null 2>err-junk-braces || fail=1
compare_ exp-junk err-junk-braces || fail=1
returns_ 1 sed '22222ld' </dev/null 2>err-junk-braces || fail=1
compare_ exp-junk err-junk-braces || fail=1
#
# Slash after a/c/i (EXPECTED_SLASH)
# note: GNU extensions are less strict than --posix.
cat <<\EOF >exp-junk || framework_failure_
sed: -e expression #1, char 2: expected \ after `a', `c' or `i'
EOF
for opt in a c i ;
do
# EOF after command
returns_ 1 sed "1$opt" </dev/null 2>err-junk-$opt || fail=1
compare_ exp-junk err-junk-$opt || fail=1
# no slash after command, in GNU extension mode - accepted.
sed "1${opt}foo" </dev/null >/dev/null || fail=1
# no slash after command, in --posix mode - rejected.
returns_ 1 sed --posix "${opt}foo" </dev/null 2>err-junk-$opt-psx || fail=1
compare_ exp-junk err-junk-$opt-psx || fail=1
done
#
# ':' with address (NO_COLON_ADDR)
#
cat <<\EOF >exp-colon-addr || framework_failure_
sed: -e expression #1, char 2: : doesn't want any addresses
EOF
returns_ 1 sed '2:' </dev/null 2>err-colon-addr || fail=1
compare_ exp-colon-addr err-colon-addr || fail=1
#
# q/Q need one address (ONE_ADDR)
#
cat <<\EOF >exp-colon-addr || framework_failure_
sed: -e expression #1, char 2: : doesn't want any addresses
EOF
returns_ 1 sed '2:' </dev/null 2>err-colon-addr || fail=1
compare_ exp-colon-addr err-colon-addr || fail=1
#
# unterminated Y commands (UNTERM_Y_CMD)
# NOTE: the code calls bad_proc(UNTERM_Y_CMD)
# in multiple places due to varied conditions - check them all.
# dummy addresses ensures the offending character is always 5.
cat <<\EOF >exp-unterm-y || framework_failure_
sed: -e expression #1, char 5: unterminated `y' command
EOF
returns_ 1 sed '1111y' </dev/null 2>err-unterm-y1 || fail=1
compare_ exp-unterm-y err-unterm-y1 || fail=1
returns_ 1 sed '111y/' </dev/null 2>err-unterm-y2 || fail=1
compare_ exp-unterm-y err-unterm-y2 || fail=1
returns_ 1 sed '11y/a' </dev/null 2>err-unterm-y3 || fail=1
compare_ exp-unterm-y err-unterm-y3 || fail=1
returns_ 1 sed '1y/a/' </dev/null 2>err-unterm-y4 || fail=1
compare_ exp-unterm-y err-unterm-y4 || fail=1
returns_ 1 sed 'y/a/a' </dev/null 2>err-unterm-y5 || fail=1
compare_ exp-unterm-y err-unterm-y5 || fail=1
#
# Y command with bad legth (Y_CMD_LEN)
# TODO: check with multibyte strings.
cat <<\EOF >exp-bad-y-len || framework_failure_
sed: -e expression #1, char 7: strings for `y' command are different lengths
EOF
returns_ 1 sed 'y/a/bb/' </dev/null 2>err-bad-y-len || fail=1
compare_ exp-bad-y-len err-bad-y-len || fail=1
#
# GNU Extension: allow a/c/i to continue in next 'program'.
# in --posix mode, reject it with "incomplete command" (INCOMPLETE_CMD)
#
cat <<\EOF >exp-inc-cmd || framework_failure_
sed: -e expression #1, char 2: incomplete command
EOF
for opt in a c i ;
do
# works as a gnu extension
sed -e "$opt\\" -e foo < /dev/null || fail=1
# rejected in posix mode
returns_ 1 sed --posix -e "$opt\\" -e foo </dev/null 2>err-inc-cmd-$opt \
|| fail=1
compare_ exp-inc-cmd err-inc-cmd-$opt || fail=1
done
Exit $fail
|