| 1 | #!/bin/sh
|
|---|
| 2 | # Test the '#n' silent mode (activated by first line comment)
|
|---|
| 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 | echo X > in1 || framework_failure_
|
|---|
| 22 |
|
|---|
| 23 | # expected output with 'sed -n = in1' (silent mode)
|
|---|
| 24 | echo 1 > exp-silent || framework_failure_
|
|---|
| 25 |
|
|---|
| 26 | # expected output with 'sed = in1' (not silent mode)
|
|---|
| 27 | printf "1\nX\n" > exp-norm || framework_failure_
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | # A comment '#n' in the first script, in the first line
|
|---|
| 31 | sed -e '#n' in1 > out1 || fail=1
|
|---|
| 32 | compare_ /dev/null out1 || fail=1
|
|---|
| 33 |
|
|---|
| 34 | sed -e '#n' -e = in1 > out2 || fail=1
|
|---|
| 35 | compare_ exp-silent out2 || fail=1
|
|---|
| 36 |
|
|---|
| 37 | sed -e '#ni!' -e = in1 > out3 || fail=1
|
|---|
| 38 | compare_ exp-silent out3 || fail=1
|
|---|
| 39 |
|
|---|
| 40 | # not the first 2 characters, or space before n,
|
|---|
| 41 | # or uppercase N - do not activate silent mode
|
|---|
| 42 | sed -e '=#n' in1 > out4 || fail=1
|
|---|
| 43 | compare_ exp-norm out4 || fail=1
|
|---|
| 44 |
|
|---|
| 45 | sed -e '# n' -e = in1 > out5 || fail=1
|
|---|
| 46 | compare_ exp-norm out5 || fail=1
|
|---|
| 47 |
|
|---|
| 48 | sed -e '#N' -e = in1 > out6 || fail=1
|
|---|
| 49 | compare_ exp-norm out6 || fail=1
|
|---|
| 50 |
|
|---|
| 51 | sed -e = -e '#n' in1 > out7 || fail=1
|
|---|
| 52 | compare_ exp-norm out7 || fail=1
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | #
|
|---|
| 56 | # Test the same, with a program instead of -e.
|
|---|
| 57 | #
|
|---|
| 58 | cat << \EOF > prog1 || framework_failure_
|
|---|
| 59 | #n
|
|---|
| 60 | =
|
|---|
| 61 | EOF
|
|---|
| 62 | sed -f prog1 in1 > out8 || fail=1
|
|---|
| 63 | compare_ exp-silent out8 || fail=1
|
|---|
| 64 |
|
|---|
| 65 | # not in the first 2 characters
|
|---|
| 66 | cat << \EOF > prog2 || framework_failure_
|
|---|
| 67 | =
|
|---|
| 68 | #n
|
|---|
| 69 | EOF
|
|---|
| 70 | sed -f prog2 in1 > out9 || fail=1
|
|---|
| 71 | compare_ exp-norm out9 || fail=1
|
|---|
| 72 |
|
|---|
| 73 | # not in the first 2 characters
|
|---|
| 74 | cat << \EOF > prog3 || framework_failure_
|
|---|
| 75 | # n
|
|---|
| 76 | =
|
|---|
| 77 | EOF
|
|---|
| 78 | sed -f prog3 in1 > out10 || fail=1
|
|---|
| 79 | compare_ exp-norm out10 || fail=1
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | # -e then a program file.
|
|---|
| 83 | cat << \EOF > prog4 || framework_failure_
|
|---|
| 84 | #n
|
|---|
| 85 | EOF
|
|---|
| 86 | sed -e = -f prog4 in1 > out11 || fail=1
|
|---|
| 87 | compare_ exp-norm out11 || fail=1
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | # If the program comes before -e , silent mode is activated.
|
|---|
| 91 | sed -f prog4 -e = in1 > out12 || fail=1
|
|---|
| 92 | compare_ exp-silent out12 || fail=1
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | Exit $fail
|
|---|