[前][次][番号順一覧][スレッド一覧]

ruby-changes:20520

From: nobu <ko1@a...>
Date: Sun, 17 Jul 2011 15:30:21 +0900 (JST)
Subject: [ruby-changes:20520] nobu:r32568 (trunk): * error.c (rb_warn_m): accept multiple args in like puts. rdoc

nobu	2011-07-17 15:30:10 +0900 (Sun, 17 Jul 2011)

  New Revision: 32568

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32568

  Log:
    * error.c (rb_warn_m): accept multiple args in like puts.  rdoc
      patch by Erik Price at [ruby-core:38119].  [Feature #5029]

  Modified files:
    trunk/ChangeLog
    trunk/error.c
    trunk/test/ruby/test_io.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32567)
+++ ChangeLog	(revision 32568)
@@ -1,3 +1,8 @@
+Sun Jul 17 15:30:04 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@g...>
 
 	* test/openssl/test_ssl_session.rb: add PEM SSL session without TLS
Index: error.c
===================================================================
--- error.c	(revision 32567)
+++ error.c	(revision 32568)
@@ -225,18 +225,25 @@
 
 /*
  * 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 <code>-W0</code> flag).
+ * Displays each of the given messages followed by a record separator on
+ * 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
-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 @@
 
     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
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 32567)
+++ test/ruby/test_io.rb	(revision 32568)
@@ -1975,4 +1975,21 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]