1 | #!/bin/sh
|
---|
2 | # Test CR/LF behaviour on platforms which support O_BINARY file mode
|
---|
3 | # (i.e. differentiates between text and binary files).
|
---|
4 |
|
---|
5 | # Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
---|
6 |
|
---|
7 | # This program is free software: you can redistribute it and/or modify
|
---|
8 | # it under the terms of the GNU General Public License as published by
|
---|
9 | # the Free Software Foundation, either version 3 of the License, or
|
---|
10 | # (at your option) any later version.
|
---|
11 |
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 |
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
---|
19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
---|
20 | print_ver_ sed
|
---|
21 |
|
---|
22 | # Test if O_TEXT is enabled by default (i.e. lines terminated with "\r\n").
|
---|
23 | # If not, skip the test.
|
---|
24 | printf a | sed cb > out1 \
|
---|
25 | || framework_failure_ "failed to run sed 'cb'"
|
---|
26 | size=$(LC_ALL=C wc -c < out1 | tr -d '[:space:]') \
|
---|
27 | || framework_failure_ "failed to check size of 'out1'"
|
---|
28 | case $size in
|
---|
29 | 2) skip_ "platform does not enable O_TEXT by default" ;;
|
---|
30 | 3) ;;
|
---|
31 | *) framework_failure_ "unexpected size '$size'" ;;
|
---|
32 | esac
|
---|
33 |
|
---|
34 |
|
---|
35 | # files with "\r\n" and with just "\n"
|
---|
36 | printf 'a\015\12' > inT || framework_failure_
|
---|
37 | printf 'a\12' > inB || framework_failure_
|
---|
38 | cp inT inplaceT1 || framework_failure_
|
---|
39 | cp inT inplaceT2 || framework_failure_
|
---|
40 | cp inT inplaceT3 || framework_failure_
|
---|
41 | cp inB inplaceB1 || framework_failure_
|
---|
42 | cp inB inplaceB2 || framework_failure_
|
---|
43 |
|
---|
44 | printf 'z\015\12' > expT || framework_failure_
|
---|
45 | printf 'z\12' > expB || framework_failure_
|
---|
46 |
|
---|
47 |
|
---|
48 | # First round of tests. These all seem equivalent,
|
---|
49 | # but older seds had sublte implementation differences
|
---|
50 | # between STDIN and explicit input files (bug#25459).
|
---|
51 | # Similarly, also test --inplace type output.
|
---|
52 | sed 's/a/z/' inT > out1 || fail=1
|
---|
53 | sed 's/a/z/' < inT > out2 || fail=1
|
---|
54 | cat inT | sed 's/a/z/' > out3 || fail=1
|
---|
55 | sed -i 's/a/z/' inplaceT1 || fail=1
|
---|
56 |
|
---|
57 | compare_ expT out1 || fail=1
|
---|
58 | compare_ expT out2 || fail=1
|
---|
59 | compare_ expT out3 || fail=1
|
---|
60 | compare_ expT inplaceT1 || fail=1
|
---|
61 |
|
---|
62 | # Input file with only "\n". Output should contain "\r\n".
|
---|
63 | sed 's/a/z/' inB > out4 || fail=1
|
---|
64 | sed 's/a/z/' < inB > out5 || fail=1
|
---|
65 | cat inB | sed 's/a/z/' > out6 || fail=1
|
---|
66 | sed -i 's/a/z/' inplaceB1 || fail=1
|
---|
67 |
|
---|
68 | compare_ expT out4 || fail=1
|
---|
69 | compare_ expT out5 || fail=1
|
---|
70 | compare_ expT out6 || fail=1
|
---|
71 | compare_ expT inplaceB1 || fail=1
|
---|
72 |
|
---|
73 | # Input file with only "\n", with "sed -b" should output only "\n".
|
---|
74 | sed -b 's/a/z/' inB > out7 || fail=1
|
---|
75 | sed -b 's/a/z/' < inB > out8 || fail=1
|
---|
76 | cat inB | sed -b 's/a/z/' > out9 || fail=1
|
---|
77 | sed -b -i 's/a/z/' inplaceB2 || fail=1
|
---|
78 |
|
---|
79 | compare_ expB out7 || fail=1
|
---|
80 | compare_ expB out8 || fail=1
|
---|
81 | compare_ expB out9 || fail=1
|
---|
82 | compare_ expB inplaceB2 || fail=1
|
---|
83 |
|
---|
84 | # End-of-line tests on input file with "\r\n".
|
---|
85 | # In TEXT mode, "\r\n" is end-of-line, the "y" character will be added prior to
|
---|
86 | # it. In BINARY mode, "\r" is just another character - the "y" character will
|
---|
87 | # be added after the "\r".
|
---|
88 | printf 'ay\015\012' > expTeol || framework_failure_
|
---|
89 | printf 'a\015y\012' > expBeol || framework_failure_
|
---|
90 |
|
---|
91 | sed 's/$/y/' inT > out10 || fail=1
|
---|
92 | sed 's/$/y/' < inT > out11 || fail=1
|
---|
93 | cat inT | sed 's/$/y/' > out12 || fail=1
|
---|
94 | sed -i 's/$/y/' inplaceT2 || fail=1
|
---|
95 |
|
---|
96 | sed -b 's/$/y/' inT > out13 || fail=1
|
---|
97 | sed -b 's/$/y/' < inT > out14 || fail=1
|
---|
98 | cat inT | sed -b 's/$/y/' > out15 || fail=1
|
---|
99 | sed -i -b 's/$/y/' inplaceT3 || fail=1
|
---|
100 |
|
---|
101 | compare_ expTeol out10 || fail=1
|
---|
102 | compare_ expTeol out11 || fail=1
|
---|
103 | compare_ expTeol out12 || fail=1
|
---|
104 | compare_ expTeol inplaceT2 || fail=1
|
---|
105 |
|
---|
106 | compare_ expBeol out13 || fail=1
|
---|
107 | compare_ expBeol out14 || fail=1
|
---|
108 | compare_ expBeol out15 || fail=1
|
---|
109 | compare_ expBeol inplaceT3 || fail=1
|
---|
110 |
|
---|
111 | Exit $fail
|
---|