From 237901a41b44dd86754b0a02979d03b56faeeb73 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 25 Oct 2017 12:04:53 +0000 Subject: io.c: warn old write * io.c (rb_io_puts): warn if write method accepts just one argument. [ruby-core:83529] [Feature #14042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 7 +++++++ test/ruby/test_io.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/io.c b/io.c index 03cd40e7e8..5e44899b7a 100644 --- a/io.c +++ b/io.c @@ -1690,6 +1690,13 @@ static VALUE rb_io_writev(VALUE io, int argc, VALUE *argv) { if (argc > 1 && rb_obj_method_arity(io, id_write) == 1) { + if (io != rb_stderr && RTEST(ruby_verbose)) { + VALUE klass = CLASS_OF(io); + char sep = FL_TEST(klass, FL_SINGLETON) ? (klass = io, '.') : '#'; + rb_warning("%+"PRIsVALUE"%c""write is outdated interface" + " which accepts just one argument", + klass, sep); + } do rb_io_write(io, *argv++); while (--argc); return argv[0]; /* unused right now */ } diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index a32369eca5..f16573682b 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2458,6 +2458,22 @@ End end) end + def test_puts_old_write + capture = String.new + def capture.write(str) + self << str + end + + capture.clear + assert_warning(/[.#]write is outdated/) do + stdout, $stdout = $stdout, capture + puts "hey" + ensure + $stdout = stdout + end + assert_equal("hey\n", capture) + end + def test_display pipe(proc do |w| "foo".display(w) -- cgit v1.2.3