Skip to content

Commit 4de713c

Browse files
ksssclaude
andcommitted
Add stdlib signature tests for #2967
PR #2967 で更新された core/stdlib の signature に対する runtime signature test を追加する。 - IO#pathconf — pipe + Etc::PC_PIPE_BUF で検証 - StringIO singleton: open (non-block / block 両形) - StringIO instance: pread, read_nonblock, write_nonblock, sysread, ungetc, fcntl (NotImplementedError), fsync, internal_encoding, external_encoding, set_encoding_by_bom - Etc::Group.each / Etc::Passwd.each の block + Enumerator overload - Etc::Passwd の age/comment/quota (member 存在で guard) read_nonblock / write_nonblock の `exception:` キーワードは true/false のリテラルに展開して assertion を分けた。 `exception: false` は empty 入力で nil を返す分岐があるため。 Digest::Class の変更は raap で別途検証されているため test/stdlib/digest には手を入れていない。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 88597ed commit 4de713c

3 files changed

Lines changed: 162 additions & 0 deletions

File tree

test/stdlib/Etc_test.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,68 @@ def test_uname
111111
Etc, :uname
112112
end
113113
end
114+
115+
class EtcGroupSingletonTest < Test::Unit::TestCase
116+
include TestHelper
117+
118+
library "etc"
119+
testing "singleton(::Etc::Group)"
120+
121+
def test_each
122+
assert_send_type "() { (::Etc::Group) -> void } -> singleton(::Etc::Group)",
123+
Etc::Group, :each do |_g| end
124+
assert_send_type "() -> ::Enumerator[::Etc::Group]",
125+
Etc::Group, :each
126+
end
127+
end
128+
129+
class EtcPasswdSingletonTest < Test::Unit::TestCase
130+
include TestHelper
131+
132+
library "etc"
133+
testing "singleton(::Etc::Passwd)"
134+
135+
def test_each
136+
assert_send_type "() { (::Etc::Passwd) -> void } -> singleton(::Etc::Passwd)",
137+
Etc::Passwd, :each do |_u| end
138+
assert_send_type "() -> ::Enumerator[::Etc::Passwd]",
139+
Etc::Passwd, :each
140+
end
141+
end
142+
143+
class EtcPasswdInstanceTest < Test::Unit::TestCase
144+
include TestHelper
145+
146+
library "etc"
147+
testing "::Etc::Passwd"
148+
149+
def test_age
150+
omit "no age member on this platform" unless Etc::Passwd.members.include?(:age)
151+
pw = Etc.getpwuid
152+
153+
assert_send_type "() -> ::Integer",
154+
pw, :age
155+
assert_send_type "(::Integer) -> void",
156+
pw, :age=, pw.age
157+
end
158+
159+
def test_comment
160+
omit "no comment member on this platform" unless Etc::Passwd.members.include?(:comment)
161+
pw = Etc.getpwuid
162+
163+
assert_send_type "() -> ::String",
164+
pw, :comment
165+
assert_send_type "(::String) -> void",
166+
pw, :comment=, pw.comment
167+
end
168+
169+
def test_quota
170+
omit "no quota member on this platform" unless Etc::Passwd.members.include?(:quota)
171+
pw = Etc.getpwuid
172+
173+
assert_send_type "() -> ::Integer",
174+
pw, :quota
175+
assert_send_type "(::Integer) -> void",
176+
pw, :quota=, pw.quota
177+
end
178+
end

test/stdlib/IO_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative "test_helper"
22
require 'tempfile'
3+
require 'etc'
34

45
require "io/wait"
56

@@ -227,6 +228,15 @@ def test_append_symbol
227228
end
228229
end
229230

231+
def test_pathconf
232+
IO.pipe do |r, w|
233+
assert_send_type "(Integer) -> Integer",
234+
w, :pathconf, Etc::PC_PIPE_BUF
235+
end
236+
rescue NotImplementedError
237+
omit "Not implemented"
238+
end
239+
230240
def test_advise
231241
IO.open(IO.sysopen(File.expand_path(__FILE__))) do |io|
232242
assert_send_type "(Symbol) -> nil",

test/stdlib/StringIO_test.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ def test_gets
3939
end
4040
end
4141

42+
class StringIOSingletonTest < Test::Unit::TestCase
43+
include TestHelper
44+
45+
testing 'singleton(::StringIO)'
46+
47+
def test_open
48+
assert_send_type "() -> ::StringIO",
49+
StringIO, :open
50+
assert_send_type "(::String) -> ::StringIO",
51+
StringIO, :open, "abc"
52+
assert_send_type "(::String, ::String) -> ::StringIO",
53+
StringIO, :open, "abc", "r"
54+
assert_send_type "() { (::StringIO) -> ::Integer } -> ::Integer",
55+
StringIO, :open do |io| io.write("a") end
56+
end
57+
end
58+
4259
class StringIOTypeTest < Test::Unit::TestCase
4360
include TestHelper
4461

@@ -85,4 +102,74 @@ def test_readlines
85102
assert_send_type "(::String sep, ::Integer limit, chomp: boolish) -> ::Array[::String]",
86103
StringIO.new("\n"), :readlines, "\n", 1, chomp: true
87104
end
105+
106+
def test_pread
107+
assert_send_type "(Integer, Integer) -> String",
108+
StringIO.new("abcdef"), :pread, 3, 0
109+
assert_send_type "(Integer, Integer, String) -> String",
110+
StringIO.new("abcdef"), :pread, 3, 0, +"buf"
111+
end
112+
113+
def test_read_nonblock
114+
assert_send_type "(int) -> String",
115+
StringIO.new("abc"), :read_nonblock, 2
116+
assert_send_type "(int, string) -> String",
117+
StringIO.new("abc"), :read_nonblock, 2, +"buf"
118+
assert_send_type "(int, exception: true) -> String",
119+
StringIO.new("abc"), :read_nonblock, 2, exception: true
120+
assert_send_type "(int, exception: false) -> String",
121+
StringIO.new("abc"), :read_nonblock, 2, exception: false
122+
assert_send_type "(int, exception: false) -> nil",
123+
StringIO.new(""), :read_nonblock, 2, exception: false
124+
end
125+
126+
def test_write_nonblock
127+
assert_send_type "(_ToS) -> Integer",
128+
StringIO.new(+""), :write_nonblock, "abc"
129+
assert_send_type "(_ToS, exception: true) -> Integer",
130+
StringIO.new(+""), :write_nonblock, "abc", exception: true
131+
assert_send_type "(_ToS, exception: false) -> Integer",
132+
StringIO.new(+""), :write_nonblock, "abc", exception: false
133+
end
134+
135+
def test_sysread
136+
assert_send_type "(Integer) -> String",
137+
StringIO.new("abc"), :sysread, 2
138+
assert_send_type "(Integer, String) -> String",
139+
StringIO.new("abc"), :sysread, 2, +"buf"
140+
end
141+
142+
def test_ungetc
143+
assert_send_type "(String) -> nil",
144+
StringIO.new(+"abc"), :ungetc, "x"
145+
assert_send_type "(Integer) -> nil",
146+
StringIO.new(+"abc"), :ungetc, 65
147+
end
148+
149+
def test_set_encoding_by_bom
150+
assert_send_type "() -> Encoding",
151+
StringIO.new("\u{FEFF}abc"), :set_encoding_by_bom
152+
assert_send_type "() -> nil",
153+
StringIO.new("abc"), :set_encoding_by_bom
154+
end
155+
156+
def test_fcntl
157+
assert_send_type_error "(*untyped) -> bot", NotImplementedError,
158+
StringIO.new("abc"), :fcntl, 1, 1
159+
end
160+
161+
def test_fsync
162+
assert_send_type "() -> Integer",
163+
StringIO.new("abc"), :fsync
164+
end
165+
166+
def test_internal_encoding
167+
assert_send_type "() -> nil",
168+
StringIO.new("abc"), :internal_encoding
169+
end
170+
171+
def test_external_encoding
172+
assert_send_type "() -> Encoding",
173+
StringIO.new("abc"), :external_encoding
174+
end
88175
end

0 commit comments

Comments
 (0)