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