Try to fix a fragile `File#mtime` test.

parent 31827189
......@@ -345,11 +345,7 @@ mrb_file_mtime(mrb_state *mrb, mrb_value self)
fd = (int)mrb_fixnum(mrb_io_fileno(mrb, self));
if (fstat(fd, &st) == -1)
return mrb_false_value();
#ifndef MRB_WITHOUT_FLOAT
return mrb_funcall(mrb, obj, "at", 1, mrb_float_value(mrb, st.st_mtime));
#else
return mrb_funcall(mrb, obj, "at", 1, mrb_fixnum_value(st.st_mtime));
#endif
}
mrb_value
......
......@@ -73,12 +73,12 @@ assert('File#mtime') do
skip "File#mtime require Time"
end
begin
now = Time.now.to_i
mt = 0
File.open("#{$mrbtest_io_wfname}.mtime", 'w') do |f|
mt = f.mtime.to_i
assert_equal Time, f.mtime.class
File.open("#{$mrbtest_io_wfname}.mtime", 'r') do |f2|
assert_equal true, f.mtime == f2.mtime
end
end
assert_equal true, mt >= now
ensure
File.delete("#{$mrbtest_io_wfname}.mtime")
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment