Skip to content

#require should return false if any $LOADED_FEATURES + any $LOAD_PATH already matches the target #1501

@MaxLap

Description

@MaxLap

If a file that was already required matches the the required path, #require should return false, even if another file exist on the path which is earlier.

Note, the script just unshifts the path, but this is also for cases where a later file is loaded absolutely.

require 'tmpdir'
require 'fileutils'

def make_ruby_file(dir, path)
  File.write("#{dir}/#{path}", <<-RUBY)
    puts "in " + #{path.inspect}
  RUBY
end

# #require should skip if any existing $LOADED_FEATURES already match $LOAD_PATH + path.
Dir.mktmpdir('truffleruby_test') do |dir|
  FileUtils.mkpath("#{dir}/one")
  FileUtils.mkpath("#{dir}/prepended")
  make_ruby_file(dir, 'one/test.rb')
  make_ruby_file(dir, 'prepended/test.rb')

  $LOAD_PATH << "#{dir}/one"
  require 'test'
  $LOAD_PATH.unshift "#{dir}/prepended"
  require 'test'
end

In MRI: in one/test.rb
In JRuby: in one/test.rb
In TruffleRuby:

in one/test.rb
in prepended/test.rb

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions