Skip to content

Commit d11ca20

Browse files
committed
Use openssl instead of fiddle and erb for native extension test
1 parent a7dfd0c commit d11ca20

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

spec/bundled_gems_spec.rb

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ def self.ruby=(ruby)
6161
Gem::BUNDLED_GEMS.send(:remove_const, :ARCHDIR)
6262
Gem::BUNDLED_GEMS.send(:remove_const, :SINCE)
6363
Gem::BUNDLED_GEMS.send(:remove_const, :SINCE_FAST_PATH)
64+
Gem::BUNDLED_GEMS.send(:remove_const, :PREFIXED)
6465
Gem::BUNDLED_GEMS.const_set(:LIBDIR, File.expand_path(File.join(__dir__, "../../..", "lib")) + "/")
6566
Gem::BUNDLED_GEMS.const_set(:ARCHDIR, File.expand_path($LOAD_PATH.find{|path| path.include?(".ext/common") }) + "/")
66-
Gem::BUNDLED_GEMS.const_set(:SINCE, { "fiddle" => "3.5.0", "irb" => "3.5.0", "csv" => "3.4.0", "net-smtp" => "3.1.0", "erb" => RUBY_VERSION })
67+
Gem::BUNDLED_GEMS.const_set(:SINCE, { "openssl" => RUBY_VERSION, "irb" => "3.5.0", "csv" => "3.4.0", "net-smtp" => "3.1.0" })
6768
Gem::BUNDLED_GEMS.const_set(:SINCE_FAST_PATH, Gem::BUNDLED_GEMS::SINCE.transform_keys { |g| g.sub(/\A.*\-/, "") } )
69+
Gem::BUNDLED_GEMS.const_set(:PREFIXED, { "openssl" => true })
6870
STUB
6971
}
7072

@@ -89,18 +91,18 @@ def script(code, options = {})
8991
require "csv"
9092
rescue LoadError
9193
end
92-
require "erb"
94+
require "openssl"
9395
RUBY
9496

