Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e21e4e133e38
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d3d918af43fc
Choose a head ref
  • 5 commits
  • 31 files changed
  • 2 contributors

Commits on Jul 27, 2017

  1. Squashed 'spec/mspec/' changes from 021a119..353605f

    353605f Add a small script to search for multi-line regexp patterns
    ea7600d Implement #guard and #guard_not to combine guards
    9c56e03 Add specs for SpecGuard#{run_if,run_unless}
    f1ddbbd Use stub_const in PlatformGuard specs
    e5d30e3 Remove unused file
    aa5a51b Fix a typo
    d8e4d0c Require to pass a maximum value for MSpecScript#cores
    
    git-subtree-dir: spec/mspec
    git-subtree-split: 353605f0266f344d784231a7b24a2444c3255285
    eregon committed Jul 27, 2017
    Copy the full SHA
    b7f09a5 View commit details
  2. Copy the full SHA
    ffbd2b8 View commit details
  3. Squashed 'spec/ruby/' changes from 86090df..c3e6b90

    c3e6b90 Avoid nested platform_is_not guards in Process#setrlimit spec
    25d17e1 Use #guard in String#unpack('lL')
    734643b Use #guard in IO#close_on_exec{=,?} spec and unshare specs
    8f8a787 Use #guard in pack('lL') spec
    cb5c619 Use #guard instead of if for pack('J') spec
    5afae7c Used a fixed seed in Random#rand spec
    1746e3a [spec] add some BigDecimal#to_r specs
    5b3c045 Fix spec for StringScanner#peek and check for a byte slice
    c8e9070 Add spec for String#{[],slice,byteslice} with a too large index or length
    d361f81 Add spec for the encoding of the result of String#{slice,[]}
    c171890 Simplify and just use int for the return value of rb_io_wait_readable
    908b2c5 Save and restore errno in rb_io_wait_readable spec
    fc04747 Try to fix race in rb_thread_call_without_gvl spec
    010a0be Fix C-API globals spec to not block if the sub-thread dies
    063de5b Add additional Numeric#step specs
    be77411 Simplify spec for invalid break from another thread
    8da1d68 Ensure that LocalJumpError comes from Thread#value instead of break
    60f2d29 Avoid repeating scratchpad symbols in method
    837f04b Add spec for an invalid break from another thread
    d2f0a3b Fix race in ThreadSpecs.status_of_dying_thread_after_sleep
    1332d7b Initialize $foo before spec
    e891a28 Suppress intended warning
    bfcbf9a Add specs for a Thread status after it is killed, then sleeping and woken up
    764f99e Fix copy/paste error in Thread#inspect spec
    75a88c2 Restore thread status aborting specs
    c4cf24a Remove Gemfile.lock
    79ed474 Use https instead of git protocol
    
    git-subtree-dir: spec/ruby
    git-subtree-split: c3e6b9017926f44a76e2b966c4dd35fa84c4cd3b
    eregon committed Jul 27, 2017
    Copy the full SHA
    fa78f58 View commit details
  4. Copy the full SHA
    8246886 View commit details

Commits on Aug 5, 2017

  1. Copy the full SHA
    d3d918a View commit details
28 changes: 26 additions & 2 deletions spec/mspec/lib/mspec/guards/guard.rb
Original file line number Diff line number Diff line change
@@ -76,14 +76,22 @@ def yield?(invert = false)

def run_if(name, &block)
@name = name
yield if yield?(false)
if block
yield if yield?(false)
else
yield?(false)
end
ensure
unregister
end

def run_unless(name, &block)
@name = name
yield if yield?(true)
if block
yield if yield?(true)
else
yield?(true)
end
ensure
unregister
end
@@ -115,3 +123,19 @@ def match?
raise "must be implemented by the subclass"
end
end

# Combined guards

def guard(condition, &block)
raise "condition must be a Proc" unless condition.is_a?(Proc)
raise LocalJumpError, "no block given" unless block
return yield if MSpec.mode? :unguarded or MSpec.mode? :verify or MSpec.mode? :report
yield if condition.call
end

def guard_not(condition, &block)
raise "condition must be a Proc" unless condition.is_a?(Proc)
raise LocalJumpError, "no block given" unless block
return yield if MSpec.mode? :unguarded or MSpec.mode? :verify or MSpec.mode? :report
yield unless condition.call
end
2 changes: 1 addition & 1 deletion spec/mspec/lib/mspec/matchers/base.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ class MSpecEnv
include MSpecMatchers
end

# Expactations are sometimes used in a module body
# Expectations are sometimes used in a module body
class Module
include MSpecMatchers
end
2 changes: 1 addition & 1 deletion spec/mspec/lib/mspec/utils/script.rb
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ def files_from_patterns(patterns)
files patterns
end

def cores(max = 1)
def cores(max)
require 'etc'
[Etc.nprocessors, max].min
end
246 changes: 246 additions & 0 deletions spec/mspec/spec/guards/guard_spec.rb
Original file line number Diff line number Diff line change
@@ -178,3 +178,249 @@
]
end
end

describe SpecGuard, ".run_if" do
before :each do
@guard = SpecGuard.new
ScratchPad.clear
end

it "yields if match? returns true" do
@guard.stub(:match?).and_return(true)
@guard.run_if(:name) { ScratchPad.record :yield }
ScratchPad.recorded.should == :yield
end

it "does not yield if match? returns false" do
@guard.stub(:match?).and_return(false)
@guard.run_if(:name) { fail }
end

it "returns the result of the block if match? is true" do
@guard.stub(:match?).and_return(true)
@guard.run_if(:name) { 42 }.should == 42
end

it "returns nil if given a block and match? is false" do
@guard.stub(:match?).and_return(false)
@guard.run_if(:name) { 42 }.should == nil
end

it "returns what #match? returns when no block is given" do
@guard.stub(:match?).and_return(true)
@guard.run_if(:name).should == true
@guard.stub(:match?).and_return(false)
@guard.run_if(:name).should == false
end
end

describe SpecGuard, ".run_unless" do
before :each do
@guard = SpecGuard.new
ScratchPad.clear
end

it "yields if match? returns false" do
@guard.stub(:match?).and_return(false)
@guard.run_unless(:name) { ScratchPad.record :yield }
ScratchPad.recorded.should == :yield
end

