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: 840ed0d5bde8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9f232f43c286
Choose a head ref
  • 2 commits
  • 17 files changed
  • 1 contributor

Commits on Jul 18, 2016

  1. Squashed 'spec/ruby/' changes from 9b80404..ced79c8

    ced79c8 Remove spec depending on platform-dependent behavior from ungetc/lseek.
    26689c1 Added Exception#cause spec
    36f0116 Add a Hash spec
    1a7edec Import specs extracted from Rubinius' merged Codedb ffi io branch
    4c86731 [Truffle] Add rb_gc_register_address and rb_ary_new4.
    9f34a94 [Truffle] Pass all cext complex specs.
    51b1b08 [Truffle] Pass all cext rational specs.
    ec7a0fe [Truffle] Pass all cext mutex specs.
    e9cb231 [Truffle] Pass all cext float specs.
    3bce77e [Truffle] Pass all cext fixnum specs.
    a9bdd5b [Truffle] rb_gc_enable and _disable
    064fdca Add sort_by! spec for single-element array.
    440c00f [Truffle] Use jt cextc as the cext compiler.
    b223b45 Add an example for Array#slice!
    87a550a Add missing require in shared Range specs
    be39236 Add a case for nil&.attr+=val to the safe navigation operator specs
    cba3695 Merge pull request #274 from iliabylich/add-specs-for-safe-navigator
    ffabc7f Add specs for a safe navigator.
    0a65ffe Merge pull request #272 from wied03/def_specs
    88343ce Test return value of defined setters and []= methods and multiple arguments provided.
    8e65d52 Merge pull request #273 from jrafanie/add_2_3_tests_for_reject_bang
    e68a19a Add specs for Array#reject!, delete_if 2.3 change
    147b216 Merge pull request #271 from odaira/myContribution
    d02b3ac Skip specs using getsockopt, which is known to return a wrong length in AIX
    c9634e9 Add ensure to the begin/rescue/else permutations for rescue_spec
    7e05c6d Prevent regression of outer scope return value with begin/else logic
    e1f7b0d Test rescue begin/else on methods as well as blocks
    d4ced96 feature guard for fork
    
    git-subtree-dir: spec/ruby
    git-subtree-split: ced79c84680f8a82e099eb14c164a57ce56b44b0
    eregon committed Jul 18, 2016
    Copy the full SHA
    9c36da2 View commit details
  2. Copy the full SHA
    9f232f4 View commit details
2 changes: 2 additions & 0 deletions spec/ruby/core/array/delete_if_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/enumeratorize', __FILE__)
require File.expand_path('../shared/delete_if', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)

describe "Array#delete_if" do
@@ -61,4 +62,5 @@
end

it_behaves_like :enumeratorized_with_origin_size, :delete_if, [1,2,3]
it_behaves_like :delete_if, :delete_if
end
2 changes: 2 additions & 0 deletions spec/ruby/core/array/reject_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/enumeratorize', __FILE__)
require File.expand_path('../shared/delete_if', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)

describe "Array#reject" do
@@ -112,4 +113,5 @@

it_behaves_like :enumeratorize, :reject!
it_behaves_like :enumeratorized_with_origin_size, :reject!, [1,2,3]
it_behaves_like :delete_if, :reject!
end
27 changes: 27 additions & 0 deletions spec/ruby/core/array/shared/delete_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe :delete_if, shared: true do
before :each do
@object = [1,2,3]
end

ruby_version_is "2.3" do
it "updates the receiver after all blocks" do
@object.send(@method) do |e|
@object.length.should == 3
true
end
@object.length.should == 0
end
end

ruby_version_is ""..."2.3" do
it "updates the receiver after each true block" do
count = 0
@object.send(@method) do |e|
@object.length.should == (3 - count)
count += 1
true
end
@object.length.should == 0
end
end
end
9 changes: 9 additions & 0 deletions spec/ruby/core/array/shared/keep_if.rb
Original file line number Diff line number Diff line change
@@ -11,6 +11,15 @@
[1, 2, 3].send(@method).should be_an_instance_of(enumerator_class)
end

