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