diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2024-02-15 10:56:29 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2024-03-14 18:33:28 +0900 |
commit | 5326337d4f15ccf33128b3cf5a8896ba7f91fcc4 (patch) | |
tree | 3ad7ae3a09b634a82be39e42fda926df3ed5035a | |
parent | 67fe047821d08781f783476c4060f017cd27541f (diff) | |
download | ruby-5326337d4f15ccf33128b3cf5a8896ba7f91fcc4.tar.gz |
[Feature #20244] Issue a single `Warning.warn` call
Make the entire series of message lines a multiline string so that the
`Warning.warn` hook can receive them in a single call.
-rw-r--r-- | dir.c | 8 | ||||
-rw-r--r-- | test/ruby/test_dir.rb | 20 |
2 files changed, 26 insertions, 2 deletions
@@ -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 |