it "updates the receiver after all blocks" do
a = [1, 2, 3]
a.send(@method) do |e|
a.length.should == 3
false
end
a.length.should == 0
end

before :all do
@object = [1,2,3]
end
19 changes: 19 additions & 0 deletions spec/ruby/core/exception/cause_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "Exception#cause" do
it "returns the active exception when an exception is raised" do
begin
raise Exception, "the cause"
rescue Exception
begin
raise RuntimeError, "the consequence"
rescue RuntimeError => e
e.should be_an_instance_of(RuntimeError)
e.message.should == "the consequence"

e.cause.should be_an_instance_of(Exception)
e.cause.message.should == "the cause"
end
end
end
end
58 changes: 30 additions & 28 deletions spec/ruby/core/fiber/resume_spec.rb
Original file line number Diff line number Diff line change
@@ -13,40 +13,42 @@
fiber2.resume.should == :fiber2
end

# Redmine #595
it "executes the ensure clause" do
rd, wr = IO.pipe

pid = Kernel::fork do
rd.close
f = Fiber.new do
begin
Fiber.yield
ensure
wr.write "executed"
with_feature :fork do
# Redmine #595
it "executes the ensure clause" do
rd, wr = IO.pipe

pid = Kernel::fork do
rd.close
f = Fiber.new do
begin
Fiber.yield
ensure
wr.write "executed"
end
end
end

# The apparent issue is that when Fiber.yield executes, control
# "leaves" the "ensure block" and so the ensure clause should run. But
# control really does NOT leave the ensure block when Fiber.yield
# executes. It merely pauses there. To require ensure to run when a
# Fiber is suspended then makes ensure-in-a-Fiber-context different
# than ensure-in-a-Thread-context and this would be very confusing.
f.resume
# The apparent issue is that when Fiber.yield executes, control
# "leaves" the "ensure block" and so the ensure clause should run. But
# control really does NOT leave the ensure block when Fiber.yield
# executes. It merely pauses there. To require ensure to run when a
# Fiber is suspended then makes ensure-in-a-Fiber-context different
# than ensure-in-a-Thread-context and this would be very confusing.
f.resume

# When we execute the second #resume call, the ensure block DOES exit,
# the ensure clause runs. This is Ruby behavior as of 2.3.1.
f.resume
# When we execute the second #resume call, the ensure block DOES exit,
# the ensure clause runs. This is Ruby behavior as of 2.3.1.
f.resume

exit 0
end
exit 0
end

wr.close
Process.waitpid pid
wr.close
Process.waitpid pid

rd.read.should == "executed"
rd.close
rd.read.should == "executed"
rd.close
end
end
end
end
8 changes: 8 additions & 0 deletions spec/ruby/core/hash/shift_spec.rb
Original file line number Diff line number Diff line change
@@ -26,6 +26,14 @@
h.shift.should == [h, nil]
end

it "preserves Hash invariants when removing the last item" do
h = new_hash(:a => 1, :b => 2)
h.shift.should == [:a, 1]
h.shift.should == [:b, 2]
h[:c] = 3
h.should == {:c => 3}
end

it "raises a RuntimeError if called on a frozen instance" do
lambda { HashSpecs.frozen_hash.shift }.should raise_error(RuntimeError)
lambda { HashSpecs.empty_frozen_hash.shift }.should raise_error(RuntimeError)
7 changes: 7 additions & 0 deletions spec/ruby/core/io/popen_spec.rb
Original file line number Diff line number Diff line change
@@ -39,6 +39,13 @@
rm_r @fname
end

it "sees an infinitely looping subprocess exit when read pipe is closed" do
io = IO.popen "#{RUBY_EXE} -e 'r = loop{puts \"y\"; 0} rescue 1; exit r'", 'r'
io.close

$?.exitstatus.should_not == 0
end

it "writes to a write-only pipe" do
@io = IO.popen("#{RUBY_EXE} -e 'IO.copy_stream(STDIN,STDOUT)' > #{@fname}", "w")
@io.write("bar")
17 changes: 17 additions & 0 deletions spec/ruby/core/io/read_spec.rb
Original file line number Diff line number Diff line change
@@ -302,6 +302,23 @@
it "raises IOError on closed stream" do
lambda { IOSpecs.closed_io.read }.should raise_error(IOError)
end

it "raises IOError when stream is closed by another thread" do
r, w = IO.pipe
t = Thread.new do
begin
r.read(1)
rescue => e
e
end
end

Thread.pass until t.stop?
r.close
t.join
t.value.should be_kind_of(IOError)
w.close
end
end

platform_is :windows do
28 changes: 28 additions & 0 deletions spec/ruby/core/io/reopen_spec.rb
Original file line number Diff line number Diff line change
@@ -193,6 +193,34 @@
end
end

describe "IO#reopen with an IO at EOF" do
before :each do
@name = tmp("io_reopen.txt")
touch(@name) { |f| f.puts "a line" }
@other_name = tmp("io_reopen_other.txt")
touch(@other_name) do |f|
f.puts "Line 1"
f.puts "Line 2"
end

@io = new_io @name, "r"
@other_io = new_io @other_name, "r"
@io.read
end

after :each do
@io.close unless @io.closed?
@other_io.close unless @other_io.closed?
rm_r @name, @other_name
end

it "resets the EOF status to false" do
@io.eof?.should be_true
@io.reopen @other_io
@io.eof?.should be_false
end
end

describe "IO#reopen with an IO" do
before :each do
@name = tmp("io_reopen.txt")
12 changes: 0 additions & 12 deletions spec/ruby/core/io/ungetc_spec.rb
Original file line number Diff line number Diff line change
@@ -81,18 +81,6 @@
@io.pos.should == pos - 1
end

# TODO: file MRI bug
# Another specified behavior that MRI doesn't follow:
# "Has no effect with unbuffered reads (such as IO#sysread)."
#
#it "has no effect with unbuffered reads" do
# length = File.size(@io_name)
# content = @io.sysread(length)
# @io.rewind
# @io.ungetc(100)
# @io.sysread(length).should == content
#end

it "makes subsequent unbuffered operations to raise IOError" do
@io.getc
@io.ungetc(100)
15 changes: 0 additions & 15 deletions spec/ruby/core/io/write_spec.rb
Original file line number Diff line number Diff line change
@@ -20,21 +20,6 @@
rm_r @filename
end

# TODO: impl detail? discuss this with matz. This spec is useless. - rdavis
# I agree. I've marked it not compliant on macruby, as we don't buffer input. -pthomson
not_compliant_on :macruby do
it "writes all of the string's bytes but buffers them" do
written = @file.write("abcde")
written.should == 5
File.open(@filename) do |file|
file.read.should == "012345678901234567890123456789"
@file.fsync
file.rewind
file.read.should == "abcde5678901234567890123456789"
end
end
end

it "does not check if the file is writable if writing zero bytes" do
lambda { @readonly_file.write("") }.should_not raise_error
end
63 changes: 63 additions & 0 deletions spec/ruby/language/fixtures/rescue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module RescueSpecs
def self.begin_else(raise_exception)
begin
ScratchPad << :one
raise "an error occurred" if raise_exception
rescue
ScratchPad << :rescue_ran
:rescue_val
else
ScratchPad << :else_ran
:val
end
end

def self.begin_else_ensure(raise_exception)
begin
ScratchPad << :one
raise "an error occurred" if raise_exception
rescue
ScratchPad << :rescue_ran
:rescue_val
else
ScratchPad << :else_ran
:val
ensure
ScratchPad << :ensure_ran
:ensure_val
end
end

def self.begin_else_return(raise_exception)
begin
ScratchPad << :one
raise "an error occurred" if raise_exception
rescue
ScratchPad << :rescue_ran
:rescue_val
else
ScratchPad << :else_ran
:val
end
ScratchPad << :outside_begin
:return_val
end

def self.begin_else_return_ensure(raise_exception)
begin
ScratchPad << :one
raise "an error occurred" if raise_exception
rescue
ScratchPad << :rescue_ran
:rescue_val
else
ScratchPad << :else_ran
:val
ensure
ScratchPad << :ensure_ran
:ensure_val
end
ScratchPad << :outside_begin
:return_val
end
end
Loading