9597
expect(err).to include(/csv was loaded from (.*) from Ruby 3.4.0/)
96-
expect(err).to include(/-e:17/)
97-
expect(err).to include(/erb was loaded from (.*) from Ruby #{RUBY_VERSION}/)
98-
expect(err).to include(/-e:20/)
98+
expect(err).to include(/-e:19/)
99+
expect(err).to include(/openssl was loaded from (.*) from Ruby #{RUBY_VERSION}/)
100+
expect(err).to include(/-e:22/)
99101
end
100102

101103
it "Show warning when bundled gems called as dependency" do
102104
build_lib "activesupport", "7.0.7.2" do |s|
103-
s.write "lib/active_support/all.rb", "require 'erb'"
105+
s.write "lib/active_support/all.rb", "require 'openssl'"
104106
end
105107

106108
script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
@@ -114,7 +116,7 @@ def script(code, options = {})
114116
require "active_support/all"
115117
RUBY
116118

117-
expect(err).to include(/erb was loaded from (.*) from Ruby 3.5.0/)
119+
expect(err).to include(/openssl was loaded from (.*) from Ruby 3.5.0/)
118120
expect(err).to include(/lib\/active_support\/all\.rb:1/)
119121
end
120122

@@ -131,37 +133,37 @@ def script(code, options = {})
131133
RUBY
132134

133135
expect(err).to include(/net\/smtp was loaded from (.*) from Ruby 3.1.0/)
134-
expect(err).to include(/-e:17/)
136+
expect(err).to include(/-e:19/)
135137
expect(err).to include("You can add net-smtp")
136138
end
137139

138-
it "Show warning sub-feature like fiddle/import" do
140+
it "Show warning sub-feature like openssl/bn" do
139141
skip "This test is not working on Windows" if Gem.win_platform?
140142

141143
script <<-RUBY
142144
gemfile do
143145
source "https://rubygems.org"
144146
end
145147
146-
require "fiddle/import"
148+
require "openssl/bn"
147149
RUBY
148150

149-
expect(err).to include(/fiddle\/import is found in fiddle, (.*) part of the default gems starting from Ruby 3\.5\.0/)
150-
expect(err).to include(/-e:16/)
151+
expect(err).to include(/openssl\/bn is found in openssl, (.*) part of the default gems starting from Ruby #{RUBY_VERSION}/)
152+
expect(err).to include(/-e:18/)
151153
end
152154

153155
it "Show warning when bundle exec with ruby and script" do
154156
code = <<-RUBY
155157
#{stub_code}
156-
require "erb"
158+
require "openssl"
157159
RUBY
158160
create_file("script.rb", code)
159161
create_file("Gemfile", "source 'https://rubygems.org'")
160162

161163
bundle "exec ruby script.rb"
162164

163-
expect(err).to include(/erb was loaded from (.*) from Ruby 3.5.0/)
164-
expect(err).to include(/script\.rb:10/)
165+
expect(err).to include(/openssl was loaded from (.*) from Ruby 3.5.0/)
166+
expect(err).to include(/script\.rb:12/)
165167
end
166168

167169
it "Show warning when bundle exec with shebang's script" do
@@ -170,24 +172,24 @@ def script(code, options = {})
170172
code = <<-RUBY
171173
#!/usr/bin/env ruby
172174
#{stub_code}
173-
require "erb"
175+
require "openssl"
174176
RUBY
175177
create_file("script.rb", code)
176178
FileUtils.chmod(0o777, bundled_app("script.rb"))
177179
create_file("Gemfile", "source 'https://rubygems.org'")
178180

179181
bundle "exec ./script.rb"
180182

181-
expect(err).to include(/erb was loaded from (.*) from Ruby 3.5.0/)
182-
expect(err).to include(/script\.rb:11/)
183+
expect(err).to include(/openssl was loaded from (.*) from Ruby 3.5.0/)
184+
expect(err).to include(/script\.rb:13/)
183185
end
184186

185187
it "Show warning when bundle exec with -r option" do
186188
create_file("stub.rb", stub_code)
187189
create_file("Gemfile", "source 'https://rubygems.org'")
188-
bundle "exec ruby -r./stub -rerb -e ''"
190+
bundle "exec ruby -r./stub -ropenssl -e ''"
189191

190-
expect(err).to include(/erb was loaded from (.*) from Ruby 3.5.0/)
192+
expect(err).to include(/openssl was loaded from (.*) from Ruby 3.5.0/)
191193
end
192194

193195
it "Show warning when warn is not the standard one in the current scope" do
@@ -201,7 +203,7 @@ def my
201203
source "https://rubygems.org"
202204
end
203205
204-
require "erb"
206+
require "openssl"
205207
end
206208
207209
extend self
@@ -210,24 +212,24 @@ def my
210212
My.my
211213
RUBY
212214

213-
expect(err).to include(/erb was loaded from (.*) from Ruby 3.5.0/)
214-
expect(err).to include(/-e:21/)
215+
expect(err).to include(/openssl was loaded from (.*) from Ruby 3.5.0/)
216+
expect(err).to include(/-e:23/)
215217
end
216218

217219
it "Don't show warning when bundled gems called as dependency" do
218220
build_lib "activesupport", "7.0.7.2" do |s|
219-
s.write "lib/active_support/all.rb", "require 'erb'"
221+
s.write "lib/active_support/all.rb", "require 'openssl'"
220222
end
221-
build_lib "erb", "1.0.0" do |s|
222-
s.write "lib/erb.rb", "puts 'erb'"
223+
build_lib "openssl", "1.0.0" do |s|
224+
s.write "lib/openssl.rb", "puts 'openssl'"
223225
end
224226

225227
script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
226228
gemfile do
227229
source "https://gem.repo1"
228230
path "#{lib_path}" do
229231
gem "activesupport", "7.0.7.2"
230-
gem "erb"
232+
gem "openssl"
231233
end
232234
end
233235
@@ -248,11 +250,11 @@ def my
248250
# Bootsnap.setup(cache_dir: 'tmp/cache')
249251
250252
# bootsnap expand required feature to full path
251-
# require 'csv'
252-
require Gem::BUNDLED_GEMS::LIBDIR + 'erb'
253+
# require 'openssl'
254+
require Gem::BUNDLED_GEMS::ARCHDIR + 'openssl'
253255
RUBY
254256

255-
expect(err).to include(/erb was loaded from (.*) from Ruby 3.5.0/)
257+
expect(err).to include(/openssl was loaded from (.*) from Ruby 3.5.0/)
256258
# TODO: We should assert caller location like below:
257259
# test_warn_bootsnap.rb:14: warning: ...
258260
end
@@ -268,40 +270,40 @@ def my
268270
# Bootsnap.setup(cache_dir: 'tmp/cache')
269271
270272
# bootsnap expand required feature to full path
271-
# require 'fiddle'
272-
require Gem::BUNDLED_GEMS::ARCHDIR + "fiddle"
273+
# require 'openssl'
274+
require Gem::BUNDLED_GEMS::ARCHDIR + "openssl"
273275
RUBY
274276

275-
expect(err).to include(/fiddle was loaded from (.*) from Ruby 3.5.0/)
277+
expect(err).to include(/openssl was loaded from (.*) from Ruby #{RUBY_VERSION}/)
276278
# TODO: We should assert caller location like below:
277279
# test_warn_bootsnap_rubyarchdir_gem.rb:14: warning: ...
278280
end
279281

280282
it "Show warning with bootsnap and some gem in Gemfile" do
281283
# Original issue is childprocess 5.0.0 and logger.
282-
build_lib "erb2", "5.0.0" do |s|
284+
build_lib "openssl2", "5.0.0" do |s|
283285
# bootsnap expand required feature to full path
284-
rubylibpath = File.expand_path(File.join(__dir__, "..", "lib"))
285-
s.write "lib/erb2.rb", "require '#{rubylibpath}/erb'"
286+
rubyextpath = File.expand_path(File.join(__dir__, "..", ".ext", "common"))
287+
s.write "lib/openssl2.rb", "require '#{rubyextpath}/openssl'"
286288
end
287289

288290
script <<-RUBY
289291
gemfile do
290292
source "https://rubygems.org"
291293
# gem "bootsnap", require: false
292294
path "#{lib_path}" do
293-
gem "erb2", "5.0.0"
295+
gem "openssl2", "5.0.0"
294296
end
295297
end
296298
297299
# require 'bootsnap'
298300
# Bootsnap.setup(cache_dir: 'tmp/cache')
299301
300302
# bootsnap expand required feature to full path
301-
require Gem.loaded_specs["erb2"].full_gem_path + '/lib/erb2'
303+
require Gem.loaded_specs["openssl2"].full_gem_path + '/lib/openssl2'
302304
RUBY
303305

304-
expect(err).to include(/erb was loaded from (.*) from Ruby #{RUBY_VERSION}/)
306+
expect(err).to include(/openssl was loaded from (.*) from Ruby #{RUBY_VERSION}/)
305307
# TODO: We should assert caller location like below:
306308
# $GEM_HOME/gems/childprocess-5.0.0/lib/childprocess.rb:7: warning:
307309
end
@@ -315,31 +317,31 @@ def my
315317
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
316318
loader.setup
317319
318-
require 'erb'
320+
require 'openssl'
319321
RUBY
320322
create_file("script.rb", code)
321323
create_file("Gemfile", "source 'https://rubygems.org'")
322324
bundle "exec ruby script.rb"
323325

324-
expect(err).to include(/erb was loaded from (.*) from Ruby 3.5.0/)
325-
expect(err).to include(/script\.rb:15/)
326+
expect(err).to include(/openssl was loaded from (.*) from Ruby 3.5.0/)
327+
expect(err).to include(/script\.rb:17/)
326328
end
327329

328-
it "Don't show warning fiddle/import when fiddle on Gemfile" do
329-
build_lib "fiddle", "1.0.0" do |s|
330-
s.write "lib/fiddle.rb", "puts 'fiddle'"
331-
s.write "lib/fiddle/import.rb", "puts 'fiddle/import'"
330+
it "Don't show warning openssl/bn when openssl on Gemfile" do
331+
build_lib "openssl", "1.0.0" do |s|
332+
s.write "lib/openssl.rb", "puts 'openssl'"
333+
s.write "lib/openssl/bn.rb", "puts 'openssl/bn'"
332334
end
333335

334336
script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
335337
gemfile do
336338
source "https://gem.repo1"
337339
path "#{lib_path}" do
338-
gem "fiddle"
340+
gem "openssl"
339341
end
340342
end
341343
342-
require "fiddle/import"
344+
require "openssl/bn"
343345
RUBY
344346

345347
expect(err).to be_empty

0 commit comments

Comments
 (0)