source: trunk/src/sed/testsuite/execute-tests.sh@ 3613

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