mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
bb1e08e770
commit
9446db408c
2 changed files with 7 additions and 4 deletions
|
@ -1509,6 +1509,9 @@ class TestProcess < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_sleep
|
def test_sleep
|
||||||
assert_raise(ArgumentError) { sleep(1, 1) }
|
assert_raise(ArgumentError) { sleep(1, 1) }
|
||||||
|
[-1, -1.0, -1r].each do |sec|
|
||||||
|
assert_raise_with_message(ArgumentError, /not.*negative/) { sleep(sec) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_getpgid
|
def test_getpgid
|
||||||
|
|
8
time.c
8
time.c
|
@ -2524,12 +2524,12 @@ time_timespec(VALUE num, int interval)
|
||||||
if (FIXNUM_P(num)) {
|
if (FIXNUM_P(num)) {
|
||||||
t.tv_sec = NUM2TIMET(num);
|
t.tv_sec = NUM2TIMET(num);
|
||||||
if (interval && t.tv_sec < 0)
|
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;
|
t.tv_nsec = 0;
|
||||||
}
|
}
|
||||||
else if (RB_FLOAT_TYPE_P(num)) {
|
else if (RB_FLOAT_TYPE_P(num)) {
|
||||||
if (interval && RFLOAT_VALUE(num) < 0.0)
|
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 {
|
else {
|
||||||
double f, d;
|
double f, d;
|
||||||
|
|
||||||
|
@ -2554,7 +2554,7 @@ time_timespec(VALUE num, int interval)
|
||||||
else if (RB_TYPE_P(num, T_BIGNUM)) {
|
else if (RB_TYPE_P(num, T_BIGNUM)) {
|
||||||
t.tv_sec = NUM2TIMET(num);
|
t.tv_sec = NUM2TIMET(num);
|
||||||
if (interval && t.tv_sec < 0)
|
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;
|
t.tv_nsec = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2565,7 +2565,7 @@ time_timespec(VALUE num, int interval)
|
||||||
f = rb_ary_entry(ary, 1);
|
f = rb_ary_entry(ary, 1);
|
||||||
t.tv_sec = NUM2TIMET(i);
|
t.tv_sec = NUM2TIMET(i);
|
||||||
if (interval && t.tv_sec < 0)
|
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));
|
f = rb_funcall(f, '*', 1, INT2FIX(1000000000));
|
||||||
t.tv_nsec = NUM2LONG(f);
|
t.tv_nsec = NUM2LONG(f);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue