diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-29 16:08:16 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-29 16:08:16 +0000 |
commit | 3fa5bd38af50fb3d98de0ea51043d73f8d06a24b (patch) | |
tree | d473b71cc6925ee1e17727215e9f9a66e3f24802 /spec/ruby/core/io | |
parent | 1e658d45e1f8dbadab18f9c35b5cfb5a5fec98bf (diff) |
Update to ruby/spec@83063a3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/io')
-rw-r--r-- | spec/ruby/core/io/close_spec.rb | 26 | ||||
-rw-r--r-- | spec/ruby/core/io/codepoints_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/io/each_codepoint_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/io/tell_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/io/ungetc_spec.rb | 16 |
5 files changed, 44 insertions, 4 deletions
diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb index 0e51ec23d2..77a8748e7c 100644 --- a/spec/ruby/core/io/close_spec.rb +++ b/spec/ruby/core/io/close_spec.rb @@ -31,6 +31,13 @@ describe "IO#close" do lambda { @io.write "data" }.should raise_error(IOError) end + it 'does not close the stream if autoclose is false' do + other_io = IO.new(@io.fileno) + other_io.autoclose = false + other_io.close + lambda { @io.write "data" }.should_not raise_error(IOError) + end + ruby_version_is ''...'2.3' do it "raises an IOError if closed" do @io.close @@ -45,6 +52,24 @@ describe "IO#close" do @io.close.should be_nil end end + + ruby_version_is '2.5' do + it 'raises an IOError with a clear message' do + read_io, write_io = IO.pipe + going_to_read = false + thread = Thread.new do + lambda do + going_to_read = true + read_io.read + end.should raise_error(IOError, 'stream closed in another thread') + end + + Thread.pass until going_to_read && thread.stop? + read_io.close + thread.join + write_io.close + end + end end describe "IO#close on an IO.popen stream" do @@ -79,4 +104,3 @@ describe "IO#close on an IO.popen stream" do end end - diff --git a/spec/ruby/core/io/codepoints_spec.rb b/spec/ruby/core/io/codepoints_spec.rb index 6e6b9613b5..b232a9c598 100644 --- a/spec/ruby/core/io/codepoints_spec.rb +++ b/spec/ruby/core/io/codepoints_spec.rb @@ -4,7 +4,7 @@ require File.expand_path('../shared/codepoints', __FILE__) # See redmine #1667 describe "IO#codepoints" do - it_behaves_like(:io_codepoints, :codepoints) + it_behaves_like :io_codepoints, :codepoints end describe "IO#codepoints" do diff --git a/spec/ruby/core/io/each_codepoint_spec.rb b/spec/ruby/core/io/each_codepoint_spec.rb index eb16e004fa..2bcf898c89 100644 --- a/spec/ruby/core/io/each_codepoint_spec.rb +++ b/spec/ruby/core/io/each_codepoint_spec.rb @@ -4,7 +4,7 @@ require File.expand_path('../shared/codepoints', __FILE__) # See redmine #1667 describe "IO#each_codepoint" do - it_behaves_like(:io_codepoints, :codepoints) + it_behaves_like :io_codepoints, :codepoints end describe "IO#each_codepoint" do diff --git a/spec/ruby/core/io/tell_spec.rb b/spec/ruby/core/io/tell_spec.rb index d2f523cf10..cc54012a37 100644 --- a/spec/ruby/core/io/tell_spec.rb +++ b/spec/ruby/core/io/tell_spec.rb @@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__) require File.expand_path('../shared/pos', __FILE__) describe "IO#tell" do - it_behaves_like(:io_pos, :tell) + it_behaves_like :io_pos, :tell end diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb index ce4cc9d346..488e587f5a 100644 --- a/spec/ruby/core/io/ungetc_spec.rb +++ b/spec/ruby/core/io/ungetc_spec.rb @@ -31,6 +31,22 @@ describe "IO#ungetc" do @io.getc.should == ?c end + it "interprets the codepoint in the external encoding" do + @io.set_encoding(Encoding::UTF_8) + @io.ungetc(233) + c = @io.getc + c.encoding.should == Encoding::UTF_8 + c.should == "é" + c.bytes.should == [195, 169] + + @io.set_encoding(Encoding::IBM437) + @io.ungetc(130) + c = @io.getc + c.encoding.should == Encoding::IBM437 + c.bytes.should == [130] + c.encode(Encoding::UTF_8).should == "é" + end + it "pushes back one character when invoked at the end of the stream" do # read entire content @io.read |