Add and update specs for IO methods#1384
Open
javanthropus wants to merge 16 commits into
Open
Conversation
Verify that calling IO#binmode on an IO stream disables any active newline conversion (such as universal newline mode) when reading data.
- Add spec for reading a byte with IO#getbyte after calling ungetc on a stream without character conversion.
- Add spec verifying that calling IO#getbyte after ungetc on a stream with character conversion enabled raises IOError ("byte oriented read for character buffered IO").
- Add spec verifying IO#internal_encoding returns nil when external encoding is BINARY. - Add Ruby version-specific specs for setting internal encoding when external encoding is BINARY: Ruby < 3.3 returns the assigned value, while Ruby >= 3.3 ignores the internal encoding and returns nil because binary mode does not support internal character conversion.
Verify that calling IO#pwrite with a negative offset raises Errno::EINVAL.
- Add spec for CRuby Bug #18421 (fixed in 3.0.4) ensuring IO#read_nonblock(0, buffer) clears the output buffer and returns it empty when length is 0.
- Update IOError expectation message check when read_nonblock is called after ungetc with character conversion enabled ("byte oriented read for character buffered IO").
- Add specs verifying that IO#read successfully reads bytes after calling ungetc on streams without character conversion.
- Add specs across various mode combinations verifying that IO#read raises IOError ("byte oriented read for character buffered IO") after ungetc when character conversion is enabled.
- Add spec for IO#readbyte after ungetc on a stream without character conversion.
- Add spec verifying that IO#readbyte raises IOError ("byte oriented read for character buffered IO") after ungetc when character conversion is enabled.
…er conversion
Verify that calling IO#readpartial after ungetc on an IO stream with character conversion enabled raises IOError ("byte oriented read for character buffered IO").
- Add spec verifying IO#reopen raises ArgumentError when passed excess arguments.
- Add specs for reopening an IO with a String path, verifying that the newly opened stream preserves the capabilities and restrictions of the original open mode ('r', 'w', 'r+', 'a').
When ungetc pushes characters into the IO stream's character buffer, calling IO#seek should discard that buffer before seeking to the target offset. This adds a spec for CRuby Bug #20919 fixed in Ruby 3.4.
- Refactor `IO#set_encoding when passed nil, nil` mode blocks ('r', 'rb', 'r+', 'w', 'w+', 'a', 'a+') to reuse shared behaviors `:io_set_encoding_common`, `:io_set_encoding_readonly`, and `:io_set_encoding_write`.
- Add spec for passing "-" as second argument to reset internal_encoding to nil.
- Add validation specs for non-ASCII compatible arguments, nil first argument with non-nil second argument, and invalid newline decorator option.
- Add specs for ASCII-incompatible encodings (handling with binmode, character conversion, write-only streams, and error raising on readable streams).
- Add Ruby 3.2+ spec for newline decorator in binary mode.
- Add Ruby 3.3+ specs for setting internal encoding when second argument is nil.
- Add spec for encoding names containing null bytes.
- Update IOError message expectation when sysread is called after buffered reads.
- Add spec verifying that calling sysread on an IO with a non-empty character buffer raises IOError ("byte oriented read for character buffered IO").
- Update IOError message expectation when sysseek is called after buffered reads.
- Add spec verifying that calling sysseek on an IO with a non-empty character buffer raises IOError ("sysseek for buffered IO").
- Refactor pipe test fixture setup to use before/after blocks for clean tear-down. - Add specs for Ruby < 3.2 verifying that non-blocking syswrite on a full pipe raises Errno::EAGAIN (or Errno::EWOULDBLOCK on Windows) instead of returning partial bytes.
- Add spec for IO#write writing binary data when external encoding is ASCII-8BIT. - Add specs verifying that IO#write performs newline conversion on binary data when no encoding or ASCII-8BIT encoding is specified alongside newline conversion options.
The implementation on Windows does not error in this case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds missing specs, updates error message expectations, refactors redundant test fixtures, and adds coverage for edge cases and version-specific behaviors across
core/io.Summary of Changes
IO#binmode: Added spec verifying that newline conversion is disabled when reading in binary mode.IO#getbyte,IO#read,IO#readbyte,IO#readpartial: Added specs for reading afterungetc, including specs verifying that byte-oriented methods raiseIOError("byte oriented read for character buffered IO") when character conversion is enabled.IO#internal_encoding: Added specs forBINARYexternal encoding, including Ruby 3.3+ behavior where internal encoding assignments are ignored.IO#pwrite: Added spec verifyingErrno::EINVALis raised on negative offsets.IO#read_nonblock: Added spec for CRuby Bug #18421 (fixed in 3.0.4) ensuring 0-length reads clear the buffer, and updatedIOErrorexpectation.IO#reopen: Added specs for excess argument validation and mode preservation (r,w,r+,a) when reopening with a String path.IO#seek: Added spec for CRuby Bug #20919 (fixed in 3.4) verifying character buffer is cleared afterungetc.IO#set_encoding: Refactoredset_encoding nil, nilmode blocks to reuse shared behaviors. Added specs for"-"internal encoding, ASCII compatibility validation, newline options, ASCII-incompatible encodings, and Ruby 3.2+/3.3+ version specific behaviors.IO#sysread,IO#sysseek: UpdatedIOErrorexpectation messages for buffered IO and added specs for non-empty character buffers.IO#syswrite: Refactored pipe test setup and added specs for non-blocking write behavior on full pipes (raisingErrno::EAGAIN/Errno::EWOULDBLOCKon Ruby < 3.2).IO#write: Added specs for writing binary data withASCII-8BITexternal encoding and newline conversion.Verification
Ran specs via
mspec core/io/:103 files, 1582 examples, 2459 expectations, 0 failures, 0 errors, 0 tagged