summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dir.c8
-rw-r--r--test/ruby/test_dir.rb20
2 files changed, 26 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index da23c383cb..84ef5ee6f5 100644
--- a/dir.c
+++ b/dir.c
@@ -1082,9 +1082,13 @@ chdir_alone_block_p(void)
if (rb_thread_current() != chdir_lock.thread)
rb_raise(rb_eRuntimeError, "conflicting chdir during another chdir block");
if (!block_given) {
- rb_warn("conflicting chdir during another chdir block");
if (!NIL_P(chdir_lock.path)) {
- rb_compile_warn(RSTRING_PTR(chdir_lock.path), chdir_lock.line, "here");
+ rb_warn("conflicting chdir during another chdir block\n"
+ "%" PRIsVALUE ":%d: note: previous chdir was here",
+ chdir_lock.path, chdir_lock.line);
+ }
+ else {
+ rb_warn("conflicting chdir during another chdir block");
}
}
}
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 7468d3fc76..2cc1c3ef4a 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -171,6 +171,26 @@ class TestDir < Test::Unit::TestCase
42
end
+ assert_separately(["-", @root], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ root = ARGV.shift
+
+ $dir_warnings = []
+
+ def Warning.warn(message)
+ $dir_warnings << message
+ end
+
+ line2 = line1 = __LINE__; Dir.chdir(root) do
+ line2 = __LINE__; Dir.chdir
+ end
+
+ message = $dir_warnings.shift
+ assert_include(message, "#{__FILE__}:#{line2}:")
+ assert_include(message, "#{__FILE__}:#{line1}:")
+ assert_empty($dir_warnings)
+ end;
+
assert_equal(42, ret)
ensure
begin