Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
take-cheeze committed Dec 20, 2019
1 parent 6e06c74 commit fd13561
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mrblib/yarn.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mrb_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
33 changes: 33 additions & 0 deletions test/uv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fd13561

Please sign in to comment.