From fd13561d14427164d94be9d69873e25215c0c60e Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Fri, 20 Dec 2019 11:00:55 +0900 Subject: [PATCH] Add some tests --- mrblib/yarn.rb | 6 +++++- src/mrb_uv.c | 2 +- test/uv.rb | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/mrblib/yarn.rb b/mrblib/yarn.rb index 729322c..419cd04 100644 --- a/mrblib/yarn.rb +++ b/mrblib/yarn.rb @@ -1,6 +1,10 @@ module UV def self.sleep sec - current_yarn.sleep sec + if UV.current_loop.current_yarn + current_yarn.sleep sec + else + UV.sleep_milli sec * 1000 + end end def self.quote cmd diff --git a/src/mrb_uv.c b/src/mrb_uv.c index 037595b..3c360d2 100644 --- a/src/mrb_uv.c +++ b/src/mrb_uv.c @@ -1869,7 +1869,7 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) { mrb_define_module_function(mrb, _class_uv, "random", mrb_uv_random, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1)); #endif #if MRB_UV_CHECK_VERSION(1, 34, 0) - mrb_define_module_function(mrb, _class_uv, "sleep", mrb_uv_sleep, MRB_ARGS_REQ(1)); + mrb_define_module_function(mrb, _class_uv, "sleep_milli", mrb_uv_sleep, MRB_ARGS_REQ(1)); #endif mrb_define_const(mrb, _class_uv, "UV_RUN_DEFAULT", mrb_fixnum_value(UV_RUN_DEFAULT)); diff --git a/test/uv.rb b/test/uv.rb index 22e17b0..46f9d38 100644 --- a/test/uv.rb +++ b/test/uv.rb @@ -206,3 +206,36 @@ assert_kind_of Fixnum, p.uid assert_kind_of Fixnum, p.gid end + +assert 'UV.constrained_memory' do + skip unless UV.respond_to? :constrained_memory + assert_kind_of Fixnum, UV.constrained_memory +end + +assert 'UV.timeofday' do + skip unless UV.respond_to? :timeofday + assert_kind_of Time, UV.timeofday +end + +assert 'UV.sleep_milli' do + skip unless UV.respond_to? :sleep_milli + skip unless UV.respond_to? :timeofday + t = UV.timeofday + UV.sleep_milli 1 + assert_true (UV.timeofday - t) >= 0.001 +end + +assert 'UV::OS.environ' do + skip unless UV::OS.respond_to? :environ + assert_kind_of Hash, UV::OS.environ +end + +assert 'UV::OS.uname' do + skip unless UV::OS.respond_to? :uname + u = UV::OS.uname + assert_kind_of Hash, u + assert_kind_of String, u[:sysname] + assert_kind_of String, u[:release] + assert_kind_of String, u[:version] + assert_kind_of String, u[:machine] +end