• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

mrubyを超漢字で動作させる


Commit MetaInfo

Revisão4a6c651f82c2d416682e9729842d4fda6beee2bf (tree)
Hora2014-07-12 20:36:45
Autortake_cheeze <takechi101010@gmai...>
CommiterYukihiro "Matz" Matsumoto

Mensagem de Log

Run mrbgem and core tests on minimum dependencies.
Solves #2355.

In test drivers:
* Uses mrb_t_pass_result to check and pass test result to main mrb_state.
* Adds mrb_init_test_driver to init test mrb_state.

Mudança Sumário

Diff

--- a/mrbgems/mruby-enumerator/mrbgem.rake
+++ b/mrbgems/mruby-enumerator/mrbgem.rake
@@ -2,5 +2,6 @@ MRuby::Gem::Specification.new('mruby-enumerator') do |spec|
22 spec.license = 'MIT'
33 spec.author = 'mruby developers'
44 spec.add_dependency('mruby-fiber', :core => 'mruby-fiber')
5+ spec.add_dependency 'mruby-enum-ext', :core => 'mruby-enum-ext'
56 spec.summary = 'Enumerator class'
67 end
--- a/mrbgems/mruby-hash-ext/mrbgem.rake
+++ b/mrbgems/mruby-hash-ext/mrbgem.rake
@@ -2,4 +2,6 @@ MRuby::Gem::Specification.new('mruby-hash-ext') do |spec|
22 spec.license = 'MIT'
33 spec.author = 'mruby developers'
44 spec.summary = 'extensional Hash class'
5+ spec.add_dependency 'mruby-enum-ext', :core => 'mruby-enum-ext'
6+ spec.add_dependency 'mruby-array-ext', :core => 'mruby-array-ext'
57 end
--- a/mrbgems/mruby-numeric-ext/test/numeric.rb
+++ b/mrbgems/mruby-numeric-ext/test/numeric.rb
@@ -5,13 +5,8 @@ assert('Integer#chr') do
55 assert_equal("A", 65.chr)
66 assert_equal("B", 0x42.chr)
77
8- if "こんにちわ世界".size == 7 then
9- # UTF-8 gem is configured
10- assert_raise(RangeError) { 0x110000.chr }
11- else
12- # multibyte encoding (not support yet)
13- assert_raise(RangeError) { 256.chr }
14- end
8+ # multibyte encoding (not support yet)
9+ assert_raise(RangeError) { 256.chr }
1510 end
1611
1712 assert('Integer#div') do
--- a/tasks/mrbgem_spec.rake
+++ b/tasks/mrbgem_spec.rake
@@ -45,10 +45,6 @@ module MRuby
4545 MRuby::Gem.current = self
4646 end
4747
48- def run_test_in_other_mrb_state?
49- not test_preload.nil? or not test_objs.empty? or not test_args.empty?
50- end
51-
5248 def setup
5349 MRuby::Gem.current = self
5450 MRuby::Build::COMMANDS.each do |command|
@@ -184,13 +180,15 @@ module MRuby
184180 print_gem_comment(f)
185181 f.puts %Q[#include <stdlib.h>]
186182 f.puts %Q[#include "mruby.h"]
187- f.puts %Q[#include "mruby/array.h"]
188183 f.puts %Q[#include "mruby/irep.h"]
189- f.puts %Q[#include "mruby/string.h"]
190184 f.puts %Q[#include "mruby/variable.h"]
191185 f.puts %Q[#include "mruby/hash.h"] unless test_args.empty?
192186 end
193187
188+ def test_dependencies
189+ [@name]
190+ end
191+
194192 def version_ok?(req_versions)
195193 req_versions.map do |req|
196194 cmp, ver = req.split
@@ -290,7 +288,7 @@ module MRuby
290288 @ary.empty?
291289 end
292290
293- def check(build)
291+ def generate_gem_table
294292 gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res }
295293
296294 default_gems = []
@@ -335,9 +333,29 @@ module MRuby
335333 fail "Conflicts of gem `#{g.name}` found: #{cfls.join ', '}" unless cfls.empty?
336334 end
337335
338- class << gem_table
336+ gem_table
337+ end
338+
339+ def tsort_dependencies ary, table, all_dependency_listed = false
340+ unless all_dependency_listed
341+ left = ary.dup
342+ until left.empty?
343+ v = left.pop
344+ table[v].dependencies.each do |dep|
345+ left.push dep[:gem]
346+ ary.push dep[:gem]
347+ end
348+ end
349+ end
350+
351+ ary.uniq!
352+ table.instance_variable_set :@root_gems, ary
353+ class << table
339354 include TSort
340- alias tsort_each_node each_key
355+ def tsort_each_node &b
356+ @root_gems.each &b
357+ end
358+
341359 def tsort_each_child(n, &b)
342360 fetch(n).dependencies.each do |v|
343361 b.call v[:gem]
@@ -346,10 +364,16 @@ module MRuby
346364 end
347365
348366 begin
349- @ary = gem_table.tsort.map { |v| gem_table[v] }
367+ table.tsort.map { |v| table[v] }
350368 rescue TSort::Cyclic => e
351369 fail "Circular mrbgem dependency found: #{e.message}"
352370 end
371+ end
372+
373+ def check(build)
374+ gem_table = generate_gem_table
375+
376+ @ary = tsort_dependencies gem_table.keys, gem_table, true
353377
354378 each do |g|
355379 import_include_paths(g)
--- a/tasks/mrbgems_test.rake
+++ b/tasks/mrbgems_test.rake
@@ -1,16 +1,12 @@
11 MRuby.each_target do
2- no_mrb_open_test_gem = []
2+ gem_table = gems.generate_gem_table
33
44 gems.each do |g|
5- unless g.run_test_in_other_mrb_state?
6- no_mrb_open_test_gem << g
7- next
8- end
9-
105 test_rbobj = g.test_rbireps.ext(exts.object)
6+ dep_list = gems.tsort_dependencies g.test_dependencies, gem_table
117
128 file test_rbobj => g.test_rbireps
13- file g.test_rbireps => [g.test_rbfiles].flatten + [g.build.mrbcfile, __FILE__] do |t|
9+ file g.test_rbireps => [g.test_rbfiles].flatten + [File.join(g.dir, 'mrbgem.rake'), g.build.mrbcfile, __FILE__, "#{MRUBY_ROOT}/tasks/mrbgem_spec.rake"] do |t|
1410 open(t.name, 'w') do |f|
1511 g.print_gem_test_header(f)
1612 test_preload = g.test_preload and [g.dir, MRUBY_ROOT].map {|dir|
@@ -33,21 +29,32 @@ MRuby.each_target do
3329 g.build.mrbc.run f, rbfile, "gem_test_irep_#{g.funcname}_#{i}"
3430 end
3531 f.puts %Q[void mrb_#{g.funcname}_gem_test(mrb_state *mrb);] unless g.test_objs.empty?
32+ dep_list.each do |d|
33+ f.puts %Q[void GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb_state *mrb);]
34+ f.puts %Q[void GENERATED_TMP_mrb_#{d.funcname}_gem_final(mrb_state *mrb);]
35+ end
36+ f.puts %Q[void mrb_init_test_driver(mrb_state *mrb);]
37+ f.puts %Q[void mrb_t_pass_result(mrb_state *dst, mrb_state *src);]
3638 f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb) {]
3739 unless g.test_rbfiles.empty?
3840 f.puts %Q[ mrb_state *mrb2;]
3941 if g.test_args.empty?
40- f.puts %Q[ mrb_value val1, val2, val3, ary1, ary2;]
42+ f.puts %Q[ mrb_value verbose;]
4143 else
42- f.puts %Q[ mrb_value val1, val2, val3, ary1, ary2, test_args_hash;]
44+ f.puts %Q[ mrb_value verbose, test_args_hash;]
4345 end
4446 f.puts %Q[ int ai;]
4547 g.test_rbfiles.count.times do |i|
4648 f.puts %Q[ ai = mrb_gc_arena_save(mrb);]
47- f.puts %Q[ mrb2 = mrb_open();]
48- f.puts %Q[ val3 = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"));]
49- f.puts %Q[ if (mrb_test(val3)) {]
50- f.puts %Q[ mrb_gv_set(mrb2, mrb_intern_lit(mrb2, "$mrbtest_verbose"), val3);]
49+ f.puts %Q[ mrb2 = mrb_open_core(mrb_default_allocf, NULL);]
50+ dep_list.each do |d|
51+ f.puts %Q[ GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb2);]
52+ f.puts %Q[ mrb_state_atexit(mrb2, GENERATED_TMP_mrb_#{d.funcname}_gem_final);]
53+ end
54+ f.puts %Q[ mrb_init_test_driver(mrb2);]
55+ f.puts %Q[ verbose = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"));]
56+ f.puts %Q[ if (mrb_test(verbose)) {]
57+ f.puts %Q[ mrb_gv_set(mrb2, mrb_intern_lit(mrb2, "$mrbtest_verbose"), verbose);]
5158 f.puts %Q[ }]
5259 if test_preload.nil?
5360 f.puts %Q[ mrb_load_irep(mrb2, mrbtest_assert_irep);]
@@ -73,30 +80,9 @@ MRuby.each_target do
7380 f.puts %Q[ mrb_#{g.funcname}_gem_test(mrb2);] unless g.test_objs.empty?
7481
7582 f.puts %Q[ mrb_load_irep(mrb2, gem_test_irep_#{g.funcname}_#{i});]
76- f.puts %Q[ if (mrb2->exc) {]
77- f.puts %Q[ mrb_print_error(mrb2);]
78- f.puts %Q[ exit(EXIT_FAILURE);]
79- f.puts %Q[ }]
8083 f.puts %Q[ ]
8184
82- %w(ok_test ko_test kill_test).each do |vname|
83- f.puts %Q[ val2 = mrb_gv_get(mrb2, mrb_intern_lit(mrb2, "$#{vname}"));]
84- f.puts %Q[ if (mrb_fixnum_p(val2)) {]
85- f.puts %Q[ val1 = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$#{vname}"));]
86- f.puts %Q[ mrb_gv_set(mrb, mrb_intern_lit(mrb, "$#{vname}"), mrb_fixnum_value(mrb_fixnum(val1) + mrb_fixnum(val2)));]
87- f.puts %Q[ }\n]
88- end
89-
90- f.puts %Q[ ary2 = mrb_gv_get(mrb2, mrb_intern_lit(mrb2, "$asserts"));]
91- f.puts %Q[ if (mrb_test(ary2)) {]
92- f.puts %Q[ ary1 = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$asserts"));]
93- f.puts %Q[ val2 = mrb_ary_shift(mrb2, ary2);]
94- f.puts %Q[ ]
95- f.puts %Q[ while (mrb_test(val2)) {]
96- f.puts %Q[ mrb_ary_push(mrb, ary1, mrb_str_new(mrb, RSTRING_PTR(val2), RSTRING_LEN(val2)));]
97- f.puts %Q[ val2 = mrb_ary_shift(mrb2, ary2);]
98- f.puts %Q[ }]
99- f.puts %Q[ }]
85+ f.puts %Q[ mrb_t_pass_result(mrb, mrb2);]
10086 f.puts %Q[ mrb_close(mrb2);]
10187 f.puts %Q[ mrb_gc_arena_restore(mrb, ai);]
10288 end
@@ -104,44 +90,5 @@ MRuby.each_target do
10490 f.puts %Q[}]
10591 end
10692 end
107-
108- end
109-
110- no_mrb_open_test = "#{build_dir}/test/no_mrb_open_test"
111- no_mrb_open_test_rbfiles = no_mrb_open_test_gem.reduce([]) { |res, v|
112- res += v.test_rbfiles
113- }
114- if no_mrb_open_test_rbfiles.empty?
115- no_mrb_open_test_rbfiles << "#{MRUBY_ROOT}/test/no_mrb_open_test_dummy.rb"
116- end
117-
118- no_mrb_open_test_lib = no_mrb_open_test.ext(exts.object)
119- file no_mrb_open_test_lib => "#{no_mrb_open_test}.c"
120- file "#{no_mrb_open_test}.c" => no_mrb_open_test_rbfiles + [MRUBY_CONFIG, __FILE__] do |t|
121- open(t.name, 'w') do |f|
122- f.puts %Q[/*]
123- f.puts %Q[ * This file contains a test code for following gems:]
124- no_mrb_open_test_gem.each { |g| f.puts %Q[ * #{g.name}] }
125- f.puts %Q[ *]
126- f.puts %Q[ * IMPORTANT:]
127- f.puts %Q[ * This file was generated!]
128- f.puts %Q[ * All manual changes will get lost.]
129- f.puts %Q[ */]
130-
131- f.puts %Q[]
132-
133- f.puts %Q[\#include "mruby.h"]
134- f.puts %Q[\#include "mruby/irep.h"]
135-
136- f.puts %Q[]
137-
138- mrbc.run f, no_mrb_open_test_rbfiles, "no_mrb_open_gem_test_irep"
139-
140- f.puts %Q[]
141-
142- f.puts %Q[void no_mrb_open_mrbgem_test(mrb_state *mrb) {]
143- f.puts %Q[ mrb_load_irep(mrb, no_mrb_open_gem_test_irep);]
144- f.puts %Q[}]
145- end
14693 end
14794 end
--- a/test/driver.c
+++ b/test/driver.c
@@ -16,6 +16,7 @@
1616 #include "mruby/compile.h"
1717 #include "mruby/string.h"
1818 #include "mruby/variable.h"
19+#include "mruby/array.h"
1920
2021 void
2122 mrb_init_mrbtest(mrb_state *);
@@ -81,12 +82,62 @@ mrb_t_printstr(mrb_state *mrb, mrb_value self)
8182 return argv;
8283 }
8384
85+void
86+mrb_init_test_driver(mrb_state *mrb)
87+{
88+ struct RClass *krn, *mrbtest;
89+
90+ krn = mrb->kernel_module;
91+ mrb_define_method(mrb, krn, "__t_printstr__", mrb_t_printstr, MRB_ARGS_REQ(1));
92+
93+ mrbtest = mrb_define_module(mrb, "Mrbtest");
94+
95+ mrb_define_const(mrb, mrbtest, "FIXNUM_MAX", mrb_fixnum_value(MRB_INT_MAX));
96+ mrb_define_const(mrb, mrbtest, "FIXNUM_MIN", mrb_fixnum_value(MRB_INT_MIN));
97+ mrb_define_const(mrb, mrbtest, "FIXNUM_BIT", mrb_fixnum_value(MRB_INT_BIT));
98+}
99+
100+void
101+mrb_t_pass_result(mrb_state *mrb_dst, mrb_state *mrb_src)
102+{
103+ mrb_value res_src;
104+
105+ if (mrb_src->exc) {
106+ mrb_print_error(mrb_src);
107+ exit(EXIT_FAILURE);
108+ }
109+
110+#define TEST_COUNT_PASS(name) \
111+ do { \
112+ res_src = mrb_gv_get(mrb_src, mrb_intern_lit(mrb_src, "$" #name)); \
113+ if (mrb_fixnum_p(res_src)) { \
114+ mrb_value res_dst = mrb_gv_get(mrb_dst, mrb_intern_lit(mrb_dst, "$" #name)); \
115+ mrb_gv_set(mrb_dst, mrb_intern_lit(mrb_dst, "$" #name), mrb_fixnum_value(mrb_fixnum(res_dst) + mrb_fixnum(res_src))); \
116+ } \
117+ } while (FALSE) \
118+
119+ TEST_COUNT_PASS(ok_test);
120+ TEST_COUNT_PASS(ko_test);
121+ TEST_COUNT_PASS(kill_test);
122+
123+#undef TEST_COUNT_PASS
124+
125+ res_src = mrb_gv_get(mrb_src, mrb_intern_lit(mrb_src, "$asserts"));
126+
127+ if (mrb_array_p(res_src)) {
128+ mrb_int i;
129+ mrb_value res_dst = mrb_gv_get(mrb_dst, mrb_intern_lit(mrb_dst, "$asserts"));
130+ for (i = 0; i < RARRAY_LEN(res_src); ++i) {
131+ mrb_value val_src = RARRAY_PTR(res_src)[i];
132+ mrb_ary_push(mrb_dst, res_dst, mrb_str_new(mrb_dst, RSTRING_PTR(val_src), RSTRING_LEN(val_src)));
133+ }
134+ }
135+}
136+
84137 int
85138 main(int argc, char **argv)
86139 {
87140 mrb_state *mrb;
88- struct RClass *krn;
89- struct RClass *mrbtest;
90141 int ret;
91142
92143 print_hint();
@@ -103,15 +154,7 @@ main(int argc, char **argv)
103154 mrb_gv_set(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"), mrb_true_value());
104155 }
105156
106- krn = mrb->kernel_module;
107- mrb_define_method(mrb, krn, "__t_printstr__", mrb_t_printstr, MRB_ARGS_REQ(1));
108-
109- mrbtest = mrb_define_module(mrb, "Mrbtest");
110-
111- mrb_define_const(mrb, mrbtest, "FIXNUM_MAX", mrb_fixnum_value(MRB_INT_MAX));
112- mrb_define_const(mrb, mrbtest, "FIXNUM_MIN", mrb_fixnum_value(MRB_INT_MIN));
113- mrb_define_const(mrb, mrbtest, "FIXNUM_BIT", mrb_fixnum_value(MRB_INT_BIT));
114-
157+ mrb_init_test_driver(mrb);
115158 mrb_init_mrbtest(mrb);
116159 ret = eval_test(mrb);
117160 mrb_close(mrb);
--- a/test/init_mrbtest.c
+++ b/test/init_mrbtest.c
@@ -6,15 +6,26 @@ extern const uint8_t mrbtest_assert_irep[];
66 extern const uint8_t mrbtest_irep[];
77
88 void mrbgemtest_init(mrb_state* mrb);
9+void mrb_init_test_driver(mrb_state* mrb);
10+void mrb_t_pass_result(mrb_state *mrb_dst, mrb_state *mrb_src);
911
1012 void
1113 mrb_init_mrbtest(mrb_state *mrb)
1214 {
15+ mrb_state *core_test;
16+
1317 mrb_load_irep(mrb, mrbtest_assert_irep);
14- mrb_load_irep(mrb, mrbtest_irep);
18+
19+ core_test = mrb_open_core(mrb_default_allocf, NULL);
20+ mrb_init_test_driver(core_test);
21+ mrb_load_irep(core_test, mrbtest_assert_irep);
22+ mrb_load_irep(core_test, mrbtest_irep);
23+ mrb_t_pass_result(mrb, core_test);
24+
1525 #ifndef DISABLE_GEMS
1626 mrbgemtest_init(mrb);
1727 #endif
28+
1829 if (mrb->exc) {
1930 mrb_print_error(mrb);
2031 exit(EXIT_FAILURE);
--- a/test/mrbtest.rake
+++ b/test/mrbtest.rake
@@ -12,11 +12,12 @@ MRuby.each_target do
1212 ass_lib = ass_c.ext(exts.object)
1313
1414 mrbtest_lib = libfile("#{current_build_dir}/mrbtest")
15- gem_test_files = gems.select { |g| g.run_test_in_other_mrb_state? }.map { |g| g.test_rbireps.ext(exts.object) }
16- file mrbtest_lib => [mlib, ass_lib, gems.map(&:test_objs), gem_test_files].flatten do |t|
15+ mrbtest_objs = gems.map do |v|
16+ v.test_objs + [v.test_rbireps.ext(exts.object)]
17+ end
18+ file mrbtest_lib => [mlib, ass_lib] + mrbtest_objs do |t|
1719 archiver.run t.name, t.prerequisites
1820 end
19- file mrbtest_lib => "#{build_dir}/test/no_mrb_open_test.c".ext(exts.object)
2021
2122 unless build_mrbtest_lib_only?
2223 driver_obj = objfile("#{current_build_dir}/driver")
@@ -55,16 +56,12 @@ MRuby.each_target do
5556 f.puts IO.read(init)
5657 mrbc.run f, mrbs, 'mrbtest_irep'
5758 gems.each do |g|
58- next unless g.run_test_in_other_mrb_state?
5959 f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb);]
6060 end
61- f.puts %Q[void no_mrb_open_mrbgem_test(mrb_state *mrb);]
6261 f.puts %Q[void mrbgemtest_init(mrb_state* mrb) {]
6362 gems.each do |g|
64- next unless g.run_test_in_other_mrb_state?
6563 f.puts %Q[ GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb);]
6664 end
67- f.puts %Q[ no_mrb_open_mrbgem_test(mrb);]
6865 f.puts %Q[}]
6966 end
7067 end
--- a/test/no_mrb_open_test_dummy.rb
+++ /dev/null
@@ -1,2 +0,0 @@
1-#dummy
2-