1 | #!/bin/sh
|
---|
2 | # Test execution less-common cases
|
---|
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 | #
|
---|
22 | # 'D' when pattern-space has no newline (act like 'd')
|
---|
23 | #
|
---|
24 | echo a | sed 1D > out1 || fail=1
|
---|
25 | compare_ /dev/null out1 || fail=1
|
---|
26 |
|
---|
27 | #
|
---|
28 | # s///e with a command that returns zero output
|
---|
29 | #
|
---|
30 | printf "\n" > exp2 || framework_failure_
|
---|
31 | echo "" | sed '1etrue' > out2 || fail=1
|
---|
32 | compare_ exp2 out2 || fail=1
|
---|
33 |
|
---|
34 |
|
---|
35 | #
|
---|
36 | # plain 'e' with a command that returns non-delimted output
|
---|
37 | #
|
---|
38 | printf "a\n" > exp3 || framework_failure_
|
---|
39 | echo "printf a" | sed '1e' > out3 || fail=1
|
---|
40 | compare_ exp3 out3 || fail=1
|
---|
41 |
|
---|
42 | #
|
---|
43 | # plain 'e' with a command that returns delimted '\n' output
|
---|
44 | # (implementation note: the delimiter is first chomp'd)
|
---|
45 | printf "a\n" > exp4 || framework_failure_
|
---|
46 | echo "echo a" | sed '1e' > out4 || fail=1
|
---|
47 | compare_ exp4 out4 || fail=1
|
---|
48 |
|
---|
49 | #
|
---|
50 | # e with a command that returns delimted '\0' output
|
---|
51 | #
|
---|
52 | printf "b\0" > exp5 || framework_failure_
|
---|
53 | # This input file contains the shell command to be excuted:
|
---|
54 | printf 'cat exp5' > in5 || framework_failure_
|
---|
55 | sed -z '1e' <in5 > out5 || fail=1
|
---|
56 | compare_ exp5 out5 || fail=1
|
---|
57 |
|
---|
58 | if test "$fail" -eq 1 ; then
|
---|
59 | od -tx1c exp5
|
---|
60 | od -tx1c out5
|
---|
61 | fi
|
---|
62 |
|
---|
63 | #
|
---|
64 | # 'P' command, with and without '\n' in the pattern space
|
---|
65 | #
|
---|
66 | echo a > in6 || framework_failure_
|
---|
67 | printf "%s\n" a b | sed -n 'N;P' > out6 || fail=1
|
---|
68 | compare_ in6 out6 || fail=1
|
---|
69 |
|
---|
70 | printf "%s\n" a | sed -n 'P' > out7 || fail=1
|
---|
71 | compare_ in6 out7 || fail=1
|
---|
72 |
|
---|
73 | #
|
---|
74 | # 'Q' with exit code
|
---|
75 | #
|
---|
76 | echo a > in7 || framework_failure_
|
---|
77 | returns_ 42 sed '1Q42' in7 || fail=1
|
---|
78 |
|
---|
79 | #
|
---|
80 | # 'r' without a filename (silently ignored)
|
---|
81 | #
|
---|
82 | echo c > in8 || framework_failure_
|
---|
83 | sed 'rfoo.bar' in8 > out8 || fail=1
|
---|
84 | compare_ in8 out8 || fail=1
|
---|
85 |
|
---|
86 | #
|
---|
87 | # 'W' without a filename (silently ignored)
|
---|
88 | #
|
---|
89 | echo d > in9 || framework_failure_
|
---|
90 | sed 'Wfoo1' in9 > out9 || fail=1
|
---|
91 | compare_ in9 out9 || fail=1
|
---|
92 |
|
---|
93 | #
|
---|
94 | # 'W', with and without '\n' in pattern space
|
---|
95 | #
|
---|
96 |
|
---|
97 | # pattern-space with '\n', only 'a' should be written
|
---|
98 | printf "%s\n" a b > in10 || framework_failure_
|
---|
99 | echo a > a || framework_failure_
|
---|
100 | sed 'N;Ww1.txt' in10 > out10 || fail=1
|
---|
101 | compare_ a w1.txt || fail=1
|
---|
102 | compare_ in10 out10 || fail=1
|
---|
103 |
|
---|
104 | # pattern-space without '\n', entire pattern-space ('a') should be written
|
---|
105 | sed 'Ww2.txt' a > out11 || fail=1
|
---|
106 | compare_ a out11 || fail=1
|
---|
107 | compare_ a w2.txt || fail=1
|
---|
108 |
|
---|
109 |
|
---|
110 | #
|
---|
111 | # 'T' command
|
---|
112 | #
|
---|
113 |
|
---|
114 | # Unsuccessful substitute, 'T' jumps to 'skip'.
|
---|
115 | echo a | sed -n 's/X/Y/ ; Tskip ; Q42 ; :skip' || fail=1
|
---|
116 |
|
---|
117 | # Successful substitute, 'T' does not jumps to 'skip', sed exits with code 42.
|
---|
118 | echo a | returns_ 42 sed -n 's/a/Y/ ; Tskip ; Q42 ; :skip' || fail=1
|
---|
119 |
|
---|
120 |
|
---|
121 | #
|
---|
122 | # 'F' command
|
---|
123 | #
|
---|
124 | echo a > in12 || framework_failure_
|
---|
125 | printf "%s\n" in12 a > exp12 || framework_failure_
|
---|
126 | sed F in12 > out12 || fail=1
|
---|
127 | compare_ exp12 out12 || fail=1
|
---|
128 |
|
---|
129 | # 'F' with multiple files
|
---|
130 | echo b > in13 || framework_failure_
|
---|
131 | echo c > in14 || framework_failure_
|
---|
132 | printf "%s\n" in12 a in13 b in14 c > exp14 || framework_failure_
|
---|
133 | sed F in12 in13 in14 > out14 || fail=1
|
---|
134 | compare_ exp14 out14 || fail=1
|
---|
135 |
|
---|
136 | # 'F' with stdin
|
---|
137 | printf "%s\n" - a > exp15 || framework_failure_
|
---|
138 | sed F < in12 > out15 || fail=1
|
---|
139 | compare_ exp15 out15 || fail=1
|
---|
140 |
|
---|
141 |
|
---|
142 | Exit $fail
|
---|