Skip to content

Commit

Permalink
Showing 107 changed files with 2,040 additions and 872 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -58,6 +58,12 @@ matrix:
- JT=check_ambiguous_arguments
- SKIP_BUILD=true
jdk: oraclejdk8
- env:
- USE_BUILD_PACK=yes
- JT='test fast'
jdk: oraclejdk8
- env: JT='test mri'
jdk: oraclejdk8
allow_failures:
- env: JT='test mri'
jdk: oraclejdk8
2 changes: 0 additions & 2 deletions core/src/main/java/org/jruby/RubyRegexp.java
Original file line number Diff line number Diff line change
@@ -41,7 +41,6 @@
import org.jcodings.Encoding;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.joni.Matcher;
import org.joni.NameEntry;
import org.joni.Option;
@@ -68,7 +67,6 @@
import org.jruby.util.KCode;
import org.jruby.util.RegexpOptions;
import org.jruby.util.RegexpSupport;
import org.jruby.util.Sprintf;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;
import org.jruby.util.cli.Options;
Original file line number Diff line number Diff line change
@@ -495,8 +495,6 @@ public IRubyObject rubyEncodingFromObject(IRubyObject str) {
* @return the charset
*/
public Charset charsetForEncoding(Encoding encoding) {
Charset charset = encoding.getCharset();

if (encoding.toString().equals("ASCII-8BIT")) {
return Charset.forName("ISO-8859-1");
}
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

0 comments on commit 1bf5aee

Please sign in to comment.