-
-
Notifications
You must be signed in to change notification settings - Fork 392
Description
These two expectations are incorrect: https://github.com/ruby/spec/blob/master/core/argf/binmode_spec.rb#L15-L29
Basically, there is a file with Unix-style line breaks, and it is expecting that setting binmode
will convert these Unix-style line endings into Windows-style line endings. That does not make any sense, because it's just not what binmode
does. Per http://ruby-doc.org/core-2.0.0/ARGF.html#method-i-binmode
Puts ARGF into binary mode. Once a stream is in binary mode, it cannot be reset to non-binary mode. This option has the following effects:
- Newline conversion is disabled.
- Encoding conversion is disabled.
- Content is treated as ASCII-8BIT.
The proof is in the pudding:
C:\Users\Administrator\GitHub\spec>C:\Ruby\ruby-2.2.4-i386-mingw32\bin\ruby.exe -ve "ARGF.binmode; p ARGF.gets" C:\Users\Administrator\GitHub\spec\core\argf\fixtures\bin_file.txt
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
"test\n"
And here is the same result using ruby 1.8.7 (cause I wondered where these expectations came from, perhaps this is how it used to work on 1.8? But no.)
C:\Users\Administrator\GitHub\spec>C:\Ruby\ruby-1.8.7-p374-i386-mingw32\bin\ruby.exe -ve "ARGF.binmode; p ARGF.gets" C:\Users\Administrator\GitHub\spec\core\argf\fixtures\bin_file.txt
ruby 1.8.7 (2013-06-27 patchlevel 374) [i386-mingw32]
"test\n"
Ok, so to fix this and test ARGF.binmode
properly, we need to add another fixture - a text file (named win_file.txt
) containing Windows-style line breaks, then reading it in binmode
should give us Windows-style line breaks, and reading it without binmode
should give us Unix-style line endings:
C:\Users\Administrator\GitHub\spec>C:\Ruby\ruby-2.2.4-i386-mingw32\bin\ruby.exe -ve "ARGF.binmode; p ARGF.gets" C:\Users\Administrator\GitHub\spec\core\argf\fixtures\win_file.txt
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
"test\r\n"
C:\Users\Administrator\GitHub\spec>C:\Ruby\ruby-2.2.4-i386-mingw32\bin\ruby.exe -ve "p ARGF.gets" C:\Users\Administrator\GitHub\spec\core\argf\fixtures\win_file
.txt
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
"test\n"
@eregon unless there are any objections, I will be sending a PR for this, LMK...