it "does not yield if match? returns true" do
@guard.stub(:match?).and_return(true)
@guard.run_unless(:name) { fail }
end

it "returns the result of the block if match? is false" do
@guard.stub(:match?).and_return(false)
@guard.run_unless(:name) { 42 }.should == 42
end

it "returns nil if given a block and match? is true" do
@guard.stub(:match?).and_return(true)
@guard.run_unless(:name) { 42 }.should == nil
end

it "returns the opposite of what #match? returns when no block is given" do
@guard.stub(:match?).and_return(true)
@guard.run_unless(:name).should == false
@guard.stub(:match?).and_return(false)
@guard.run_unless(:name).should == true
end
end

describe Object, "#guard" do
before :each do
ScratchPad.clear
end

after :each do
MSpec.clear_modes
end

it "allows to combine guards" do
guard1 = VersionGuard.new 'x.x.x'
VersionGuard.stub(:new).and_return(guard1)
guard2 = PlatformGuard.new :dummy
PlatformGuard.stub(:new).and_return(guard2)

guard1.stub(:match?).and_return(true)
guard2.stub(:match?).and_return(true)
guard -> { ruby_version_is "2.4" and platform_is :linux } do
ScratchPad.record :yield
end
ScratchPad.recorded.should == :yield

guard1.stub(:match?).and_return(false)
guard2.stub(:match?).and_return(true)
guard -> { ruby_version_is "2.4" and platform_is :linux } do
fail
end

guard1.stub(:match?).and_return(true)
guard2.stub(:match?).and_return(false)
guard -> { ruby_version_is "2.4" and platform_is :linux } do
fail
end

guard1.stub(:match?).and_return(false)
guard2.stub(:match?).and_return(false)
guard -> { ruby_version_is "2.4" and platform_is :linux } do
fail
end
end

it "yields when the Proc returns true" do
guard -> { true } do
ScratchPad.record :yield
end
ScratchPad.recorded.should == :yield
end

it "does not yield when the Proc returns false" do
guard -> { false } do
fail
end
end

it "yields if MSpec.mode?(:unguarded) is true" do
MSpec.register_mode :unguarded

guard -> { false } do
ScratchPad.record :yield1
end
ScratchPad.recorded.should == :yield1

guard -> { true } do
ScratchPad.record :yield2
end
ScratchPad.recorded.should == :yield2
end

it "yields if MSpec.mode?(:verify) is true" do
MSpec.register_mode :verify

guard -> { false } do
ScratchPad.record :yield1
end
ScratchPad.recorded.should == :yield1

guard -> { true } do
ScratchPad.record :yield2
end
ScratchPad.recorded.should == :yield2
end

it "yields if MSpec.mode?(:report) is true" do
MSpec.register_mode :report

guard -> { false } do
ScratchPad.record :yield1
end
ScratchPad.recorded.should == :yield1

guard -> { true } do
ScratchPad.record :yield2
end
ScratchPad.recorded.should == :yield2
end

it "raises an error if no Proc is given" do
-> { guard :foo }.should raise_error(RuntimeError)
end

it "requires a block" do
-> {
guard(-> { true })
}.should raise_error(LocalJumpError)
-> {
guard(-> { false })
}.should raise_error(LocalJumpError)
end
end

describe Object, "#guard_not" do
before :each do
ScratchPad.clear
end

it "allows to combine guards" do
guard1 = VersionGuard.new 'x.x.x'
VersionGuard.stub(:new).and_return(guard1)
guard2 = PlatformGuard.new :dummy
PlatformGuard.stub(:new).and_return(guard2)

guard1.stub(:match?).and_return(true)
guard2.stub(:match?).and_return(true)
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
fail
end

guard1.stub(:match?).and_return(false)
guard2.stub(:match?).and_return(true)
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
ScratchPad.record :yield1
end
ScratchPad.recorded.should == :yield1

guard1.stub(:match?).and_return(true)
guard2.stub(:match?).and_return(false)
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
ScratchPad.record :yield2
end
ScratchPad.recorded.should == :yield2

guard1.stub(:match?).and_return(false)
guard2.stub(:match?).and_return(false)
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
ScratchPad.record :yield3
end
ScratchPad.recorded.should == :yield3
end

it "yields when the Proc returns false" do
guard_not -> { false } do
ScratchPad.record :yield
end
ScratchPad.recorded.should == :yield
end

it "does not yield when the Proc returns true" do
guard_not -> { true } do
fail
end
end

it "raises an error if no Proc is given" do
-> { guard_not :foo }.should raise_error(RuntimeError)
end

it "requires a block" do
-> {
guard_not(-> { true })
}.should raise_error(LocalJumpError)
-> {
guard_not(-> { false })
}.should raise_error(LocalJumpError)
end
end
51 changes: 24 additions & 27 deletions spec/mspec/spec/guards/platform_spec.rb
Original file line number Diff line number Diff line change
@@ -20,6 +20,13 @@
ScratchPad.recorded.should == :yield
end

it "returns what #os? returns when no block is given" do
PlatformGuard.stub(:os?).and_return(true)
platform_is(:solarce).should == true
PlatformGuard.stub(:os?).and_return(false)
platform_is(:solarce).should == false
end

it "sets the name of the guard to :platform_is" do
platform_is(:solarce) { }
@guard.name.should == :platform_is
@@ -53,6 +60,13 @@
ScratchPad.recorded.should == :yield
end

it "returns the opposite of what #os? returns when no block is given" do
PlatformGuard.stub(:os?).and_return(true)
platform_is_not(:solarce).should == false
PlatformGuard.stub(:os?).and_return(false)
platform_is_not(:solarce).should == true
end

it "sets the name of the guard to :platform_is_not" do
platform_is_not(:solarce) { }
@guard.name.should == :platform_is_not
@@ -110,66 +124,49 @@
end

describe PlatformGuard, ".implementation?" do
before :all do
@verbose = $VERBOSE
$VERBOSE = nil
end

after :all do
$VERBOSE = @verbose
end

before :each do
@ruby_engine = Object.const_get :RUBY_ENGINE
end

after :each do
Object.const_set :RUBY_ENGINE, @ruby_engine
end

