Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly guard JIT specs.
Browse files Browse the repository at this point in the history
brixen committed Aug 30, 2015
1 parent 9dd6f73 commit c808b9b
Showing 4 changed files with 197 additions and 187 deletions.
140 changes: 71 additions & 69 deletions spec/jit/call_site_spec.rb
Original file line number Diff line number Diff line change
@@ -1,100 +1,102 @@
require File.expand_path("../spec_helper", __FILE__)

describe "JIT compiling a call site" do
context "to m()" do
before :each do
klass = Class.new do
def m() :m end
def call() m() end
with_feature :jit do
describe "JIT compiling a call site" do
context "to m()" do
before :each do
klass = Class.new do
def m() :m end
def call() m() end
end

@o = klass.new

jit(@o, :call) { @o.call }
end

@o = klass.new
it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end

jit(@o, :call) { @o.call }
it "returns the result of calling the method" do
@o.call.should equal(:m)
end
end

it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end
context "to m() defined in an included module" do
before :each do
mod = Module.new do
def m() :m end
end
klass = Class.new do
def call() m() end
include mod
end

it "returns the result of calling the method" do
@o.call.should equal(:m)
end
end
@o = klass.new

context "to m() defined in an included module" do
before :each do
mod = Module.new do
def m() :m end
end
klass = Class.new do
def call() m() end
include mod
jit(@o, :call) { @o.call }
end

@o = klass.new
it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end

jit(@o, :call) { @o.call }
it "returns the result of calling the included method" do
@o.call.should equal(:m)
end
end

it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end
context "to m() defined in a prepended module" do
before :each do

it "returns the result of calling the included method" do
@o.call.should equal(:m)
end
end
mod = Module.new do
def m() :m end
end
klass = Class.new do
def m() :shadowed end
def call() m() end
prepend mod
end

context "to m() defined in a prepended module" do
before :each do
o = @o = klass.new

mod = Module.new do
def m() :m end
end
klass = Class.new do
def m() :shadowed end
def call() m() end
prepend mod
jit(o, :call) { o.call }
end

o = @o = klass.new
it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end

jit(o, :call) { o.call }
it "returns the result of calling the prepended method" do
@o.call.should equal(:m)
end
end

it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end
context "to m() that calls super defined in a prepended module" do
before :each do

it "returns the result of calling the prepended method" do
@o.call.should equal(:m)
end
end
mod = Module.new do
def m() super; :m end
end
klass = Class.new do
def m() :shadowed end
def call() m() end
prepend mod
end

context "to m() that calls super defined in a prepended module" do
before :each do
o = @o = klass.new

mod = Module.new do
def m() super; :m end
end
klass = Class.new do
def m() :shadowed end
def call() m() end
prepend mod
jit(o, :call) { o.call }
end

o = @o = klass.new

jit(o, :call) { o.call }
end

it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end
it "compiles" do
@o.method(:call).executable.jitted?.should be_true
end

it "returns the result of calling the prepended method" do
@o.call.should equal(:m)
it "returns the result of calling the prepended method" do
@o.call.should equal(:m)
end
end
end
end
28 changes: 15 additions & 13 deletions spec/jit/instruction_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
require File.expand_path("../spec_helper", __FILE__)

describe "JIT compiling a string_dup instruction" do
before :each do
klass = Class.new do
def m() "abc" end
end
with_feature :jit do
describe "JIT compiling a string_dup instruction" do
before :each do
klass = Class.new do
def m() "abc" end
end

@o = klass.new
@o = klass.new

jit(@o, :m) { @o.m }
end
jit(@o, :m) { @o.m }
end

it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end
it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

it "dups the literal String" do
@o.method(:m).executable.literals[0].object_id.should_not equal(@o.m)
it "dups the literal String" do
@o.method(:m).executable.literals[0].object_id.should_not equal(@o.m)
end
end
end
212 changes: 107 additions & 105 deletions spec/jit/method_spec.rb
Original file line number Diff line number Diff line change
@@ -1,156 +1,158 @@
require File.expand_path("../spec_helper", __FILE__)

describe "JIT compiling a method call" do
context "to m()" do
before :each do
klass = Class.new do
def m() :m end
with_feature :jit do
describe "JIT compiling a method call" do
context "to m()" do
before :each do
klass = Class.new do
def m() :m end
end

@o = klass.new

jit(@o, :m) { @o.m }
end

@o = klass.new
it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

jit(@o, :m) { @o.m }
end
it "returns the last computed value" do
@o.m.should equal(:m)
end

it "compiles" do
@o.method(:m).executable.jitted?.should be_true
it "raises an ArgumentError if passed an argument" do
lambda { @o.m 5 }.should raise_error(ArgumentError)
end
end

it "returns the last computed value" do
@o.m.should equal(:m)
end
context "to m() without calling it" do
before :each do
klass = Class.new do
def m() :m end
end

it "raises an ArgumentError if passed an argument" do
lambda { @o.m 5 }.should raise_error(ArgumentError)
end
end
@o = klass.new

