VirtualBox

source: kBuild/trunk/src/sed/testsuite/obinary.sh@ 3613

Last change on this file since 3613 was 3613, checked in by bird, 7 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 .)

  • Property svn:executable set to *
File size: 3.8 KB
Line 
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
20print_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.
24printf a | sed cb > out1 \
25 || framework_failure_ "failed to run sed 'cb'"
26size=$(LC_ALL=C wc -c < out1 | tr -d '[:space:]') \
27 || framework_failure_ "failed to check size of 'out1'"
28case $size in
29 2) skip_ "platform does not enable O_TEXT by default" ;;
30 3) ;;
31 *) framework_failure_ "unexpected size '$size'" ;;
32esac
33
34
35# files with "\r\n" and with just "\n"
36printf 'a\015\12' > inT || framework_failure_
37printf 'a\12' > inB || framework_failure_
38cp inT inplaceT1 || framework_failure_
39cp inT inplaceT2 || framework_failure_
40cp inT inplaceT3 || framework_failure_
41cp inB inplaceB1 || framework_failure_
42cp inB inplaceB2 || framework_failure_
43
44printf 'z\015\12' > expT || framework_failure_
45printf '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.
52sed 's/a/z/' inT > out1 || fail=1
53sed 's/a/z/' < inT > out2 || fail=1
54cat inT | sed 's/a/z/' > out3 || fail=1
55sed -i 's/a/z/' inplaceT1 || fail=1
56
57compare_ expT out1 || fail=1
58compare_ expT out2 || fail=1
59compare_ expT out3 || fail=1
60compare_ expT inplaceT1 || fail=1
61
62# Input file with only "\n". Output should contain "\r\n".
63sed 's/a/z/' inB > out4 || fail=1
64sed 's/a/z/' < inB > out5 || fail=1
65cat inB | sed 's/a/z/' > out6 || fail=1
66sed -i 's/a/z/' inplaceB1 || fail=1
67
68compare_ expT out4 || fail=1
69compare_ expT out5 || fail=1
70compare_ expT out6 || fail=1
71compare_ expT inplaceB1 || fail=1
72
73# Input file with only "\n", with "sed -b" should output only "\n".
74sed -b 's/a/z/' inB > out7 || fail=1
75sed -b 's/a/z/' < inB > out8 || fail=1
76cat inB | sed -b 's/a/z/' > out9 || fail=1
77sed -b -i 's/a/z/' inplaceB2 || fail=1
78
79compare_ expB out7 || fail=1
80compare_ expB out8 || fail=1
81compare_ expB out9 || fail=1
82compare_ 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".
88printf 'ay\015\012' > expTeol || framework_failure_
89printf 'a\015y\012' > expBeol || framework_failure_
90
91sed 's/$/y/' inT > out10 || fail=1
92sed 's/$/y/' < inT > out11 || fail=1
93cat inT | sed 's/$/y/' > out12 || fail=1
94sed -i 's/$/y/' inplaceT2 || fail=1
95
96sed -b 's/$/y/' inT > out13 || fail=1
97sed -b 's/$/y/' < inT > out14 || fail=1
98cat inT | sed -b 's/$/y/' > out15 || fail=1
99sed -i -b 's/$/y/' inplaceT3 || fail=1
100
101compare_ expTeol out10 || fail=1
102compare_ expTeol out11 || fail=1
103compare_ expTeol out12 || fail=1
104compare_ expTeol inplaceT2 || fail=1
105
106compare_ expBeol out13 || fail=1
107compare_ expBeol out14 || fail=1
108compare_ expBeol out15 || fail=1
109compare_ expBeol inplaceT3 || fail=1
110
111Exit $fail
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette