Skip to content

Commit 487b667

Browse files
authored
Merge pull request #2785 from ruby/backports
Ruby 4.0.0 backports
2 parents 51c9f36 + 05e92bb commit 487b667

File tree

5 files changed

+101
-8
lines changed

5 files changed

+101
-8
lines changed

lib/rbs/collection/config/lockfile_generator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ def generate
184184
lockfile.gems[name] = { name: name, version: "0", source: source }
185185
end
186186
return
187+
when 'set', 'pathname'
188+
# set and pathname is migrated to core from stdlib.
189+
RBS.logger.info {
190+
from = from_gem || "rbs_collection.yaml"
191+
"`#{name}` is a part of the Ruby core library. The dependency to the library can be safely deleted from #{from}."
192+
}
193+
return
187194
when *ALUMNI_STDLIBS.keys
188195
version = ALUMNI_STDLIBS.fetch(name)
189196
if from_gem

test/rbs/cli_test.rb

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,86 @@ def test_collection_install__mutex_m__rbs_dependency_and__gem_dependency
15461546
end
15471547
end
15481548

1549+
def test_collection_install__pathname_set
1550+
Dir.mktmpdir do |dir|
1551+
Dir.chdir(dir) do
1552+
dir = Pathname(dir)
1553+
dir.join(RBS::Collection::Config::PATH).write(<<~YAML)
1554+
sources:
1555+
- name: ruby/gem_rbs_collection
1556+
remote: https://github.com/ruby/gem_rbs_collection.git
1557+
revision: b4d3b346d9657543099a35a1fd20347e75b8c523
1558+
repo_dir: gems
1559+
1560+
path: #{dir.join('gem_rbs_collection')}
1561+
1562+
gems:
1563+
- name: pathname
1564+
- name: set
1565+
- name: ast
1566+
- name: cgi-escape
1567+
YAML
1568+
1569+
bundle_install('ast', 'logger')
1570+
_stdout, stderr = run_rbs_collection("install", bundler: true)
1571+
1572+
assert_include stderr, 'Cannot find `pathname` gem.'
1573+
assert_include stderr, 'Cannot find `set` gem.'
1574+
1575+
lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
1576+
lockfile_path: dir + "rbs_collection.lock.yaml",
1577+
data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read)
1578+
)
1579+
1580+
assert_nil lockfile.gems["set"]
1581+
assert_nil lockfile.gems["pathname"]
1582+
assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["cgi-escape"][:source]
1583+
assert_instance_of RBS::Collection::Sources::Git, lockfile.gems["ast"][:source]
1584+
end
1585+
end
1586+
end
1587+
1588+
def test_collection_install__set_pathname__manifest
1589+
Dir.mktmpdir do |dir|
1590+
Dir.chdir(dir) do
1591+
dir = Pathname(dir)
1592+
1593+
(dir + RBS::Collection::Config::PATH).write(<<~YAML)
1594+
sources:
1595+
- type: local
1596+
path: repo
1597+
1598+
path: #{dir.join('gem_rbs_collection')}
1599+
YAML
1600+
1601+
(dir/"repo/true_string/0").mkpath
1602+
(dir/"repo/true_string/0/manifest.yaml").write(<<~YAML)
1603+
dependencies:
1604+
- name: set
1605+
- name: pathname
1606+
- name: cgi-escape
1607+
YAML
1608+
1609+
bundle_install("logger", "true_string") # true_string is a soutaro's gem that doesn't have sig directory
1610+
1611+
_stdout, stderr = run_rbs_collection("install", bundler: true)
1612+
1613+
assert_include stderr, '`set` is a part of the Ruby core library.'
1614+
assert_include stderr, '`pathname` is a part of the Ruby core library.'
1615+
1616+
lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
1617+
lockfile_path: dir + "rbs_collection.lock.yaml",
1618+
data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read)
1619+
)
1620+
1621+
assert_nil lockfile.gems["set"]
1622+
assert_nil lockfile.gems["pathname"]
1623+
assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["cgi-escape"][:source]
1624+
assert_instance_of RBS::Collection::Sources::Local, lockfile.gems["true_string"][:source]
1625+
end
1626+
end
1627+
end
1628+
15491629
def test_subtract
15501630
Dir.mktmpdir do |dir|
15511631
dir = Pathname(dir)

test/stdlib/Method_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ def test_receiver
154154
end
155155

156156
def test_source_location
157-
assert_send_type '() -> [String, Integer]',
158-
METHOD, :source_location
157+
if_ruby(..."4.1") do
158+
assert_send_type '() -> [String, Integer]',
159+
METHOD, :source_location
160+
end
159161
assert_send_type '() -> nil',
160162
method(:__id__), :source_location
161163
end

test/stdlib/Proc_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ def test_parameters
139139
end
140140

141141
def test_source_location
142-
assert_send_type '() -> [String, Integer]',
143-
proc{}, :source_location
142+
if_ruby(..."4.1") do
143+
assert_send_type '() -> [String, Integer]',
144+
proc{}, :source_location
145+
end
144146
assert_send_type '() -> nil',
145147
Proc.new(&Kernel.method(:print)), :source_location
146148
end

test/stdlib/UnboundMethod_test.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ def test_parameters
8989
end
9090

9191
def test_source_location
92-
assert_send_type '() -> [String, Integer]?',
93-
UMETH, :source_location
94-
assert_send_type '() -> [String, Integer]?',
95-
ParamMeths.instance_method(:leading_optional), :source_location
92+
if_ruby(..."4.1") do
93+
assert_send_type '() -> [String, Integer]?',
94+
UMETH, :source_location
95+
assert_send_type '() -> [String, Integer]?',
96+
ParamMeths.instance_method(:leading_optional), :source_location
97+
end
9698
end
9799

98100
def test_super_method

0 commit comments

Comments
 (0)