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

ruby-changes:54197

From: nobu <ko1@a...>
Date: Sun, 16 Dec 2018 21:56:05 +0900 (JST)
Subject: [ruby-changes:54197] nobu:r66418 (trunk): Refine error message for time interval

nobu	2018-12-16 21:55:59 +0900 (Sun, 16 Dec 2018)

  New Revision: 66418

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66418

  Log:
    Refine error message for time interval
    
    * time.c (time_timespec): Time interval value can be zero, not
      only positive.  [ruby-dev:50709] [Bug #15420]
    
    From: shuujii (Shuji KOBAYASHI) <shuujii@g...>

  Modified files:
    trunk/test/ruby/test_process.rb
    trunk/time.c
Index: time.c
===================================================================
--- time.c	(revision 66417)
+++ time.c	(revision 66418)
@@ -2524,12 +2524,12 @@ time_timespec(VALUE num, int interval) https://github.com/ruby/ruby/blob/trunk/time.c#L2524
     if (FIXNUM_P(num)) {
 	t.tv_sec = NUM2TIMET(num);
 	if (interval && t.tv_sec < 0)
-	    rb_raise(rb_eArgError, "%s must be positive", tstr);
+            rb_raise(rb_eArgError, "%s must not be negative", tstr);
 	t.tv_nsec = 0;
     }
     else if (RB_FLOAT_TYPE_P(num)) {
 	if (interval && RFLOAT_VALUE(num) < 0.0)
-	    rb_raise(rb_eArgError, "%s must be positive", tstr);
+            rb_raise(rb_eArgError, "%s must not be negative", tstr);
 	else {
 	    double f, d;
 
@@ -2554,7 +2554,7 @@ time_timespec(VALUE num, int interval) https://github.com/ruby/ruby/blob/trunk/time.c#L2554
     else if (RB_TYPE_P(num, T_BIGNUM)) {
 	t.tv_sec = NUM2TIMET(num);
 	if (interval && t.tv_sec < 0)
-	    rb_raise(rb_eArgError, "%s must be positive", tstr);
+            rb_raise(rb_eArgError, "%s must not be negative", tstr);
 	t.tv_nsec = 0;
     }
     else {
@@ -2565,7 +2565,7 @@ time_timespec(VALUE num, int interval) https://github.com/ruby/ruby/blob/trunk/time.c#L2565
             f = rb_ary_entry(ary, 1);
             t.tv_sec = NUM2TIMET(i);
             if (interval && t.tv_sec < 0)
-                rb_raise(rb_eArgError, "%s must be positive", tstr);
+                rb_raise(rb_eArgError, "%s must not be negative", tstr);
             f = rb_funcall(f, '*', 1, INT2FIX(1000000000));
             t.tv_nsec = NUM2LONG(f);
         }
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 66417)
+++ test/ruby/test_process.rb	(revision 66418)
@@ -1509,6 +1509,9 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1509
 
   def test_sleep
     assert_raise(ArgumentError) { sleep(1, 1) }
+    [-1, -1.0, -1r].each do |sec|
+      assert_raise_with_message(ArgumentError, /not.*negative/) { sleep(sec) }
+    end
   end
 
   def test_getpgid

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

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