context "to m() without calling it" do
before :each do
klass = Class.new do
def m() :m end
jit(@o, :m)
end

@o = klass.new
it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

jit(@o, :m)
end
it "returns the last computed value" do
@o.m.should == :m
end

it "compiles" do
@o.method(:m).executable.jitted?.should be_true
it "raises an ArgumentError if passed an argument" do
lambda { @o.m 5 }.should raise_error(ArgumentError)
end
end

it "returns the last computed value" do
@o.m.should == :m
end
context "to m(a)" do
before :each do
klass = Class.new do
def m(a) a end
end

it "raises an ArgumentError if passed an argument" do
lambda { @o.m 5 }.should raise_error(ArgumentError)
end
end
@o = klass.new

context "to m(a)" do
before :each do
klass = Class.new do
def m(a) a end
jit(@o, :m) { @o.m 5 }
end

@o = klass.new
it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

jit(@o, :m) { @o.m 5 }
end
it "returns the passed argument" do
@o.m(:a).should == :a
end

it "compiles" do
@o.method(:m).executable.jitted?.should be_true
it "raises an ArgumentError when not passed an argument" do
lambda { @o.m }.should raise_error(ArgumentError)
end
end

it "returns the passed argument" do
@o.m(:a).should == :a
end
context "to m(*a)" do
before :each do
klass = Class.new do
def m(*a) a end
end

it "raises an ArgumentError when not passed an argument" do
lambda { @o.m }.should raise_error(ArgumentError)
end
end
@o = klass.new

context "to m(*a)" do
before :each do
klass = Class.new do
def m(*a) a end
jit(@o, :m) { @o.m }
end

@o = klass.new
it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

jit(@o, :m) { @o.m }
end
it "returns an empty Array when passed no argument" do
@o.m.should == []
end

it "compiles" do
@o.method(:m).executable.jitted?.should be_true
it "returns a one-element Array when passed one argument" do
@o.m(1).should == [1]
end
end

it "returns an empty Array when passed no argument" do
@o.m.should == []
end
context "to m(a: 0)" do
before :each do
klass = Class.new do
def m(a: 0) a end
end

it "returns a one-element Array when passed one argument" do
@o.m(1).should == [1]
end
end
@o = klass.new

context "to m(a: 0)" do
before :each do
klass = Class.new do
def m(a: 0) a end
jit(@o, :m) { @o.m }
end

@o = klass.new
it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

jit(@o, :m) { @o.m }
end
it "returns the default keyword value when passed no arguments" do
@o.m.should == 0
end

it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end
it "returns the passed value of the keyword" do
@o.m(a: 2).should == 2
end

it "returns the default keyword value when passed no arguments" do
@o.m.should == 0
end
it "raises an ArgumentError when passed a non-matching keyword argument" do
lambda { @o.m(b: 2) }.should raise_error(ArgumentError)
end

it "returns the passed value of the keyword" do
@o.m(a: 2).should == 2
it "raises an ArgumentError when passed extra keyword arguments" do
lambda { @o.m(a: 2, b: 3) }.should raise_error(ArgumentError)
end
end

it "raises an ArgumentError when passed a non-matching keyword argument" do
lambda { @o.m(b: 2) }.should raise_error(ArgumentError)
end
context "to m(a=1, **kw)" do
before :each do
klass = Class.new do
def m(a=1, **kw) [a, kw] end
end

it "raises an ArgumentError when passed extra keyword arguments" do
lambda { @o.m(a: 2, b: 3) }.should raise_error(ArgumentError)
end
end
@o = klass.new

context "to m(a=1, **kw)" do
before :each do
klass = Class.new do
def m(a=1, **kw) [a, kw] end
jit(@o, :m) { @o.m }
end

@o = klass.new

jit(@o, :m) { @o.m }
end

it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

context "when passed one argument" do
it "assigns Symbol keys to the keyword rest argument" do
@o.m(a: 1, b: 2).should == [1, {a: 1, b: 2}]
it "compiles" do
@o.method(:m).executable.jitted?.should be_true
end

it "assigns non-Symbol keys to the default argument" do
@o.m("a" => 1, b: 2).should == [{"a" => 1}, {b: 2}]
context "when passed one argument" do
it "assigns Symbol keys to the keyword rest argument" do
@o.m(a: 1, b: 2).should == [1, {a: 1, b: 2}]
end

it "assigns non-Symbol keys to the default argument" do
@o.m("a" => 1, b: 2).should == [{"a" => 1}, {b: 2}]
end
end
end
end
4 changes: 4 additions & 0 deletions spec/rbx.2.1.mspec
Original file line number Diff line number Diff line change
@@ -65,4 +65,8 @@ class MSpecScript
else
MSpec.enable_feature :hash_bucket
end

if Rubinius::JIT.enabled?
Mspec.enable_feature :jit
end
end

0 comments on commit c808b9b

Please sign in to comment.