Commit 7c813a9e authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #802 from carsonmcdonald/mrbgemstestpassargs

Add ability to pass parameters from mrbgem.rake spec into test scripts.
parents a5fbaf17 c1ca6621
...@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec| ...@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
# spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb") # spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb")
# spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } # spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
# spec.test_preload = 'test/assert.rb' # spec.test_preload = 'test/assert.rb'
# Values accessible as TEST_ARGS inside test scripts
# spec.test_args = {'tmp_dir' => Dir::tmpdir}
end end
...@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('c_extension_example') do |spec| ...@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('c_extension_example') do |spec|
# spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb") # spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb")
# spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } # spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
# spec.test_preload = 'test/assert.rb' # spec.test_preload = 'test/assert.rb'
# Values accessible as TEST_ARGS inside test scripts
# spec.test_args = {'tmp_dir' => Dir::tmpdir}
end end
...@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('ruby_extension_example') do |spec| ...@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('ruby_extension_example') do |spec|
# spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb") # spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb")
# spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } # spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
# spec.test_preload = 'test/assert.rb' # spec.test_preload = 'test/assert.rb'
# Values accessible as TEST_ARGS inside test scripts
# spec.test_args = {'tmp_dir' => Dir::tmpdir}
end end
...@@ -22,7 +22,7 @@ module MRuby ...@@ -22,7 +22,7 @@ module MRuby
alias :author= :authors= alias :author= :authors=
attr_accessor :rbfiles, :objs attr_accessor :rbfiles, :objs
attr_accessor :test_objs, :test_rbfiles attr_accessor :test_objs, :test_rbfiles, :test_args
attr_accessor :test_preload attr_accessor :test_preload
attr_block MRuby::Build::COMMANDS attr_block MRuby::Build::COMMANDS
...@@ -54,6 +54,7 @@ module MRuby ...@@ -54,6 +54,7 @@ module MRuby
objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X")) objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X"))
end end
@test_preload = 'test/assert.rb' @test_preload = 'test/assert.rb'
@test_args = {}
instance_eval(&@initializer) instance_eval(&@initializer)
...@@ -140,6 +141,7 @@ module MRuby ...@@ -140,6 +141,7 @@ module MRuby
f.puts %Q[#include "mruby/proc.h"] f.puts %Q[#include "mruby/proc.h"]
f.puts %Q[#include "mruby/variable.h"] f.puts %Q[#include "mruby/variable.h"]
f.puts %Q[#include "mruby/array.h"] f.puts %Q[#include "mruby/array.h"]
f.puts %Q[#include "mruby/hash.h"]
end end
end # Specification end # Specification
......
...@@ -32,7 +32,17 @@ MRuby.each_target do ...@@ -32,7 +32,17 @@ MRuby.each_target do
f.puts %Q[ exit(0);] f.puts %Q[ exit(0);]
f.puts %Q[ }] f.puts %Q[ }]
f.puts %Q[ mrb_const_set(mrb2, mrb_obj_value(mrb2->object_class), mrb_intern(mrb2, "GEMNAME"), mrb_str_new(mrb2, "#{g.name}", #{g.name.length}));] f.puts %Q[ mrb_const_set(mrb2, mrb_obj_value(mrb2->object_class), mrb_intern(mrb2, "GEMNAME"), mrb_str_new(mrb2, "#{g.name}", #{g.name.length}));]
if not g.test_args.empty?
f.puts %Q[ mrb_value test_args_hash = mrb_hash_new_capa(mrb, #{g.test_args.length}); ]
g.test_args.each do |arg_name, arg_value|
escaped_arg_name = arg_name.gsub('\\', '\\\\\\\\').gsub('"', '\"')
escaped_arg_value = arg_value.gsub('\\', '\\\\\\\\').gsub('"', '\"')
f.puts %Q[ mrb_hash_set(mrb2, test_args_hash, mrb_str_new(mrb2, "#{escaped_arg_name.to_s}", #{escaped_arg_name.to_s.length}), mrb_str_new(mrb2, "#{escaped_arg_value.to_s}", #{escaped_arg_value.to_s.length})); ]
end
f.puts %Q[ mrb_const_set(mrb2, mrb_obj_value(mrb2->object_class), mrb_intern(mrb2, "TEST_ARGS"), test_args_hash); ]
end
f.puts %Q[ mrb_#{g.funcname}_gem_test(mrb2);] unless g.test_objs.empty? f.puts %Q[ mrb_#{g.funcname}_gem_test(mrb2);] unless g.test_objs.empty?
f.puts %Q[ mrb_load_irep(mrb2, gem_test_irep_#{g.funcname}_#{i});] f.puts %Q[ mrb_load_irep(mrb2, gem_test_irep_#{g.funcname}_#{i});]
......
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