Skip to content

Commit 0c7f6b2

Browse files
committed
Add specs for the absolute path of the main script after chdir
* See #2709
1 parent 5c6ddc7 commit 0c7f6b2

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
end
1818
end
1919

20+
it 'returns the correct absolute path when using a relative main script path and changing CWD' do
21+
script = fixture(__FILE__, 'subdir/absolute_path_main_chdir.rb')
22+
sibling = fixture(__FILE__, 'subdir/sibling.rb')
23+
subdir = File.dirname script
24+
Dir.chdir(fixture(__FILE__)) do
25+
ruby_exe('subdir/absolute_path_main_chdir.rb').should == "subdir/absolute_path_main_chdir.rb\n#{subdir}\n#{subdir}\n#{script}\n#{sibling}\n"
26+
end
27+
end
28+
2029
context "when used in eval with a given filename" do
2130
code = "caller_locations(0)[0].absolute_path"
2231

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
puts __FILE__
2+
puts __dir__
3+
Dir.chdir __dir__
4+
5+
# Check __dir__ is still correct after chdir
6+
puts __dir__
7+
8+
puts caller_locations(0)[0].absolute_path
9+
10+
# require_relative also needs to know the absolute path of the current file so we test it here too
11+
require_relative 'sibling'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
puts __FILE__
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
slow:Thread::Backtrace::Location#absolute_path returns an absolute path when using a relative main script path
22
fails:Thread::Backtrace::Location#absolute_path canonicalization returns a canonical path without symlinks, even when __FILE__ is removed
3+
slow:Thread::Backtrace::Location#absolute_path returns the correct absolute path when using a relative main script path and changing CWD

0 commit comments

Comments
 (0)