Unverified Commit e36db51b authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4337 from shuujii/refactor-t_print-for-test

Refactor `t_print` for test
parents 36c9416b df4b0813
......@@ -45,29 +45,21 @@ eval_test(mrb_state *mrb)
}
}
static void
t_printstr(mrb_state *mrb, mrb_value obj)
{
char *s;
mrb_int len;
if (mrb_string_p(obj)) {
s = RSTRING_PTR(obj);
len = RSTRING_LEN(obj);
fwrite(s, len, 1, stdout);
fflush(stdout);
}
}
mrb_value
mrb_t_printstr(mrb_state *mrb, mrb_value self)
/* Implementation of print due to the reason that there might be no print */
static mrb_value
t_print(mrb_state *mrb, mrb_value self)
{
mrb_value argv;
mrb_value *argv;
mrb_int argc;
mrb_get_args(mrb, "o", &argv);
t_printstr(mrb, argv);
mrb_get_args(mrb, "*!", &argv, &argc);
for (mrb_int i = 0; i < argc; ++i) {
mrb_value s = mrb_obj_as_string(mrb, argv[i]);
fwrite(RSTRING_PTR(s), RSTRING_LEN(s), 1, stdout);
}
fflush(stdout);
return argv;
return mrb_nil_value();
}
void
......@@ -76,7 +68,7 @@ mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose)
struct RClass *krn, *mrbtest;
krn = mrb->kernel_module;
mrb_define_method(mrb, krn, "__t_printstr__", mrb_t_printstr, MRB_ARGS_REQ(1));
mrb_define_method(mrb, krn, "t_print", t_print, MRB_ARGS_ANY());
mrbtest = mrb_define_module(mrb, "Mrbtest");
......
......@@ -5,14 +5,12 @@ $skip_test = 0
$asserts = []
$test_start = Time.now if Object.const_defined?(:Time)
# Implementation of print due to the reason that there might be no print
def t_print(*args)
i = 0
len = args.size
while i < len
str = args[i].to_s
__t_printstr__ str rescue print str
i += 1
unless RUBY_ENGINE == "mruby"
# For bintest on Ruby
def t_print(*args)
print *args
$stdout.flush
nil
end
end
......@@ -110,8 +108,8 @@ def assert_not_equal(exp, act_or_msg = nil, msg = nil, &block)
assert_true(!ret, msg, diff)
end
def assert_same(*args); _assert_same(true, *args) end
def assert_not_same(*args); _assert_same(false, *args) end
def assert_same(*args); _assert_same(true, *args) end
def assert_not_same(*args); _assert_same(false, *args) end
def _assert_same(affirmed, exp, act, msg = nil)
unless ret = exp.equal?(act) == affirmed
exp_str, act_str = [exp, act].map do |o|
......
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