diff options
author | Ron Yorston <rmy@pobox.com> | 2023-08-06 12:40:17 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-08-06 12:40:17 +0100 |
commit | 0342f258f74bde329cc98733a3b22196ca1b1bdb (patch) | |
tree | 73a58db17072aef8d3ef26b32d50e45c58dd5167 /testsuite | |
parent | 16a2532c519bac11d456f7c71f06d64385f66ed3 (diff) | |
download | busybox-w32-0342f258f74bde329cc98733a3b22196ca1b1bdb.tar.gz busybox-w32-0342f258f74bde329cc98733a3b22196ca1b1bdb.tar.bz2 busybox-w32-0342f258f74bde329cc98733a3b22196ca1b1bdb.zip |
diff: more changes to --binary
The changes introduced to support the --binary option gave incorrect
results when comparing files with CRLF line endings *without* the
--binary option present.
The code needs to keep track of the position within the file and is
confused by text mode.
As an alternative solution, always use binary mode but skip the CR
of a CRLF pair when the --binary option isn't used. This gives
results matching GNU diff when comparing files with matching line
endings, with or without --binary. When line endings differ the
results aren't always the same.
Costs 32 bytes in the 32-bit build, saves 16 in 64-bit.
(GitHub issue #348)
Diffstat (limited to 'testsuite')
-rwxr-xr-x | testsuite/diff.tests | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/testsuite/diff.tests b/testsuite/diff.tests index 0ced0f248..ee0567a80 100755 --- a/testsuite/diff.tests +++ b/testsuite/diff.tests | |||
@@ -123,6 +123,69 @@ testing "diff always takes context from old file" \ | |||
123 | "abc\na c\ndef\n" \ | 123 | "abc\na c\ndef\n" \ |
124 | "a c\n" | 124 | "a c\n" |
125 | 125 | ||
126 | optional PLATFORM_MINGW32 LONG_OPTS | ||
127 | testing "diff LF line endings" \ | ||
128 | 'diff -u - input' \ | ||
129 | "\ | ||
130 | --- - | ||
131 | +++ input | ||
132 | @@ -1,4 +1,4 @@ | ||
133 | a | ||
134 | b | ||
135 | +c | ||
136 | d | ||
137 | -e | ||
138 | " \ | ||
139 | "a\nb\nc\nd\n" \ | ||
140 | "a\nb\nd\ne\n" | ||
141 | |||
142 | testing "diff --binary LF line endings" \ | ||
143 | 'diff --binary -u - input' \ | ||
144 | "\ | ||
145 | --- - | ||
146 | +++ input | ||
147 | @@ -1,4 +1,4 @@ | ||
148 | a | ||
149 | b | ||
150 | +c | ||
151 | d | ||
152 | -e | ||
153 | " \ | ||
154 | "a\nb\nc\nd\n" \ | ||
155 | "a\nb\nd\ne\n" | ||
156 | |||
157 | testing "diff CRLF line endings" \ | ||
158 | 'diff -u - input' \ | ||
159 | "\ | ||
160 | --- - | ||
161 | +++ input | ||
162 | @@ -1,4 +1,4 @@ | ||
163 | a | ||
164 | b | ||
165 | +c | ||
166 | d | ||
167 | -e | ||
168 | " \ | ||
169 | "a\r\nb\r\nc\r\nd\r\n" \ | ||
170 | "a\r\nb\r\nd\r\ne\r\n" | ||
171 | |||
172 | testing "diff --binary CRLF line endings" \ | ||
173 | 'diff --binary -u - input' \ | ||
174 | "\ | ||
175 | --- - | ||
176 | +++ input | ||
177 | @@ -1,4 +1,4 @@ | ||
178 | a | ||
179 | b | ||
180 | +c | ||
181 | d | ||
182 | -e | ||
183 | " \ | ||
184 | "a\r\nb\r\nc\r\nd\r\n" \ | ||
185 | "a\r\nb\r\nd\r\ne\r\n" | ||
186 | |||
187 | SKIP= | ||
188 | |||
126 | # testing "test name" "commands" "expected result" "file input" "stdin" | 189 | # testing "test name" "commands" "expected result" "file input" "stdin" |
127 | 190 | ||
128 | # clean up | 191 | # clean up |