From 18f0a65018dd357a1815941618d3cf9f274e6239 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 17 Jul 2011 06:30:10 +0000 Subject: [PATCH] * error.c (rb_warn_m): accept multiple args in like puts. rdoc patch by Erik Price at [ruby-core:38119]. [Feature #5029] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ error.c | 23 +++++++++++++++-------- test/ruby/test_io.rb | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9dfe973ee3..6f6b3f9cde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Jul 17 15:30:04 2011 Nobuyoshi Nakada + + * error.c (rb_warn_m): accept multiple args in like puts. rdoc + patch by Erik Price at [ruby-core:38119]. [Feature #5029] + Sun Jul 17 07:56:31 2011 Martin Bosslet * test/openssl/test_ssl_session.rb: add PEM SSL session without TLS diff --git a/error.c b/error.c index ce959fc221..53f5472efc 100644 --- a/error.c +++ b/error.c @@ -225,18 +225,25 @@ rb_warning(const char *fmt, ...) /* * call-seq: - * warn(msg) -> nil + * warn(msg, ...) -> nil * - * Display the given message (followed by a newline) on STDERR unless - * warnings are disabled (for example with the -W0 flag). + * Displays each of the given messages followed by a record separator on + * STDERR unless warnings have been disabled (for example with the + * -W0 flag). + * + * warn("warning 1", "warning 2") + * + * produces: + * + * warning 1 + * warning 2 */ static VALUE -rb_warn_m(VALUE self, VALUE mesg) +rb_warn_m(int argc, VALUE *argv, VALUE exc) { - if (!NIL_P(ruby_verbose)) { - rb_io_write(rb_stderr, mesg); - rb_io_write(rb_stderr, rb_default_rs); + if (!NIL_P(ruby_verbose) && argc > 0) { + rb_io_puts(argc, argv, rb_stderr); } return Qnil; } @@ -1572,7 +1579,7 @@ Init_Exception(void) rb_mErrno = rb_define_module("Errno"); - rb_define_global_function("warn", rb_warn_m, 1); + rb_define_global_function("warn", rb_warn_m, -1); } void diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 0325867496..c62edbba00 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1975,4 +1975,21 @@ End write_file.close file.close! end + + def test_warn + stderr = EnvUtil.verbose_warning do + warn "warning" + end + assert_equal("warning\n", stderr) + + stderr = EnvUtil.verbose_warning do + warn + end + assert_equal("", stderr) + + stderr = EnvUtil.verbose_warning do + warn "[Feature #5029]", "[ruby-core:38070]" + end + assert_equal("[Feature #5029]\n[ruby-core:38070]\n", stderr) + end end