summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-16 12:55:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-16 12:55:59 +0000
commit9446db408ce9fec8116aa767ce159513558a3638 (patch)
tree087fa0d8b919977bc3b65d033e9c88c4e941c756
parentbb1e08e770e6d3c6528e9d5041b52016b94bebd2 (diff)
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@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_process.rb3
-rw-r--r--time.c8
2 files changed, 7 insertions, 4 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 816751e..6f16ac3 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1509,6 +1509,9 @@ class TestProcess < Test::Unit::TestCase
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
diff --git a/time.c b/time.c
index 8d272d9..e70899a 100644
--- a/time.c
+++ b/time.c
@@ -2524,12 +2524,12 @@ time_timespec(VALUE num, int interval)
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)
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)
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);
}