it "returns true if passed :ruby and RUBY_ENGINE == 'ruby'" do
Object.const_set :RUBY_ENGINE, 'ruby'
stub_const 'RUBY_ENGINE', 'ruby'
PlatformGuard.implementation?(:ruby).should == true
end

it "returns true if passed :rubinius and RUBY_ENGINE == 'rbx'" do
Object.const_set :RUBY_ENGINE, 'rbx'
stub_const 'RUBY_ENGINE', 'rbx'
PlatformGuard.implementation?(:rubinius).should == true
end

it "returns true if passed :jruby and RUBY_ENGINE == 'jruby'" do
Object.const_set :RUBY_ENGINE, 'jruby'
stub_const 'RUBY_ENGINE', 'jruby'
PlatformGuard.implementation?(:jruby).should == true
end

it "returns true if passed :ironruby and RUBY_ENGINE == 'ironruby'" do
Object.const_set :RUBY_ENGINE, 'ironruby'
stub_const 'RUBY_ENGINE', 'ironruby'
PlatformGuard.implementation?(:ironruby).should == true
end

it "returns true if passed :maglev and RUBY_ENGINE == 'maglev'" do
Object.const_set :RUBY_ENGINE, 'maglev'
stub_const 'RUBY_ENGINE', 'maglev'
PlatformGuard.implementation?(:maglev).should == true
end

it "returns true if passed :topaz and RUBY_ENGINE == 'topaz'" do
Object.const_set :RUBY_ENGINE, 'topaz'
stub_const 'RUBY_ENGINE', 'topaz'
PlatformGuard.implementation?(:topaz).should == true
end

it "returns true if passed :ruby and RUBY_ENGINE matches /^ruby/" do
Object.const_set :RUBY_ENGINE, 'ruby'
stub_const 'RUBY_ENGINE', 'ruby'
PlatformGuard.implementation?(:ruby).should == true

Object.const_set :RUBY_ENGINE, 'ruby1.8'
stub_const 'RUBY_ENGINE', 'ruby1.8'
PlatformGuard.implementation?(:ruby).should == true

Object.const_set :RUBY_ENGINE, 'ruby1.9'
stub_const 'RUBY_ENGINE', 'ruby1.9'
PlatformGuard.implementation?(:ruby).should == true
end

it "raises an error when passed an unrecognized name" do
Object.const_set :RUBY_ENGINE, 'ruby'
stub_const 'RUBY_ENGINE', 'ruby'
lambda {
PlatformGuard.implementation?(:python)
}.should raise_error(/unknown implementation/)
7 changes: 7 additions & 0 deletions spec/mspec/spec/guards/version_spec.rb
Original file line number Diff line number Diff line change
@@ -68,6 +68,13 @@
ScratchPad.recorded.should_not == :yield
end

it "returns what #match? returns when no block is given" do
@guard.stub(:match?).and_return(true)
ruby_version_is('x.x.x').should == true
@guard.stub(:match?).and_return(false)
ruby_version_is('x.x.x').should == false
end

it "sets the name of the guard to :ruby_version_is" do
ruby_version_is("") { }
@guard.name.should == :ruby_version_is
10 changes: 10 additions & 0 deletions spec/mspec/tool/find.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby
Dir.chdir('../rubyspec') do
regexp = Regexp.new(ARGV[0])
Dir.glob('**/*.rb') do |file|
contents = File.read(file)
if regexp =~ contents
puts file
end
end
end
4 changes: 0 additions & 4 deletions spec/mspec/tool/sync/sync.yml

This file was deleted.

2 changes: 1 addition & 1 deletion spec/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'

gem 'mspec', :github => 'ruby/mspec'
gem 'mspec', :git => 'https://github.com/ruby/mspec'
18 changes: 0 additions & 18 deletions spec/ruby/Gemfile.lock

This file was deleted.

4 changes: 2 additions & 2 deletions spec/ruby/core/array/pack/j_spec.rb
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
# To handle the special case of x64-mingw32
pointer_size = RUBY_PLATFORM =~ /\bx64\b/ ? 64 : 1.size * 8

if pointer_size == 64 then
guard -> { pointer_size == 64 } do
describe "Array#pack with format 'J'" do
it_behaves_like :array_pack_basic, 'J'
it_behaves_like :array_pack_basic_non_float, 'J'
@@ -114,7 +114,7 @@
end
end

if pointer_size == 32 then
guard -> { pointer_size == 32 } do
describe "Array#pack with format 'J'" do
it_behaves_like :array_pack_basic, 'J'
it_behaves_like :array_pack_basic_non_float, 'J'
216 changes: 64 additions & 152 deletions spec/ruby/core/array/pack/l_spec.rb
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
it_behaves_like :array_pack_32bit_be, 'L>'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'L<_'
it_behaves_like :array_pack_32bit_le, 'L_<'
@@ -51,49 +51,25 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'L<_'
it_behaves_like :array_pack_64bit_le, 'L_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'L<!'
it_behaves_like :array_pack_64bit_le, 'L!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'L>_'
it_behaves_like :array_pack_64bit_be, 'L_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'L>!'
it_behaves_like :array_pack_64bit_be, 'L!>'
end
end

platform_is :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'L<_'
it_behaves_like :array_pack_32bit_le, 'L_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_32bit_le, 'L<!'
it_behaves_like :array_pack_32bit_le, 'L!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_32bit_be, 'L>_'
it_behaves_like :array_pack_32bit_be, 'L_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_32bit_be, 'L>!'
it_behaves_like :array_pack_32bit_be, 'L!>'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'L<_'
it_behaves_like :array_pack_64bit_le, 'L_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'L<!'
it_behaves_like :array_pack_64bit_le, 'L!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'L>_'
it_behaves_like :array_pack_64bit_be, 'L_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'L>!'
it_behaves_like :array_pack_64bit_be, 'L!>'
end
end
end
@@ -107,7 +83,7 @@
it_behaves_like :array_pack_32bit_be, 'l>'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'l<_'
it_behaves_like :array_pack_32bit_le, 'l_<'
@@ -129,49 +105,25 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'l<_'
it_behaves_like :array_pack_64bit_le, 'l_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'l<!'
it_behaves_like :array_pack_64bit_le, 'l!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'l>_'
it_behaves_like :array_pack_64bit_be, 'l_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'l>!'
it_behaves_like :array_pack_64bit_be, 'l!>'
end
end

