diff options
Diffstat (limited to 'spec/rubyspec/core')
-rw-r--r-- | spec/rubyspec/core/bignum/bit_and_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubyspec/core/binding/eval_spec.rb | 10 | ||||
-rw-r--r-- | spec/rubyspec/core/binding/fixtures/classes.rb | 8 | ||||
-rw-r--r-- | spec/rubyspec/core/binding/local_variable_get_spec.rb | 11 | ||||
-rw-r--r-- | spec/rubyspec/core/binding/local_variable_set_spec.rb | 12 | ||||
-rw-r--r-- | spec/rubyspec/core/binding/shared/clone.rb | 28 | ||||
-rw-r--r-- | spec/rubyspec/core/fiber/yield_spec.rb | 15 | ||||
-rw-r--r-- | spec/rubyspec/core/file/fixtures/file_types.rb | 27 | ||||
-rw-r--r-- | spec/rubyspec/core/file/ftype_spec.rb | 6 | ||||
-rw-r--r-- | spec/rubyspec/core/file/stat/ftype_spec.rb | 7 | ||||
-rw-r--r-- | spec/rubyspec/core/fixnum/bit_and_spec.rb | 15 | ||||
-rw-r--r-- | spec/rubyspec/core/io/advise_spec.rb | 21 | ||||
-rw-r--r-- | spec/rubyspec/core/process/exec_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubyspec/core/process/spawn_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubyspec/core/time/minus_spec.rb | 6 |
15 files changed, 137 insertions, 41 deletions
diff --git a/spec/rubyspec/core/bignum/bit_and_spec.rb b/spec/rubyspec/core/bignum/bit_and_spec.rb index 6eca0e56f0..4bc5c11e1b 100644 --- a/spec/rubyspec/core/bignum/bit_and_spec.rb +++ b/spec/rubyspec/core/bignum/bit_and_spec.rb @@ -16,8 +16,8 @@ describe "Bignum#&" do end it "returns self bitwise AND other when one operand is negative" do - ((2*bignum_value) & -1).should == 18446744073709551616 - ((4*bignum_value) & -1).should == 36893488147419103232 + ((2*bignum_value) & -1).should == (2*bignum_value) + ((4*bignum_value) & -1).should == (4*bignum_value) (@bignum & -0xffffffffffffff5).should == 9223372036854775809 (@bignum & -@bignum).should == 1 (@bignum & -0x8000000000000000).should == 9223372036854775808 diff --git a/spec/rubyspec/core/binding/eval_spec.rb b/spec/rubyspec/core/binding/eval_spec.rb index cedd5fcdf9..4864b9f61f 100644 --- a/spec/rubyspec/core/binding/eval_spec.rb +++ b/spec/rubyspec/core/binding/eval_spec.rb @@ -13,6 +13,16 @@ describe "Binding#eval" do bind.eval("Inside.name").should == "BindingSpecs::Demo::Inside" end + it "does not leak variables to cloned bindings" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_empty_binding + bind2 = bind.dup + + bind.eval("x = 72") + bind.local_variables.should == [:x] + bind2.local_variables.should == [] + end + describe "with a file given" do it "does not store the filename permanently" do obj = BindingSpecs::Demo.new(1) diff --git a/spec/rubyspec/core/binding/fixtures/classes.rb b/spec/rubyspec/core/binding/fixtures/classes.rb index b7b7618411..05ca2479ba 100644 --- a/spec/rubyspec/core/binding/fixtures/classes.rb +++ b/spec/rubyspec/core/binding/fixtures/classes.rb @@ -28,5 +28,13 @@ module BindingSpecs def get_empty_binding binding end + + def get_binding_in_block + a = true + 1.times do + b = false + return binding + end + end end end diff --git a/spec/rubyspec/core/binding/local_variable_get_spec.rb b/spec/rubyspec/core/binding/local_variable_get_spec.rb index b7b0b14594..e65d08130e 100644 --- a/spec/rubyspec/core/binding/local_variable_get_spec.rb +++ b/spec/rubyspec/core/binding/local_variable_get_spec.rb @@ -42,4 +42,15 @@ describe "Binding#local_variable_get" do bind.local_variable_get(:number).should == 10 end + + it "raises a NameError on global access" do + bind = binding + lambda { bind.local_variable_get(:$0) }.should raise_error(NameError) + end + + it "raises a NameError on special variable access" do + bind = binding + lambda { bind.local_variable_get(:$~) }.should raise_error(NameError) + lambda { bind.local_variable_get(:$_) }.should raise_error(NameError) + end end diff --git a/spec/rubyspec/core/binding/local_variable_set_spec.rb b/spec/rubyspec/core/binding/local_variable_set_spec.rb index 4b14d891b3..067dcbd03e 100644 --- a/spec/rubyspec/core/binding/local_variable_set_spec.rb +++ b/spec/rubyspec/core/binding/local_variable_set_spec.rb @@ -56,4 +56,16 @@ describe "Binding#local_variable_set" do bind.local_variable_set(:number, 20) bind.local_variable_get(:number).should == 20 end + + it "raises a NameError on global access" do + bind = binding + lambda { bind.local_variable_set(:$0, "") }.should raise_error(NameError) + end + + it "raises a NameError on special variable access" do + bind = binding + lambda { bind.local_variable_set(:$~, "") }.should raise_error(NameError) + lambda { bind.local_variable_set(:$_, "") }.should raise_error(NameError) + end + end diff --git a/spec/rubyspec/core/binding/shared/clone.rb b/spec/rubyspec/core/binding/shared/clone.rb index 723e0490c3..0e934ac1b5 100644 --- a/spec/rubyspec/core/binding/shared/clone.rb +++ b/spec/rubyspec/core/binding/shared/clone.rb @@ -2,19 +2,33 @@ describe :binding_clone, shared: true do before :each do @b1 = BindingSpecs::Demo.new(99).get_binding @b2 = @b1.send(@method) + @b3 = BindingSpecs::Demo.new(99).get_binding_in_block + @b4 = @b3.send(@method) end it "returns a copy of the Binding object" do - @b1.should_not == @b2 + [[@b1, @b2, "a"], + [@b3, @b4, "a", "b"]].each do |b1, b2, *vars| + b1.should_not == b2 - eval("@secret", @b1).should == eval("@secret", @b2) - eval("square(2)", @b1).should == eval("square(2)", @b2) - eval("self.square(2)", @b1).should == eval("self.square(2)", @b2) - eval("a", @b1).should == eval("a", @b2) + eval("@secret", b1).should == eval("@secret", b2) + eval("square(2)", b1).should == eval("square(2)", b2) + eval("self.square(2)", b1).should == eval("self.square(2)", b2) + vars.each do |v| + eval("#{v}", b1).should == eval("#{v}", b2) + end + end end it "is a shallow copy of the Binding object" do - eval("a = false", @b1) - eval("a", @b2).should == false + [[@b1, @b2, "a"], + [@b3, @b4, "a", "b"]].each do |b1, b2, *vars| + vars.each do |v| + eval("#{v} = false", b1) + eval("#{v}", b2).should == false + end + b1.local_variable_set(:x, 37) + b2.local_variable_defined?(:x).should == false + end end end diff --git a/spec/rubyspec/core/fiber/yield_spec.rb b/spec/rubyspec/core/fiber/yield_spec.rb index 45054e9cec..e433da0aa9 100644 --- a/spec/rubyspec/core/fiber/yield_spec.rb +++ b/spec/rubyspec/core/fiber/yield_spec.rb @@ -29,6 +29,21 @@ with_feature :fiber do fiber.resume :caller end + it "does not propagate or reraise a rescued exception" do + fiber = Fiber.new do + begin + raise "an error in a Fiber" + rescue + Fiber.yield :first + end + + :second + end + + fiber.resume.should == :first + fiber.resume.should == :second + end + it "raises a FiberError if called from the root Fiber" do lambda{ Fiber.yield }.should raise_error(FiberError) end diff --git a/spec/rubyspec/core/file/fixtures/file_types.rb b/spec/rubyspec/core/file/fixtures/file_types.rb index 1c446b33a6..36a5ff1a95 100644 --- a/spec/rubyspec/core/file/fixtures/file_types.rb +++ b/spec/rubyspec/core/file/fixtures/file_types.rb @@ -1,6 +1,7 @@ module FileSpecs - # Try to set up known locations of each filetype - def self.reconfigure() + def self.configure_types + return if @configured + @file = tmp("test.txt") @dir = Dir.pwd @fifo = tmp("test_fifo") @@ -15,45 +16,43 @@ module FileSpecs @link = links.first break end - end - end - # TODO: Automatic reload mechanism - reconfigure + @configured = true + end - def self.normal_file() - File.open(@file, "w") {} # 'Touch' + def self.normal_file + touch(@file) yield @file ensure rm_r @file end - def self.directory() + def self.directory yield @dir end # TODO: need a platform-independent helper here - def self.fifo() + def self.fifo system "mkfifo #{@fifo} 2> /dev/null" yield @fifo ensure rm_r @fifo end - def self.block_device() + def self.block_device yield @block end - def self.character_device() + def self.character_device yield @char end - def self.symlink() + def self.symlink yield @link end - def self.socket() + def self.socket require 'socket' name = tmp("ftype_socket.socket") rm_r name diff --git a/spec/rubyspec/core/file/ftype_spec.rb b/spec/rubyspec/core/file/ftype_spec.rb index 79ed1d5b45..7c010b3e9c 100644 --- a/spec/rubyspec/core/file/ftype_spec.rb +++ b/spec/rubyspec/core/file/ftype_spec.rb @@ -1,7 +1,11 @@ require "#{File.dirname(__FILE__)}/../../spec_helper" -require "#{File.dirname(__FILE__)}/fixtures/file_types.rb" +require "#{File.dirname(__FILE__)}/fixtures/file_types" describe "File.ftype" do + before :all do + FileSpecs.configure_types + end + it "raises ArgumentError if not given exactly one filename" do lambda { File.ftype }.should raise_error(ArgumentError) lambda { File.ftype('blah', 'bleh') }.should raise_error(ArgumentError) diff --git a/spec/rubyspec/core/file/stat/ftype_spec.rb b/spec/rubyspec/core/file/stat/ftype_spec.rb index c20109765b..588c371c39 100644 --- a/spec/rubyspec/core/file/stat/ftype_spec.rb +++ b/spec/rubyspec/core/file/stat/ftype_spec.rb @@ -1,7 +1,11 @@ require "#{File.dirname(__FILE__)}/../../../spec_helper" -require "#{File.dirname(__FILE__)}/../fixtures/file_types.rb" +require "#{File.dirname(__FILE__)}/../fixtures/file_types" describe "File::Stat#ftype" do + before :all do + FileSpecs.configure_types + end + it "returns a String" do FileSpecs.normal_file do |file| File.lstat(file).ftype.should be_kind_of(String) @@ -62,4 +66,3 @@ describe "File::Stat#ftype" do end end end - diff --git a/spec/rubyspec/core/fixnum/bit_and_spec.rb b/spec/rubyspec/core/fixnum/bit_and_spec.rb index 17fd8f81f5..ff0e597a52 100644 --- a/spec/rubyspec/core/fixnum/bit_and_spec.rb +++ b/spec/rubyspec/core/fixnum/bit_and_spec.rb @@ -8,6 +8,21 @@ describe "Fixnum#&" do (0xffff & bignum_value + 0xffff_ffff).should == 65535 end + it "returns self bitwise AND other when one operand is negative" do + ((1 << 33) & -1).should == (1 << 33) + (-1 & (1 << 33)).should == (1 << 33) + + ((-(1<<33)-1) & 5).should == 5 + (5 & (-(1<<33)-1)).should == 5 + end + + it "returns self bitwise AND other when both operands are negative" do + (-5 & -1).should == -5 + (-3 & -4).should == -4 + (-12 & -13).should == -16 + (-13 & -12).should == -16 + end + it "returns self bitwise AND a Bignum" do (-1 & 2**64).should == 18446744073709551616 end diff --git a/spec/rubyspec/core/io/advise_spec.rb b/spec/rubyspec/core/io/advise_spec.rb index bd3bf24bec..460b50a59d 100644 --- a/spec/rubyspec/core/io/advise_spec.rb +++ b/spec/rubyspec/core/io/advise_spec.rb @@ -74,16 +74,17 @@ describe "IO#advise" do end platform_is :linux do - require 'etc' - uname = if Etc.respond_to?(:uname) - Etc.uname[:release] - else - `uname -r`.chomp - end - if (uname.split('.').map(&:to_i) <=> [3,6]) < 0 - # [ruby-core:65355] tmpfs is not supported - else - it "supports the willneed advice type" do + it "supports the willneed advice type" do + require 'etc' + uname = if Etc.respond_to?(:uname) + Etc.uname[:release] + else + `uname -r`.chomp + end + if (uname.split('.').map(&:to_i) <=> [3,6]) < 0 + # [ruby-core:65355] tmpfs is not supported + 1.should == 1 + else @io.advise(:willneed).should be_nil end end diff --git a/spec/rubyspec/core/process/exec_spec.rb b/spec/rubyspec/core/process/exec_spec.rb index baf9d81c10..b4eddf526e 100644 --- a/spec/rubyspec/core/process/exec_spec.rb +++ b/spec/rubyspec/core/process/exec_spec.rb @@ -22,7 +22,9 @@ describe "Process.exec" do platform_is :windows do it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do - lambda { Process.exec __FILE__ }.should raise_error(->(e){[Errno::EACCES, Errno::ENOEXEC].find{|exc| exc === e}}) + lambda { Process.exec __FILE__ }.should raise_error(SystemCallError) { |e| + [Errno::EACCES, Errno::ENOEXEC].should include(e.class) + } end end end diff --git a/spec/rubyspec/core/process/spawn_spec.rb b/spec/rubyspec/core/process/spawn_spec.rb index bd3d13f97e..66b5c5e402 100644 --- a/spec/rubyspec/core/process/spawn_spec.rb +++ b/spec/rubyspec/core/process/spawn_spec.rb @@ -576,7 +576,9 @@ describe "Process.spawn" do platform_is :windows do it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do - lambda { Process.spawn __FILE__ }.should raise_error(->(e){[Errno::EACCES, Errno::ENOEXEC].find{|exc| exc === e}}) + lambda { Process.spawn __FILE__ }.should raise_error(SystemCallError) { |e| + [Errno::EACCES, Errno::ENOEXEC].should include(e.class) + } end end end diff --git a/spec/rubyspec/core/time/minus_spec.rb b/spec/rubyspec/core/time/minus_spec.rb index e4363e2467..4e2bb60333 100644 --- a/spec/rubyspec/core/time/minus_spec.rb +++ b/spec/rubyspec/core/time/minus_spec.rb @@ -41,7 +41,7 @@ describe "Time#-" do time.usec.should == 123456 end - it "tracks microseconds" do + it "tracks microseconds from a Rational" do time = Time.at(Rational(777_777, 1_000_000)) time -= Rational(654_321, 1_000_000) time.usec.should == 123_456 @@ -63,12 +63,12 @@ describe "Time#-" do end it "maintains microseconds precision" do - time = Time.at(10) - Rational(1_000_000_000_000_001, 1_000_000_000_000_000) + time = Time.at(10) - Rational(1, 1_000_000) time.usec.should == 999_999 end it "maintains nanoseconds precision" do - time = Time.at(10) - Rational(1_000_000_000_000_001, 1_000_000_000_000_000) + time = Time.at(10) - Rational(1, 1_000_000_000) time.nsec.should == 999_999_999 end |