diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 816751ec81..6f16ac3062 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 8d272d91f3..e70899aabc 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); }