platform_is :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'l<_'
it_behaves_like :array_pack_32bit_le, 'l_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_32bit_le, 'l<!'
it_behaves_like :array_pack_32bit_le, 'l!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_32bit_be, 'l>_'
it_behaves_like :array_pack_32bit_be, 'l_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_32bit_be, 'l>!'
it_behaves_like :array_pack_32bit_be, 'l!>'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'l<_'
it_behaves_like :array_pack_64bit_le, 'l_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :array_pack_64bit_le, 'l<!'
it_behaves_like :array_pack_64bit_le, 'l!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :array_pack_64bit_be, 'l>_'
it_behaves_like :array_pack_64bit_be, 'l_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :array_pack_64bit_be, 'l>!'
it_behaves_like :array_pack_64bit_be, 'l!>'
end
end
end
@@ -185,7 +137,7 @@
it_behaves_like :array_pack_32bit_le, 'l'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'L_'
end
@@ -203,41 +155,21 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'L_'
end

describe "Array#pack with format 'L' with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'L!'
end

describe "Array#pack with format 'l' with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'l_'
end

describe "Array#pack with format 'l' with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'l!'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'L_'
end

platform_is :mingw32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'L_'
end

describe "Array#pack with format 'L' with modifier '!'" do
it_behaves_like :array_pack_32bit_le, 'L!'
end
describe "Array#pack with format 'L' with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'L!'
end

describe "Array#pack with format 'l' with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'l_'
end
describe "Array#pack with format 'l' with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'l_'
end

describe "Array#pack with format 'l' with modifier '!'" do
it_behaves_like :array_pack_32bit_le, 'l!'
end
describe "Array#pack with format 'l' with modifier '!'" do
it_behaves_like :array_pack_64bit_le, 'l!'
end
end
end
@@ -251,7 +183,7 @@
it_behaves_like :array_pack_32bit_be, 'l'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'L_'
end
@@ -269,41 +201,21 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'L_'
end

describe "Array#pack with format 'L' with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'L!'
end

describe "Array#pack with format 'l' with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'l_'
end

describe "Array#pack with format 'l' with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'l!'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'L_'
end

platform_is :mingw32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'L_'
end

describe "Array#pack with format 'L' with modifier '!'" do
it_behaves_like :array_pack_32bit_be, 'L!'
end
describe "Array#pack with format 'L' with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'L!'
end

describe "Array#pack with format 'l' with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'l_'
end
describe "Array#pack with format 'l' with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'l_'
end

describe "Array#pack with format 'l' with modifier '!'" do
it_behaves_like :array_pack_32bit_be, 'l!'
end
describe "Array#pack with format 'l' with modifier '!'" do
it_behaves_like :array_pack_64bit_be, 'l!'
end
end
end
137 changes: 58 additions & 79 deletions spec/ruby/core/io/close_on_exec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe :io_close_on_exec, shared: true do
it "sets the close-on-exec flag if true" do
@io.close_on_exec = true
@io.close_on_exec?.should == true
end

it "sets the close-on-exec flag if non-false" do
@io.close_on_exec = :true
@io.close_on_exec?.should == true
end

it "unsets the close-on-exec flag if false" do
@io.close_on_exec = true
@io.close_on_exec = false
@io.close_on_exec?.should == false
end

it "unsets the close-on-exec flag if nil" do
@io.close_on_exec = true
@io.close_on_exec = nil
@io.close_on_exec?.should == false
end

it "ensures the IO's file descriptor is closed in exec'ed processes" do
require 'fcntl'
@io.close_on_exec = true
(@io.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC).should == Fcntl::FD_CLOEXEC
end

it "raises IOError if called on a closed IO" do
@io.close
lambda { @io.close_on_exec = true }.should raise_error(IOError)
end

it "returns nil" do
@io.send(:close_on_exec=, true).should be_nil
end
end

describe "IO#close_on_exec=" do
before :each do
@name = tmp('io_close_on_exec.txt')
@@ -50,47 +11,59 @@
rm_r @name
end

platform_is :windows do
ruby_version_is ""..."2.3" do
it "returns false from #respond_to?" do
@io.respond_to?(:close_on_exec=).should be_false
end

it "raises a NotImplementedError when called" do
lambda { @io.close_on_exec = true }.should raise_error(NotImplementedError)
end
guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
it "returns false from #respond_to?" do
@io.respond_to?(:close_on_exec=).should be_false
end

ruby_version_is "2.3" do
it_should_behave_like :io_close_on_exec
it "raises a NotImplementedError when called" do
lambda { @io.close_on_exec = true }.should raise_error(NotImplementedError)
end
end

platform_is_not :windows do
it_should_behave_like :io_close_on_exec
end
end
guard -> { platform_is_not :windows or ruby_version_is "2.3" } do
it "sets the close-on-exec flag if true" do
@io.close_on_exec = true
@io.close_on_exec?.should == true
end

it "sets the close-on-exec flag if non-false" do
@io.close_on_exec = :true
@io.close_on_exec?.should == true
end

describe :io_is_close_on_exec, shared: true do
it "returns true by default" do
@io.close_on_exec?.should == true
end
it "unsets the close-on-exec flag if false" do
@io.close_on_exec = true
@io.close_on_exec = false
@io.close_on_exec?.should == false
end

it "returns true if set" do
@io.close_on_exec = true
@io.close_on_exec?.should == true
end
it "unsets the close-on-exec flag if nil" do
@io.close_on_exec = true
@io.close_on_exec = nil
@io.close_on_exec?.should == false
end

it "ensures the IO's file descriptor is closed in exec'ed processes" do
require 'fcntl'
@io.close_on_exec = true
(@io.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC).should == Fcntl::FD_CLOEXEC
end

it "raises IOError if called on a closed IO" do
@io.close
lambda { @io.close_on_exec = true }.should raise_error(IOError)
end

it "raises IOError if called on a closed IO" do
@io.close
lambda { @io.close_on_exec? }.should raise_error(IOError)
it "returns nil" do
@io.send(:close_on_exec=, true).should be_nil
end
end
end

