* 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
This commit is contained in:
nobu 2011-07-17 06:30:10 +00:00
parent 1297cc615c
commit 18f0a65018
3 changed files with 37 additions and 8 deletions

View File

@ -1,3 +1,8 @@
Sun Jul 17 15:30:04 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <Martin.Bosslet@googlemail.com> Sun Jul 17 07:56:31 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
* test/openssl/test_ssl_session.rb: add PEM SSL session without TLS * test/openssl/test_ssl_session.rb: add PEM SSL session without TLS

23
error.c
View File

@ -225,18 +225,25 @@ rb_warning(const char *fmt, ...)
/* /*
* call-seq: * call-seq:
* warn(msg) -> nil * warn(msg, ...) -> nil
* *
* Display the given message (followed by a newline) on STDERR unless * Displays each of the given messages followed by a record separator on
* warnings are disabled (for example with the <code>-W0</code> flag). * STDERR unless warnings have been disabled (for example with the
* <code>-W0</code> flag).
*
* warn("warning 1", "warning 2")
*
* <em>produces:</em>
*
* warning 1
* warning 2
*/ */
static VALUE static VALUE
rb_warn_m(VALUE self, VALUE mesg) rb_warn_m(int argc, VALUE *argv, VALUE exc)
{ {
if (!NIL_P(ruby_verbose)) { if (!NIL_P(ruby_verbose) && argc > 0) {
rb_io_write(rb_stderr, mesg); rb_io_puts(argc, argv, rb_stderr);
rb_io_write(rb_stderr, rb_default_rs);
} }
return Qnil; return Qnil;
} }
@ -1572,7 +1579,7 @@ Init_Exception(void)
rb_mErrno = rb_define_module("Errno"); 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 void

View File

@ -1975,4 +1975,21 @@ End
write_file.close write_file.close
file.close! file.close!
end 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 end