Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/find/0/find.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# end
#
module Find
# <!-- rdoc-file=lib/find.rb -->
# The version string
#
VERSION: String
# <!--
# rdoc-file=lib/find.rb
# - find(*paths, ignore_error: true) { |path| ... }
Expand Down
20 changes: 20 additions & 0 deletions stdlib/pathname/0/pathname.rbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
%a{annotate:rdoc:skip}
class Pathname
# <!-- rdoc-file=pathname_builtin.rb -->
# The version string.
#
VERSION: String

# <!--
# rdoc-file=lib/pathname.rb
# - mktmpdir() { |dir| ... }
# -->
# 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

# <!--
# rdoc-file=lib/pathname.rb
# - find(ignore_error: true) { |pathname| ... }
Expand Down Expand Up @@ -33,4 +51,6 @@ class Pathname
# See FileUtils.rm_rf
#
def rmtree: () -> self

def path: () -> String
end
14 changes: 14 additions & 0 deletions stdlib/pty/0/pty.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,17 @@ module PTY
def self.spawn: (*String command) -> [ IO, IO, Integer ]
| (*String command) { ([ IO, IO, Integer ]) -> void } -> void
end

# <!-- rdoc-file=ext/pty/pty.c -->
# Thrown when PTY::check is called for a pid that represents a process that has
# exited.
#
class PTY::ChildExited < RuntimeError
# <!--
# rdoc-file=ext/pty/pty.c
# - status()
# -->
# Returns the exit status of the child for which PTY#check raised this exception
#
def status: () -> Process::Status
end
18 changes: 18 additions & 0 deletions stdlib/stringio/0/stringio.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@
# * #each_codepoint: reads each remaining codepoint, passing it to the block.
#
class StringIO
# <!-- rdoc-file=ext/stringio/stringio.c -->
# The version string
#
VERSION: String

# <!-- rdoc-file=ext/stringio/stringio.c -->
# Maximum length that a StringIO instance can hold
#
MAX_LENGTH: Integer
# <!--
# rdoc-file=ext/stringio/stringio.c
# - StringIO.new(string = '', mode = 'r+') -> new_stringio
Expand Down Expand Up @@ -1218,6 +1227,15 @@ class StringIO
#
def isatty: () -> bool

# <!-- rdoc-file=ext/stringio/stringio.c -->
# 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

# <!--
# rdoc-file=ext/stringio/stringio.c
# - lineno -> current_line_number
Expand Down
2 changes: 2 additions & 0 deletions stdlib/timeout/0/timeout.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ end
# Raised by Timeout.timeout when the block times out.
#
class Timeout::Error < RuntimeError
def self.handle_timeout: [T] (String? message) { (Timeout::ExitException) -> T } -> T

attr_reader thread: Thread?
end

Expand Down
16 changes: 16 additions & 0 deletions stdlib/zlib/0/in_progress_error.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%a{annotate:rdoc:skip}
module Zlib
# <!-- rdoc-file=ext/zlib/zlib.c -->
# 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
11 changes: 11 additions & 0 deletions test/stdlib/Find_test.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
23 changes: 23 additions & 0 deletions test/stdlib/PTY_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assert_const_type to test constants.

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)
18 changes: 18 additions & 0 deletions test/stdlib/Pathname_ext_test.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
24 changes: 24 additions & 0 deletions test/stdlib/StringIO_test.rb
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +9 to 12

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assert_const_type to test constants.

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

Expand Down
30 changes: 19 additions & 11 deletions test/stdlib/Timeout_test.rb
Original file line number Diff line number Diff line change
@@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assert_const_type for testing constant types.

:ok
end
assert_equal :ok, res

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assert_send_type to test the method's type.

end
end
5 changes: 5 additions & 0 deletions test/stdlib/Zlib_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assert_const_type for testing constant types.

end
end

Loading