describe "IO#close_on_exec?" do
before :each do
@name = tmp('io_close_on_exec.txt')
@name = tmp('io_is_close_on_exec.txt')
@io = new_io @name
end

@@ -99,23 +72,29 @@
rm_r @name
end

platform_is :windows do
ruby_version_is ""..."2.3" do
it "returns false from #respond_to?" do
@io.respond_to?(:close_on_exec?).should be_false
end

it "raises a NotImplementedError when called" do
lambda { @io.close_on_exec? }.should raise_error(NotImplementedError)
end
guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
it "returns false from #respond_to?" do
@io.respond_to?(:close_on_exec?).should be_false
end

ruby_version_is "2.3" do
it_should_behave_like :io_close_on_exec
it "raises a NotImplementedError when called" do
lambda { @io.close_on_exec? }.should raise_error(NotImplementedError)
end
end

platform_is_not :windows do
it_should_behave_like :io_is_close_on_exec
guard -> { platform_is_not :windows or ruby_version_is "2.3" } do
it "returns true by default" do
@io.close_on_exec?.should == true
end

it "returns true if set" do
@io.close_on_exec = true
@io.close_on_exec?.should == true
end

it "raises IOError if called on a closed IO" do
@io.close
lambda { @io.close_on_exec? }.should raise_error(IOError)
end
end
end
14 changes: 13 additions & 1 deletion spec/ruby/core/numeric/step_spec.rb
Original file line number Diff line number Diff line change
@@ -65,6 +65,10 @@
describe "when no block is given" do
describe "returned Enumerator" do
describe "size" do
it "should return infinity_value when limit is nil" do
1.step(by: 42).size.should == infinity_value
end

it "should return infinity_value when step is 0" do
1.step(to: 5, by: 0).size.should == infinity_value
end
@@ -73,13 +77,21 @@
1.step(to: 2, by: 0.0).size.should == infinity_value
end

it "should return infinity_value when the limit is Float::INFINITY" do
it "should return infinity_value when ascending towards a limit of Float::INFINITY" do
1.step(to: Float::INFINITY, by: 42).size.should == infinity_value
end

it "should return infinity_value when decending towards a limit of -Float::INFINITY" do
1.step(to: -Float::INFINITY, by: -42).size.should == infinity_value
end

it "should return 1 when the both limit and step are Float::INFINITY" do
1.step(to: Float::INFINITY, by: Float::INFINITY).size.should == 1
end

it "should return 1 when the both limit and step are -Float::INFINITY" do
1.step(to: -Float::INFINITY, by: -Float::INFINITY).size.should == 1
end
end
end
end
20 changes: 10 additions & 10 deletions spec/ruby/core/process/setrlimit_spec.rb
Original file line number Diff line number Diff line change
@@ -73,13 +73,13 @@
Process.setrlimit(:STACK, *Process.getrlimit(Process::RLIMIT_STACK)).should be_nil
end

