summaryrefslogtreecommitdiff
path: root/spec/ruby/core/io
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-05-02 16:03:14 +0200
committerBenoit Daloze <eregontp@gmail.com>2020-05-02 16:03:14 +0200
commitc9213aa864fb8527388679c21f1ea8ce129e2f1a (patch)
treea6ef2403c73ef61a2aaddad6c0f8d9d09e4e6151 /spec/ruby/core/io
parenta68ddf42879005905176bc38285906fe01707aff (diff)
Update to ruby/spec@d394dfd
Diffstat (limited to 'spec/ruby/core/io')
-rw-r--r--spec/ruby/core/io/copy_stream_spec.rb40
-rw-r--r--spec/ruby/core/io/fixtures/classes.rb4
-rw-r--r--spec/ruby/core/io/fixtures/copy_in_out.rb2
3 files changed, 44 insertions, 2 deletions
diff --git a/spec/ruby/core/io/copy_stream_spec.rb b/spec/ruby/core/io/copy_stream_spec.rb
index c541e96e14..df9c5c7390 100644
--- a/spec/ruby/core/io/copy_stream_spec.rb
+++ b/spec/ruby/core/io/copy_stream_spec.rb
@@ -279,4 +279,44 @@ describe "IO.copy_stream" do
end
end
+
+
+ describe "with a destination that does partial reads" do
+ before do
+ @from_out, @from_in = IO.pipe
+ @to_out, @to_in = IO.pipe
+ end
+
+ after do
+ [@from_out, @from_in, @to_out, @to_in].each {|io| io.close rescue nil}
+ end
+
+ it "calls #write repeatedly on the destination Object" do
+ @from_in.write "1234"
+ @from_in.close
+
+ th = Thread.new do
+ IO.copy_stream(@from_out, @to_in)
+ end
+
+ copied = ""
+ 4.times do
+ copied += @to_out.read(1)
+ end
+
+ th.join
+
+ copied.should == "1234"
+ end
+
+ end
+end
+
+describe "IO.copy_stream" do
+ it "does not use buffering when writing to STDOUT" do
+ IO.popen([*ruby_exe, fixture(__FILE__ , "copy_in_out.rb")], "r+") do |io|
+ io.write("bar")
+ io.read(3).should == "bar"
+ end
+ end
end
diff --git a/spec/ruby/core/io/fixtures/classes.rb b/spec/ruby/core/io/fixtures/classes.rb
index 460dd62387..5cc42c9b44 100644
--- a/spec/ruby/core/io/fixtures/classes.rb
+++ b/spec/ruby/core/io/fixtures/classes.rb
@@ -164,7 +164,7 @@ module IOSpecs
@io = io
end
- def read(size, buf=nil)
+ def read(size, buf)
@io.read size, buf
end
@@ -178,7 +178,7 @@ module IOSpecs
@io = io
end
- def readpartial(size, buf=nil)
+ def readpartial(size, buf)
@io.readpartial size, buf
end
diff --git a/spec/ruby/core/io/fixtures/copy_in_out.rb b/spec/ruby/core/io/fixtures/copy_in_out.rb
new file mode 100644
index 0000000000..b9d4085a47
--- /dev/null
+++ b/spec/ruby/core/io/fixtures/copy_in_out.rb
@@ -0,0 +1,2 @@
+STDOUT.sync = false
+IO.copy_stream(STDIN, STDOUT)