From 3e5819fa1da0a2d7c924c67f2305678277accd7b Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 27 Sep 2026 07:45:54 +0900 Subject: [PATCH] Add missing definitions for IO and system standard libraries (find, pathname, pty, stringio, timeout, zlib) Add missing methods, classes, and constants for `find`, `pathname`, `pty`, `stringio`, `timeout`, and `zlib`. Note: `pstore` has been excluded as it is in `ALUMNI_STDLIBS` and planned to be removed from the rbs repo. | Ruby Method | Change | C function | |---|---|---| | `Find.prune` | Add singleton method `prune` | https://github.com/ruby/ruby/blob/v4.0.7/lib/find.rb#L86-L92 | | `Find::VERSION` | Add constant `VERSION` | https://github.com/ruby/ruby/blob/v4.0.7/lib/find.rb#L4-L6 | | `Pathname#empty?` | Add method `empty?` returning `bool` | https://github.com/ruby/ruby/blob/v4.0.7/ext/pathname/pathname.c#L1228-L1236 | | `Pathname.glob` | Add singleton method `glob` | https://github.com/ruby/ruby/blob/v4.0.7/ext/pathname/pathname.c#L1238-L1248 | | `Pathname#glob` | Add method `glob` returning `Array[Pathname]` or `Enumerator` | https://github.com/ruby/ruby/blob/v4.0.7/ext/pathname/pathname.c#L1250-L1262 | | `PTY::ChildExited` | Add exception class inheriting `RuntimeError` | https://github.com/ruby/ruby/blob/v4.0.7/ext/pty/pty.c | | `PTY::ChildExited#status` | Add method `status` returning `Process::Status` | https://github.com/ruby/ruby/blob/v4.0.7/ext/pty/pty.c | | `StringIO#length` | Add alias of `size` returning `Integer` | https://github.com/ruby/stringio/blob/master/ext/stringio/stringio.c | | `StringIO::MAX_LENGTH` | Add constant `MAX_LENGTH` | https://github.com/ruby/stringio/blob/master/ext/stringio/stringio.c | | `StringIO::VERSION` | Add constant `VERSION` | https://github.com/ruby/stringio/blob/master/ext/stringio/stringio.c | | `Timeout::Error.handle_timeout` | Add singleton method `handle_timeout` | https://github.com/ruby/timeout/blob/master/lib/timeout.rb | | `Zlib::InProgressError` | Add exception class inheriting `Zlib::Error` | https://github.com/ruby/zlib/blob/master/ext/zlib/zlib.c | --- stdlib/find/0/find.rbs | 4 ++++ stdlib/pathname/0/pathname.rbs | 20 +++++++++++++++++++ stdlib/pty/0/pty.rbs | 14 ++++++++++++++ stdlib/stringio/0/stringio.rbs | 18 +++++++++++++++++ stdlib/timeout/0/timeout.rbs | 2 ++ stdlib/zlib/0/in_progress_error.rbs | 16 +++++++++++++++ test/stdlib/Find_test.rb | 11 +++++++++++ test/stdlib/PTY_test.rb | 23 ++++++++++++++++++++++ test/stdlib/Pathname_ext_test.rb | 18 +++++++++++++++++ test/stdlib/StringIO_test.rb | 24 +++++++++++++++++++++++ test/stdlib/Timeout_test.rb | 30 ++++++++++++++++++----------- test/stdlib/Zlib_test.rb | 5 +++++ 12 files changed, 174 insertions(+), 11 deletions(-) create mode 100644 stdlib/zlib/0/in_progress_error.rbs diff --git a/stdlib/find/0/find.rbs b/stdlib/find/0/find.rbs index 624dfb10cd..92508060ef 100644 --- a/stdlib/find/0/find.rbs +++ b/stdlib/find/0/find.rbs @@ -21,6 +21,10 @@ # end # module Find + # + # The version string + # + VERSION: String # + # The version string. + # + VERSION: String + + # + # Creates a tmp directory and wraps the returned path in a Pathname object. + # + # Note that you need to require 'pathname' to use this method. + # + # See Dir.mktmpdir + # + def self.mktmpdir: () -> Pathname + | [U] () { (Pathname) -> U } -> U + # +# Thrown when PTY::check is called for a pid that represents a process that has +# exited. +# +class PTY::ChildExited < RuntimeError + # + # Returns the exit status of the child for which PTY#check raised this exception + # + def status: () -> Process::Status +end diff --git a/stdlib/stringio/0/stringio.rbs b/stdlib/stringio/0/stringio.rbs index 0492ed0d71..d760ed478f 100644 --- a/stdlib/stringio/0/stringio.rbs +++ b/stdlib/stringio/0/stringio.rbs @@ -509,6 +509,15 @@ # * #each_codepoint: reads each remaining codepoint, passing it to the block. # class StringIO + # + # The version string + # + VERSION: String + + # + # Maximum length that a StringIO instance can hold + # + MAX_LENGTH: Integer # + # Returns the number of bytes in the string in `self`: + # + # StringIO.new('hello').size # => 5 # Five 1-byte characters. + # StringIO.new('тест').size # => 8 # Four 2-byte characters. + # StringIO.new('こんにちは').size # => 15 # Five 3-byte characters. + # + alias length size + # + # Subclass of Zlib::Error. This error is raised when the zlib stream is + # currently in progress. + # + # For example: + # + # inflater = Zlib::Inflate.new + # inflater.inflate(compressed) do + # inflater.inflate(compressed) # Raises Zlib::InProgressError + # end + # + class InProgressError < Zlib::Error + end +end diff --git a/test/stdlib/Find_test.rb b/test/stdlib/Find_test.rb index a5de5796c2..b0bf243de7 100644 --- a/test/stdlib/Find_test.rb +++ b/test/stdlib/Find_test.rb @@ -1,6 +1,17 @@ require_relative "test_helper" require "find" +class FindSingletonTest < Test::Unit::TestCase + include TestHelper + + library "find" + testing "singleton(::Find)" + + def test_version + assert_const_type "String", "Find::VERSION" + end +end + class FindTest < StdlibTest target Find library "find" diff --git a/test/stdlib/PTY_test.rb b/test/stdlib/PTY_test.rb index 284bd1350e..9ac9859e6f 100644 --- a/test/stdlib/PTY_test.rb +++ b/test/stdlib/PTY_test.rb @@ -50,3 +50,26 @@ def test_spawn PTY, :spawn, "echo" do |r, w, pid| 1 end end end if defined?(PTY) + +class PTYChildExitedTest < Test::Unit::TestCase + include TestHelper + + library "pty" + testing "::PTY::ChildExited" + + def test_child_exited + assert_const_type "Class", "PTY::ChildExited" + assert_equal RuntimeError, PTY::ChildExited.superclass + end + + def test_status + _r, _w, pid = PTY.spawn("sleep 0.05") + sleep 0.1 + begin + PTY.check(pid, true) + rescue PTY::ChildExited => ex + assert_send_type "() -> ::Process::Status", + ex, :status + end + end +end if defined?(PTY) diff --git a/test/stdlib/Pathname_ext_test.rb b/test/stdlib/Pathname_ext_test.rb index d87392d641..56fc628b89 100644 --- a/test/stdlib/Pathname_ext_test.rb +++ b/test/stdlib/Pathname_ext_test.rb @@ -1,6 +1,24 @@ require_relative "test_helper" require 'pathname' +class PathnameExtSingletonTest < Test::Unit::TestCase + include TestHelper + + library 'pathname' + testing 'singleton(::Pathname)' + + def test_version + assert_const_type "String", "Pathname::VERSION" + end + + def test_mktmpdir + Pathname.mktmpdir do |dir| + assert_instance_of Pathname, dir + assert dir.directory? + end + end +end + class PathnameExtInstanceTest < Test::Unit::TestCase include TestHelper diff --git a/test/stdlib/StringIO_test.rb b/test/stdlib/StringIO_test.rb index 37121ea52b..ac1f22fd03 100644 --- a/test/stdlib/StringIO_test.rb +++ b/test/stdlib/StringIO_test.rb @@ -1,5 +1,29 @@ require_relative "test_helper" +class StringIOSingletonTest < Test::Unit::TestCase + include TestHelper + + library "stringio" + testing "singleton(::StringIO)" + + def test_constants + assert_const_type "String", "StringIO::VERSION" + assert_const_type "Integer", "StringIO::MAX_LENGTH" + end +end + +class StringIOInstanceTest < Test::Unit::TestCase + include TestHelper + + library "stringio" + testing "::StringIO" + + def test_length + assert_send_type "() -> ::Integer", + StringIO.new("hello"), :length + end +end + class StringIOTest < StdlibTest target StringIO diff --git a/test/stdlib/Timeout_test.rb b/test/stdlib/Timeout_test.rb index b8a8ddb2f7..ceb2b2d9b3 100644 --- a/test/stdlib/Timeout_test.rb +++ b/test/stdlib/Timeout_test.rb @@ -1,22 +1,30 @@ +# frozen_string_literal: true + require_relative "test_helper" require "timeout" -require "bigdecimal" -class TimeoutSingletonTest < Test::Unit::TestCase +class TimeoutTest < Test::Unit::TestCase include TestHelper library "timeout" testing "singleton(::Timeout)" + def test_version + assert_const_type "String", "Timeout::VERSION" + end + def test_timeout - proc = Proc.new { |sec| sec * sec } - assert_send_type "(::Integer sec) { (::Integer sec) -> ::Integer } -> ::Integer", - Timeout, :timeout, 5, &proc - assert_send_type "(::Float sec) { (::Float sec) -> ::Float } -> ::Float", - Timeout, :timeout, 1.2, &proc - assert_send_type "(::Rational sec) { (::Rational sec) -> ::Rational } -> ::Rational", - Timeout, :timeout, Rational(5, 3), &proc - assert_send_type "(::BigDecimal sec) { (::BigDecimal sec) -> ::BigDecimal } -> ::BigDecimal", - Timeout, :timeout, BigDecimal("1.123456789123456789"), &proc + assert_send_type "[T] (Numeric?, ?singleton(Exception), ?String) { (Numeric) -> T } -> T", + Timeout, :timeout, 1 do + 42 + end + end + + def test_handle_timeout + res = Timeout::Error.handle_timeout("msg") do |exc| + assert_instance_of Timeout::ExitException, exc + :ok + end + assert_equal :ok, res end end diff --git a/test/stdlib/Zlib_test.rb b/test/stdlib/Zlib_test.rb index d7b35277de..345e83b1ef 100644 --- a/test/stdlib/Zlib_test.rb +++ b/test/stdlib/Zlib_test.rb @@ -75,5 +75,10 @@ def test_zlib_version assert_send_type "() -> ::String", Zlib, :zlib_version end + + def test_in_progress_error + assert_const_type "Class", "Zlib::InProgressError" + assert_equal Zlib::Error, Zlib::InProgressError.superclass + end end