platform_is_not :solaris do
platform_is_not :aix do
it "coerces :MEMLOCK into RLIMIT_MEMLOCK" do
Process.setrlimit(:MEMLOCK, *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil
end
platform_is_not :solaris, :aix do
it "coerces :MEMLOCK into RLIMIT_MEMLOCK" do
Process.setrlimit(:MEMLOCK, *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil
end
end

platform_is_not :solaris do
it "coerces :NPROC into RLIMIT_NPROC" do
Process.setrlimit(:NPROC, *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil
end
@@ -155,13 +155,13 @@
Process.setrlimit("STACK", *Process.getrlimit(Process::RLIMIT_STACK)).should be_nil
end

platform_is_not :solaris do
platform_is_not :aix do
it "coerces 'MEMLOCK' into RLIMIT_MEMLOCK" do
Process.setrlimit("MEMLOCK", *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil
end
platform_is_not :solaris, :aix do
it "coerces 'MEMLOCK' into RLIMIT_MEMLOCK" do
Process.setrlimit("MEMLOCK", *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil
end
end

platform_is_not :solaris do
it "coerces 'NPROC' into RLIMIT_NPROC" do
Process.setrlimit("NPROC", *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil
end
4 changes: 2 additions & 2 deletions spec/ruby/core/random/rand_spec.rb
Original file line number Diff line number Diff line change
@@ -172,13 +172,13 @@
end

it "works with inclusive ranges" do
prng = Random.new
prng = Random.new 33
r = 3..5
40.times.map { prng.rand(r) }.uniq.sort.should == [3,4,5]
end

it "works with exclusive ranges" do
prng = Random.new
prng = Random.new 33
r = 3...5
20.times.map { prng.rand(r) }.uniq.sort.should == [3,4]
end
24 changes: 24 additions & 0 deletions spec/ruby/core/string/shared/slice.rb
Original file line number Diff line number Diff line change
@@ -29,6 +29,10 @@
lambda { "hello".send(@method, {}) }.should raise_error(TypeError)
lambda { "hello".send(@method, []) }.should raise_error(TypeError)
end

it "raises a RangeError if the index is too big" do
lambda { "hello".send(@method, bignum_value) }.should raise_error(RangeError)
end
end

describe :string_slice_index_length, shared: true do
@@ -85,6 +89,21 @@
str.send(@method, 2,1).tainted?.should == true
end

it "returns a string with the same encoding" do
s = "hello there"
s.send(@method, 1, 9).encoding.should == s.encoding

a = "hello".force_encoding("binary")
b = " there".force_encoding("ISO-8859-1")
c = (a + b).force_encoding(Encoding::US_ASCII)

c.send(@method, 0, 5).encoding.should == Encoding::US_ASCII
c.send(@method, 5, 6).encoding.should == Encoding::US_ASCII
c.send(@method, 1, 3).encoding.should == Encoding::US_ASCII
c.send(@method, 8, 2).encoding.should == Encoding::US_ASCII
c.send(@method, 1, 10).encoding.should == Encoding::US_ASCII
end

it "returns nil if the offset falls outside of self" do
"hello there".send(@method, 20,3).should == nil
"hello there".send(@method, -20,3).should == nil
@@ -135,6 +154,11 @@
lambda { "hello".send(@method, nil, nil) }.should raise_error(TypeError)
end

it "raises a RangeError if the index or length is too big" do
lambda { "hello".send(@method, bignum_value, 1) }.should raise_error(RangeError)
lambda { "hello".send(@method, 0, bignum_value) }.should raise_error(RangeError)
end

it "returns subclass instances" do
s = StringSpecs::MyString.new("hello")
s.send(@method, 0,0).should be_an_instance_of(StringSpecs::MyString)
305 changes: 97 additions & 208 deletions spec/ruby/core/string/unpack/l_spec.rb
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
it_behaves_like :string_unpack_32bit_be_unsigned, 'L>'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'L<_'
it_behaves_like :string_unpack_32bit_le, 'L_<'
@@ -44,65 +44,33 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'L<_'
it_behaves_like :string_unpack_64bit_le, 'L_<'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L<_'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :string_unpack_64bit_le, 'L<!'
it_behaves_like :string_unpack_64bit_le, 'L!<'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L<!'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :string_unpack_64bit_be, 'L>_'
it_behaves_like :string_unpack_64bit_be, 'L_>'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L>_'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :string_unpack_64bit_be, 'L>!'
it_behaves_like :string_unpack_64bit_be, 'L!>'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L>!'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L!>'
end
end

platform_is :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'L<_'
it_behaves_like :string_unpack_32bit_le, 'L_<'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L<_'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :string_unpack_32bit_le, 'L<!'
it_behaves_like :string_unpack_32bit_le, 'L!<'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L<!'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :string_unpack_32bit_be, 'L>_'
it_behaves_like :string_unpack_32bit_be, 'L_>'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L>_'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :string_unpack_32bit_be, 'L>!'
it_behaves_like :string_unpack_32bit_be, 'L!>'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L>!'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L!>'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'L<_'
it_behaves_like :string_unpack_64bit_le, 'L_<'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L<_'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :string_unpack_64bit_le, 'L<!'
it_behaves_like :string_unpack_64bit_le, 'L!<'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L<!'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :string_unpack_64bit_be, 'L>_'
it_behaves_like :string_unpack_64bit_be, 'L_>'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L>_'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :string_unpack_64bit_be, 'L>!'
it_behaves_like :string_unpack_64bit_be, 'L!>'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L>!'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L!>'
end
end
end
@@ -118,7 +86,7 @@
it_behaves_like :string_unpack_32bit_be_signed, 'l>'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'l<_'
it_behaves_like :string_unpack_32bit_le, 'l_<'
@@ -148,65 +116,33 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'l<_'
it_behaves_like :string_unpack_64bit_le, 'l_<'
it_behaves_like :string_unpack_64bit_le_signed, 'l<_'
it_behaves_like :string_unpack_64bit_le_signed, 'l_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :string_unpack_64bit_le, 'l<!'
it_behaves_like :string_unpack_64bit_le, 'l!<'
it_behaves_like :string_unpack_64bit_le_signed, 'l<!'
it_behaves_like :string_unpack_64bit_le_signed, 'l!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :string_unpack_64bit_be, 'l>_'
it_behaves_like :string_unpack_64bit_be, 'l_>'
it_behaves_like :string_unpack_64bit_be_signed, 'l>_'
it_behaves_like :string_unpack_64bit_be_signed, 'l_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :string_unpack_64bit_be, 'l>!'
it_behaves_like :string_unpack_64bit_be, 'l!>'
it_behaves_like :string_unpack_64bit_be_signed, 'l>!'
it_behaves_like :string_unpack_64bit_be_signed, 'l!>'
end
end

platform_is :mingw32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'l<_'
it_behaves_like :string_unpack_32bit_le, 'l_<'
it_behaves_like :string_unpack_32bit_le_signed, 'l<_'
it_behaves_like :string_unpack_32bit_le_signed, 'l_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :string_unpack_32bit_le, 'l<!'
it_behaves_like :string_unpack_32bit_le, 'l!<'
it_behaves_like :string_unpack_32bit_le_signed, 'l<!'
it_behaves_like :string_unpack_32bit_le_signed, 'l!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :string_unpack_32bit_be, 'l>_'
it_behaves_like :string_unpack_32bit_be, 'l_>'
it_behaves_like :string_unpack_32bit_be_signed, 'l>_'
it_behaves_like :string_unpack_32bit_be_signed, 'l_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :string_unpack_32bit_be, 'l>!'
it_behaves_like :string_unpack_32bit_be, 'l!>'
it_behaves_like :string_unpack_32bit_be_signed, 'l>!'
it_behaves_like :string_unpack_32bit_be_signed, 'l!>'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'l<_'
it_behaves_like :string_unpack_64bit_le, 'l_<'
it_behaves_like :string_unpack_64bit_le_signed, 'l<_'
it_behaves_like :string_unpack_64bit_le_signed, 'l_<'
end

describe "with modifier '<' and '!'" do
it_behaves_like :string_unpack_64bit_le, 'l<!'
it_behaves_like :string_unpack_64bit_le, 'l!<'
it_behaves_like :string_unpack_64bit_le_signed, 'l<!'
it_behaves_like :string_unpack_64bit_le_signed, 'l!<'
end

describe "with modifier '>' and '_'" do
it_behaves_like :string_unpack_64bit_be, 'l>_'
it_behaves_like :string_unpack_64bit_be, 'l_>'
it_behaves_like :string_unpack_64bit_be_signed, 'l>_'
it_behaves_like :string_unpack_64bit_be_signed, 'l_>'
end

describe "with modifier '>' and '!'" do
it_behaves_like :string_unpack_64bit_be, 'l>!'
it_behaves_like :string_unpack_64bit_be, 'l!>'
it_behaves_like :string_unpack_64bit_be_signed, 'l>!'
it_behaves_like :string_unpack_64bit_be_signed, 'l!>'
end
end
end
@@ -224,7 +160,7 @@
it_behaves_like :string_unpack_32bit_le_signed, 'l'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_le, 'L_'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L_'
@@ -246,49 +182,25 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_le, 'L_'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L_'
end

describe "String#unpack with format 'L' with modifier '!'" do
it_behaves_like :string_unpack_64bit_le, 'L!'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L!'
end

describe "String#unpack with format 'l' with modifier '_'" do
it_behaves_like :string_unpack_64bit_le, 'l_'
it_behaves_like :string_unpack_64bit_le_signed, 'l_'
end

describe "String#unpack with format 'l' with modifier '!'" do
it_behaves_like :string_unpack_64bit_le, 'l!'
it_behaves_like :string_unpack_64bit_le_signed, 'l!'
end
end

platform_is :mingw32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_le, 'L_'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L_'
end

describe "String#unpack with format 'L' with modifier '!'" do
it_behaves_like :string_unpack_32bit_le, 'L!'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L!'
end

describe "String#unpack with format 'l' with modifier '_'" do
it_behaves_like :string_unpack_32bit_le, 'l_'
it_behaves_like :string_unpack_32bit_le_signed, 'l_'
end

describe "String#unpack with format 'l' with modifier '!'" do
it_behaves_like :string_unpack_32bit_le, 'l!'
it_behaves_like :string_unpack_32bit_le_signed, 'l!'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_le, 'L_'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L_'
end

describe "String#unpack with format 'L' with modifier '!'" do
it_behaves_like :string_unpack_64bit_le, 'L!'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L!'
end

describe "String#unpack with format 'l' with modifier '_'" do
it_behaves_like :string_unpack_64bit_le, 'l_'
it_behaves_like :string_unpack_64bit_le_signed, 'l_'
end

describe "String#unpack with format 'l' with modifier '!'" do
it_behaves_like :string_unpack_64bit_le, 'l!'
it_behaves_like :string_unpack_64bit_le_signed, 'l!'
end
end
end
@@ -306,7 +218,7 @@
it_behaves_like :string_unpack_32bit_be_signed, 'l'
end

platform_is wordsize: 32 do
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_be, 'L_'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L_'
@@ -328,49 +240,26 @@
end
end

platform_is wordsize: 64 do
platform_is_not :mingw32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_be, 'L_'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L_'
end

describe "String#unpack with format 'L' with modifier '!'" do
it_behaves_like :string_unpack_64bit_be, 'L!'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L!'
end

describe "String#unpack with format 'l' with modifier '_'" do
it_behaves_like :string_unpack_64bit_be, 'l_'
it_behaves_like :string_unpack_64bit_be_signed, 'l_'
end

describe "String#unpack with format 'l' with modifier '!'" do
it_behaves_like :string_unpack_64bit_be, 'l!'
it_behaves_like :string_unpack_64bit_be_signed, 'l!'
end
end

platform_is :mingw32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_be, 'L_'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L_'
end

describe "String#unpack with format 'L' with modifier '!'" do
it_behaves_like :string_unpack_32bit_be, 'L!'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L!'
end

describe "String#unpack with format 'l' with modifier '_'" do
it_behaves_like :string_unpack_32bit_be, 'l_'
it_behaves_like :string_unpack_32bit_be_signed, 'l_'
end

describe "String#unpack with format 'l' with modifier '!'" do
it_behaves_like :string_unpack_32bit_be, 'l!'
it_behaves_like :string_unpack_32bit_be_signed, 'l!'
end
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_be, 'L_'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L_'
end

describe "String#unpack with format 'L' with modifier '!'" do
it_behaves_like :string_unpack_64bit_be, 'L!'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L!'
end

describe "String#unpack with format 'l' with modifier '_'" do
it_behaves_like :string_unpack_64bit_be, 'l_'
it_behaves_like :string_unpack_64bit_be_signed, 'l_'
end

describe "String#unpack with format 'l' with modifier '!'" do
it_behaves_like :string_unpack_64bit_be, 'l!'
it_behaves_like :string_unpack_64bit_be_signed, 'l!'
end
end

end
16 changes: 13 additions & 3 deletions spec/ruby/core/thread/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -111,9 +111,6 @@ def self.status_of_blocked_thread
status
end

def self.status_of_aborting_thread
end

def self.status_of_killed_thread
t = Thread.new { sleep }
Thread.pass while t.status and t.status != 'sleep'
@@ -147,6 +144,19 @@ def self.status_of_dying_sleeping_thread
status
end

def self.status_of_dying_thread_after_sleep
status = nil
t = dying_thread_ensures {
Thread.stop
status = Status.new(Thread.current)
}
Thread.pass while t.status and t.status != 'sleep'
t.wakeup
Thread.pass while t.status and t.status == 'sleep'
t.join
status
end

def self.dying_thread_ensures(kill_method_name=:kill)
Thread.new do
begin
8 changes: 5 additions & 3 deletions spec/ruby/core/thread/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -31,12 +31,14 @@
end

it "describes a dying sleeping thread" do
ThreadSpecs.status_of_dying_sleeping_thread.status.should include('sleep')
ThreadSpecs.status_of_dying_sleeping_thread.inspect.should include('sleep')
end

quarantine! do
it "reports aborting on a killed thread" do
ThreadSpecs.status_of_aborting_thread.inspect.should include('aborting')
ThreadSpecs.status_of_dying_running_thread.inspect.should include('aborting')
end

it "reports aborting on a killed thread after sleep" do
ThreadSpecs.status_of_dying_thread_after_sleep.inspect.should include('aborting')
end
end
6 changes: 4 additions & 2 deletions spec/ruby/core/thread/status_spec.rb
Original file line number Diff line number Diff line change
@@ -34,9 +34,11 @@
ThreadSpecs.status_of_dying_sleeping_thread.status.should == 'sleep'
end

quarantine! do
it "reports aborting on a killed thread" do
ThreadSpecs.status_of_aborting_thread.status.should == 'aborting'
ThreadSpecs.status_of_dying_running_thread.status.should == 'aborting'
end

it "reports aborting on a killed thread after sleep" do
ThreadSpecs.status_of_dying_thread_after_sleep.status.should == 'aborting'
end
end
6 changes: 2 additions & 4 deletions spec/ruby/core/thread/stop_spec.rb
Original file line number Diff line number Diff line change
@@ -48,9 +48,7 @@
ThreadSpecs.status_of_dying_sleeping_thread.stop?.should == true
end

quarantine! do
it "reports aborting on a killed thread" do
ThreadSpecs.status_of_aborting_thread.stop?.should == false
end
it "describes a dying thread after sleep" do
ThreadSpecs.status_of_dying_thread_after_sleep.stop?.should == false
end
end
18 changes: 16 additions & 2 deletions spec/ruby/language/break_spec.rb
Original file line number Diff line number Diff line change
@@ -40,12 +40,12 @@

it "raises a LocalJumpError when invoking the block from a method" do
lambda { @program.break_in_nested_method }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :c, :aa, :b]
ScratchPad.recorded.should == [:a, :xa, :cc, :aa, :b]
end

it "raises a LocalJumpError when yielding to the block" do
lambda { @program.break_in_yielding_method }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :c, :aa, :b]
ScratchPad.recorded.should == [:a, :xa, :cc, :aa, :b]
end
end

@@ -60,6 +60,20 @@
ScratchPad.recorded.should == [:a, :za, :xa, :zd, :aa, :zb]
end
end

describe "from another thread" do
it "raises a LocalJumpError when getting the value from another thread" do
ScratchPad << :a
thread_with_break = Thread.new do
ScratchPad << :b
break :break
ScratchPad << :c
end

lambda { thread_with_break.value }.should raise_error(LocalJumpError)
ScratchPad.recorded.should == [:a, :b]
end
end
end

describe "The break statement in a lambda" do
4 changes: 2 additions & 2 deletions spec/ruby/language/fixtures/break.rb
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ def break_in_nested_method
break :break
note :c
}
note :c
note :cc
note call_method(b)
note :d
end
@@ -101,7 +101,7 @@ def break_in_yielding_method
break :break
note :c
}
note :c
note :cc
note yielding(&b)
note :d
end
4 changes: 3 additions & 1 deletion spec/ruby/language/fixtures/defined.rb
Original file line number Diff line number Diff line change
@@ -83,7 +83,9 @@ def global_variable_undefined
end

def global_variable_read
value = $defined_specs_global_variable_read
suppress_warning do
value = $defined_specs_global_variable_read
end
defined? $defined_specs_global_variable_read
end

2 changes: 1 addition & 1 deletion spec/ruby/library/bigdecimal/to_r_spec.rb
Original file line number Diff line number Diff line change
@@ -13,4 +13,4 @@
r.denominator.should eql(1000000000000000000000000)
end

end
end
5 changes: 4 additions & 1 deletion spec/ruby/library/stringscanner/shared/peek.rb
Original file line number Diff line number Diff line change
@@ -3,12 +3,15 @@
@s = StringScanner.new('This is a test')
end

it "returns at most the specified number of characters from the current position" do
it "returns at most the specified number of bytes from the current position" do
@s.send(@method, 4).should == "This"
@s.pos.should == 0
@s.pos = 5
@s.send(@method, 2).should == "is"
@s.send(@method, 1000).should == "is a test"

s = StringScanner.new("été")
s.send(@method, 2).should == "é"
end

it "returns an empty string when the passed argument is zero" do
23 changes: 12 additions & 11 deletions spec/ruby/optional/capi/ext/io_spec.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ruby.h"
#include "rubyspec.h"
#include "ruby/io.h"
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -133,46 +134,46 @@ VALUE io_spec_rb_io_taint_check(VALUE self, VALUE io) {
}
#endif

typedef int wait_bool;
#define wait_bool_to_ruby_bool(x) (x ? Qtrue : Qfalse)

#ifdef HAVE_RB_IO_WAIT_READABLE
#define RB_IO_WAIT_READABLE_BUF 13

VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
int fd = io_spec_get_fd(io);
char buf[RB_IO_WAIT_READABLE_BUF];
wait_bool ret;
int ret, r, saved_errno;

if (set_non_blocking(fd) == -1)
rb_sys_fail("set_non_blocking failed");

if(RTEST(read_p)) {
if(read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) {
if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) {
return Qnil;
}
saved_errno = errno;
rb_ivar_set(self, rb_intern("@write_data"), Qtrue);
errno = saved_errno;
}

ret = rb_io_wait_readable(fd);

if(RTEST(read_p)) {
if(read(fd, buf, RB_IO_WAIT_READABLE_BUF) != 13) {
return Qnil;
r = read(fd, buf, RB_IO_WAIT_READABLE_BUF);
if (r != RB_IO_WAIT_READABLE_BUF) {
perror("read");
return INT2FIX(r);
}
rb_ivar_set(self, rb_intern("@read_data"),
rb_str_new(buf, RB_IO_WAIT_READABLE_BUF));
}

return wait_bool_to_ruby_bool(ret);
return ret ? Qtrue : Qfalse;
}
#endif

#ifdef HAVE_RB_IO_WAIT_WRITABLE
VALUE io_spec_rb_io_wait_writable(VALUE self, VALUE io) {
wait_bool ret;
ret = rb_io_wait_writable(io_spec_get_fd(io));
return wait_bool_to_ruby_bool(ret);
int ret = rb_io_wait_writable(io_spec_get_fd(io));
return ret ? Qtrue : Qfalse;
}
#endif

4 changes: 2 additions & 2 deletions spec/ruby/optional/capi/globals_spec.rb
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@
running = true
end

Thread.pass until running
Thread.pass while thr.status and !running
$_.should be_nil

thr.join
@@ -215,7 +215,7 @@
running = true
end

Thread.pass until running
Thread.pass while thr.status and !running
$_.should be_nil

thr.join
2 changes: 1 addition & 1 deletion spec/ruby/optional/capi/object_spec.rb
Original file line number Diff line number Diff line change
@@ -175,6 +175,7 @@ def six(a, b, *c, &d); end
describe "rb_require" do
before :each do
@saved_loaded_features = $LOADED_FEATURES.dup
$foo = nil
end

after :each do
@@ -183,7 +184,6 @@ def six(a, b, *c, &d); end
end

it "requires a ruby file" do
$foo.should == nil
$:.unshift File.dirname(__FILE__)
@o.rb_require()
$foo.should == 7
4 changes: 4 additions & 0 deletions spec/ruby/optional/capi/thread_spec.rb
Original file line number Diff line number Diff line change
@@ -107,6 +107,10 @@ def call_capi_rb_thread_wakeup
# Wait until it's blocking...
Thread.pass while thr.status and thr.status != "sleep"

# The thread status is set to sleep by rb_thread_call_without_gvl(),
# but the thread might not be in the blocking read(2) yet, so wait a bit.
sleep 0.1

# Wake it up, causing the unblock function to be run.
thr.wakeup