summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCarson McDonald <[email protected]>2013-01-29 21:54:03 -0500
committerCarson McDonald <[email protected]>2013-01-29 22:03:29 -0500
commit79f802365f02c242fd104664e97431bd8f18001c (patch)
tree3cd9bafaea58e0a717e1c971fa2e40a46c745079
parente43216c45d537b456e8225b66e0c10b0703b31a0 (diff)
downloadmruby-79f802365f02c242fd104664e97431bd8f18001c.tar.gz
mruby-79f802365f02c242fd104664e97431bd8f18001c.zip
Add ability to pass parameters from mrbgem.rake spec into test scripts.
-rw-r--r--examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake3
-rw-r--r--examples/mrbgems/c_extension_example/mrbgem.rake3
-rw-r--r--examples/mrbgems/ruby_extension_example/mrbgem.rake3
-rw-r--r--tasks/mrbgem_spec.rake4
-rw-r--r--tasks/mrbgems_test.rake10
5 files changed, 21 insertions, 2 deletions
diff --git a/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake b/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
index 88f7b31f6..067aa2cba 100644
--- a/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
+++ b/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
@@ -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_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'
+
+ # Values accessible as $test_args inside test scripts
+ # spec.test_args = {'tmp_dir' => Dir::tmpdir}
end
diff --git a/examples/mrbgems/c_extension_example/mrbgem.rake b/examples/mrbgems/c_extension_example/mrbgem.rake
index e19121df4..f56564222 100644
--- a/examples/mrbgems/c_extension_example/mrbgem.rake
+++ b/examples/mrbgems/c_extension_example/mrbgem.rake
@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('c_extension_example') do |spec|
# 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_preload = 'test/assert.rb'
+
+ # Values accessible as $test_args inside test scripts
+ # spec.test_args = {'tmp_dir' => Dir::tmpdir}
end
diff --git a/examples/mrbgems/ruby_extension_example/mrbgem.rake b/examples/mrbgems/ruby_extension_example/mrbgem.rake
index da0ad73a8..4429460e9 100644
--- a/examples/mrbgems/ruby_extension_example/mrbgem.rake
+++ b/examples/mrbgems/ruby_extension_example/mrbgem.rake
@@ -17,4 +17,7 @@ MRuby::Gem::Specification.new('ruby_extension_example') do |spec|
# 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_preload = 'test/assert.rb'
+
+ # Values accessible as $test_args inside test scripts
+ # spec.test_args = {'tmp_dir' => Dir::tmpdir}
end
diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake
index 49e45bbc9..daf4410de 100644
--- a/tasks/mrbgem_spec.rake
+++ b/tasks/mrbgem_spec.rake
@@ -22,7 +22,7 @@ module MRuby
alias :author= :authors=
attr_accessor :rbfiles, :objs
- attr_accessor :test_objs, :test_rbfiles
+ attr_accessor :test_objs, :test_rbfiles, :test_args
attr_accessor :test_preload
attr_block MRuby::Build::COMMANDS
@@ -54,6 +54,7 @@ module MRuby
objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X"))
end
@test_preload = 'test/assert.rb'
+ @test_args = {}
instance_eval(&@initializer)
@@ -140,6 +141,7 @@ module MRuby
f.puts %Q[#include "mruby/proc.h"]
f.puts %Q[#include "mruby/variable.h"]
f.puts %Q[#include "mruby/array.h"]
+ f.puts %Q[#include "mruby/hash.h"]
end
end # Specification
diff --git a/tasks/mrbgems_test.rake b/tasks/mrbgems_test.rake
index cb00aba57..bc263c80e 100644
--- a/tasks/mrbgems_test.rake
+++ b/tasks/mrbgems_test.rake
@@ -32,7 +32,15 @@ MRuby.each_target do
f.puts %Q[ exit(0);]
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}));]
-
+
+ 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|
+ f.puts %Q[ mrb_hash_set(mrb2, test_args_hash, mrb_str_new(mrb2, "#{arg_name.to_s}", #{arg_name.to_s.length}), mrb_str_new(mrb2, "#{arg_value.to_s}", #{arg_value.to_s.length})); ]
+ end
+ f.puts %Q[ mrb_gv_set(mrb2, 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_load_irep(mrb2, gem_test_irep_#{g.funcname}_#{i});]