Permalink
Browse files

Added my idea of a sanity check against MRI for compatibility purposes

- try it out!
- rake spec:compatibility
- example compatibility expressions go in spec/compatibility/expressions/*
- all the expression files are line-separated ruby expressions that return something basic and eval-able
  • Loading branch information...
1 parent bfba119 commit cdfdc272b71bbfca23b4c17e5572ebd2b966615e Mae committed Dec 26, 2006
View
@@ -25,7 +25,8 @@ namespace :spec do
end
desc "Run only specs but not any tests."
- task :only => ['spec:language', 'spec:shotgun', 'spec:library']
+ task :only => ['spec:language', 'spec:shotgun', 'spec:library',
+ 'spec:compatibility']
desc "Run the language specs."
Spec::Rake::SpecTask.new(:language) do |t|
@@ -49,6 +50,11 @@ namespace :spec do
Spec::Rake::SpecTask.new(:targets) do |t|
t.spec_files = FileList['spec/targets/*_spec.rb']
end
+
+ desc "Run the specs for the MRI Compatibility"
+ Spec::Rake::SpecTask.new(:compatibility) do |t|
+ t.spec_files = FileList['spec/compatibility/*_spec.rb']
+ end
end unless no_spec
desc "Alias for test:all"
@@ -0,0 +1,12 @@
+require 'spec/compatibility/target_context_extension'
+
+context "A Rubinius Interpreter" do
+ extend TargetContextExtension
+
+ files = Dir['spec/compatibility/expressions/*']
+ expressions = files.collect do |file|
+ open(file).read.split("\n")
+ end.flatten
+ generate_specifications(expressions)
+end
+
@@ -0,0 +1,8 @@
+2 + 2
+[1,2,3] == [1,2,3]
+[1,2,3] == [2,1,3]
+[1,2,3] == [3,2,1]
+ENV
+"foo" == 'foo'
+'foo' == "foo"
+
@@ -0,0 +1,37 @@
+require 'rubygems'
+require 'spec'
+require 'tempfile'
+
+MRI = '/usr/bin/env ruby'
+SHOTGUN = 'shotgun/rubinius'
+RCOMPILE = 'bin/rcompile'
+
+module TargetContextExtension
+ def rubinius_target(path)
+ `#{RCOMPILE} #{path}`
+ eval(`#{SHOTGUN} lib/kernel.rbc #{path}.rbc`)
+ end
+
+ def mri_target(path)
+ eval(`#{MRI} #{path}`)
+ end
+
+ def target_rvals_for(expressions)
+ expressions.each do |exp|
+ t = Tempfile.new('ruby_test_expression')
+ t.write "p(#{exp})"
+ t.close
+ yield exp, rubinius_target(t.path), mri_target(t.path)
+ t.unlink
+ end
+ end
+
+ def generate_specifications(expressions)
+ target_rvals_for(expressions) do |exp, rubinius, mri|
+ specify "should evaluate '#{exp}' the same way as MRI" do
+ rubinius.should == mri
+ end
+ end
+ end
+end
+

0 comments on commit cdfdc27

Please sign in to comment.