Skip to content

Commit

Permalink
Add more specs for #require and canonicalizing entries from $LOAD_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jul 9, 2018
1 parent aef7089 commit 9a76df4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/ruby/core/kernel/shared/require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,46 @@
ScratchPad.recorded.should == [loaded_feature]
end
end

describe "with symlinks in the required feature and $LOAD_PATH" do
before :each do
@dir = tmp("realdir")
mkdir_p @dir
@file = "#{@dir}/realfile.rb"
touch(@file) { |f| f.puts 'ScratchPad << __FILE__' }

@symlink_to_dir = tmp("symdir").freeze
File.symlink(@dir, @symlink_to_dir)
@symlink_to_file = "#{@dir}/symfile.rb"
File.symlink("realfile.rb", @symlink_to_file)
end

after :each do
rm_r @dir, @symlink_to_dir
end

ruby_version_is ""..."2.4.4" do
it "canonicalizes neither the entry in $LOAD_PATH nor the filename passed to #require" do
$LOAD_PATH.unshift(@symlink_to_dir)
@object.require("symfile").should be_true
loaded_feature = "#{@symlink_to_dir}/symfile.rb"
ScratchPad.recorded.should == [loaded_feature]
$".last.should == loaded_feature
$LOAD_PATH[0].should == @symlink_to_dir
end
end

ruby_version_is "2.4.4" do
it "canonicalizes the entry in $LOAD_PATH but not the filename passed to #require" do
$LOAD_PATH.unshift(@symlink_to_dir)
@object.require("symfile").should be_true
loaded_feature = "#{@dir}/symfile.rb"
ScratchPad.recorded.should == [loaded_feature]
$".last.should == loaded_feature
$LOAD_PATH[0].should == @symlink_to_dir
end
end
end
end

it "does not store the path if the load fails" do
Expand Down
2 changes: 2 additions & 0 deletions spec/tags/core/kernel/require_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ slow:Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread and
slow:Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread and unicode_normalize are already required
fails:Kernel#require (path resolution) loads a file that recursively requires itself
fails:Kernel.require (path resolution) loads a file that recursively requires itself
fails:Kernel#require ($LOADED_FEATURES) with symlinks in the required feature and $LOAD_PATH canonicalizes the entry in $LOAD_PATH but not the filename passed to #require
fails:Kernel.require ($LOADED_FEATURES) with symlinks in the required feature and $LOAD_PATH canonicalizes the entry in $LOAD_PATH but not the filename passed to #require

0 comments on commit 9a76df4

Please sign in to comment.