Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1239 from bovi/fallback-print

[TestEnv] Fallback print method
  • Loading branch information...
commit 25b8ae96ab4a71edf03812154aac84907bf2c4a7 2 parents 8e45630 + 72f7831
@matz matz authored
Showing with 58 additions and 23 deletions.
  1. +27 −23 test/assert.rb
  2. +31 −0 test/driver.c
View
50 test/assert.rb
@@ -4,6 +4,20 @@
$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
+ begin
+ __printstr__ args[i].to_s
+ rescue NoMethodError
+ __t_printstr__ args[i].to_s
+ end
+ i += 1
+ end
+end
+
##
# Create the assertion in a readable way
def assertion_string(err, str, iso=nil, e=nil)
@@ -28,31 +42,31 @@ def assertion_string(err, str, iso=nil, e=nil)
# which will be tested by this
# assertion
def assert(str = 'Assertion failed', iso = '')
- print(str, (iso != '' ? " [#{iso}]" : ''), ' : ') if $mrbtest_verbose
+ t_print(str, (iso != '' ? " [#{iso}]" : ''), ' : ') if $mrbtest_verbose
begin
$mrbtest_assert = []
$mrbtest_assert_idx = 0
if(!yield || $mrbtest_assert.size > 0)
$asserts.push(assertion_string('Fail: ', str, iso, nil))
$ko_test += 1
- print('F')
+ t_print('F')
else
$ok_test += 1
- print('.')
+ t_print('.')
end
rescue Exception => e
if e.class.to_s == 'MRubyTestSkip'
$asserts.push "Skip: #{str} #{iso} #{e.cause}"
- print('?')
+ t_print('?')
else
$asserts.push(assertion_string('Error: ', str, iso, e))
$kill_test += 1
- print('X')
+ t_print('X')
end
ensure
$mrbtest_assert = nil
end
- print("\n") if $mrbtest_verbose
+ t_print("\n") if $mrbtest_verbose
end
def assertion_diff(exp, act)
@@ -125,31 +139,21 @@ def assert_raise(*exp)
# Report the test result and print all assertions
# which were reported broken.
def report()
- print "\n"
+ t_print("\n")
$asserts.each do |msg|
puts msg
end
$total_test = $ok_test.+($ko_test)
- print('Total: ')
- print($total_test)
- print("\n")
-
- print(' OK: ')
- print($ok_test)
- print("\n")
- print(' KO: ')
- print($ko_test)
- print("\n")
- print('Crash: ')
- print($kill_test)
- print("\n")
+ t_print("Total: #{$total_test}\n")
+
+ t_print(" OK: #{$ok_test}\n")
+ t_print(" KO: #{$ko_test}\n")
+ t_print("Crash: #{$kill_test}\n")
if Object.const_defined?(:Time)
- print(' Time: ')
- print(Time.now - $test_start)
- print(" seconds\n")
+ t_print(" Time: #{Time.now - $test_start} seconds\n")
end
end
View
31 test/driver.c
@@ -14,6 +14,7 @@
#include <mruby/proc.h>
#include <mruby/data.h>
#include <mruby/compile.h>
+#include <mruby/string.h>
#include <mruby/variable.h>
void
@@ -59,10 +60,37 @@ eval_test(mrb_state *mrb)
return EXIT_SUCCESS;
}
+static void
+t_printstr(mrb_state *mrb, mrb_value obj)
+{
+ struct RString *str;
+ char *s;
+ int len;
+
+ if (mrb_string_p(obj)) {
+ str = mrb_str_ptr(obj);
+ s = str->ptr;
+ len = str->len;
+ fwrite(s, len, 1, stdout);
+ }
+}
+
+mrb_value
+mrb_t_printstr(mrb_state *mrb, mrb_value self)
+{
+ mrb_value argv;
+
+ mrb_get_args(mrb, "o", &argv);
+ t_printstr(mrb, argv);
+
+ return argv;
+}
+
int
main(int argc, char **argv)
{
mrb_state *mrb;
+ struct RClass *krn;
int ret;
print_hint();
@@ -79,6 +107,9 @@ main(int argc, char **argv)
mrb_gv_set(mrb, mrb_intern(mrb, "$mrbtest_verbose"), mrb_true_value());
}
+ krn = mrb->kernel_module;
+ mrb_define_method(mrb, krn, "__t_printstr__", mrb_t_printstr, MRB_ARGS_REQ(1));
+
mrb_init_mrbtest(mrb);
ret = eval_test(mrb);
mrb_close(mrb);
Please sign in to comment.
Something went wrong with that request. Please try again.