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: 0dc59ff036d9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0f616f984ba5
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 19, 2015

  1. [Truffle] New slow tag

    eregon committed Jul 19, 2015
    Copy the full SHA
    8274f1d View commit details
  2. Copy the full SHA
    a81bd9e View commit details
  3. Copy the full SHA
    0f616f9 View commit details
Showing with 20 additions and 93 deletions.
  1. +16 −28 spec/ruby/core/io/puts_spec.rb
  2. +3 −65 spec/ruby/core/kernel/puts_spec.rb
  3. +1 −0 spec/truffle/tags/core/io/reopen_tags.txt
44 changes: 16 additions & 28 deletions spec/ruby/core/io/puts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,100 +1,88 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

# TODO: need to find a better way to test this. Too fragile to set expectations
# to each write call. Only care that all the characters are sent not the number
# or write calls. Also, these tests do not make sure the ordering of the write calls
# are correct.
describe "IO#puts" do
before :each do
@before_separator = $/
@name = tmp("io_puts.txt")
@io = new_io @name
ScratchPad.record ""
def @io.write(str)
ScratchPad << str
end
end

after :each do
ScratchPad.clear
@io.close if @io
rm_r @name
$/ = @before_separator
end

it "writes just a newline when given no args" do
@io.should_receive(:write).with("\n")
@io.puts.should == nil
ScratchPad.recorded.should == "\n"
end

it "writes just a newline when given just a newline" do
lambda { $stdout.puts "\n" }.should output_to_fd("\n", STDOUT)
end

it "writes empty string with a newline when given nil as an arg" do
@io.should_receive(:write).with("")
@io.should_receive(:write).with("\n")
@io.puts(nil).should == nil
ScratchPad.recorded.should == "\n"
end

it "writes empty string with a newline when when given nil as multiple args" do
@io.should_receive(:write).with("").twice
@io.should_receive(:write).with("\n").twice
@io.puts(nil, nil).should == nil
ScratchPad.recorded.should == "\n\n"
end

it "calls to_s before writing non-string objects" do
object = mock('hola')
object.should_receive(:to_s).and_return("hola")

@io.should_receive(:write).with("hola")
@io.should_receive(:write).with("\n")
@io.puts(object).should == nil
ScratchPad.recorded.should == "hola\n"
end

it "writes each arg if given several" do
@io.should_receive(:write).with("1")
@io.should_receive(:write).with("two")
@io.should_receive(:write).with("3")
@io.should_receive(:write).with("\n").exactly(3).times
@io.puts(1, "two", 3).should == nil
ScratchPad.recorded.should == "1\ntwo\n3\n"
end

it "flattens a nested array before writing it" do
@io.should_receive(:write).with("1")
@io.should_receive(:write).with("2")
@io.should_receive(:write).with("3")
@io.should_receive(:write).with("\n").exactly(3).times
@io.puts([1, 2, [3]]).should == nil
ScratchPad.recorded.should == "1\n2\n3\n"
end

it "writes nothing for an empty array" do
x = []
@io.should_receive(:write).exactly(0).times
@io.should_not_receive(:write)
@io.puts(x).should == nil
end

it "writes [...] for a recursive array arg" do
x = []
x << 2 << x
@io.should_receive(:write).with("2")
@io.should_receive(:write).with("[...]")
@io.should_receive(:write).with("\n").exactly(2).times
@io.puts(x).should == nil
ScratchPad.recorded.should == "2\n[...]\n"
end

it "writes a newline after objects that do not end in newlines" do
@io.should_receive(:write).with("5")
@io.should_receive(:write).with("\n")
@io.puts(5).should == nil
ScratchPad.recorded.should == "5\n"
end

it "does not write a newline after objects that end in newlines" do
@io.should_receive(:write).with("5\n")
@io.puts("5\n").should == nil
ScratchPad.recorded.should == "5\n"
end

it "ignores the $/ separator global" do
$/ = ":"
@io.should_receive(:write).with("5")
@io.should_receive(:write).with("\n")
@io.puts(5).should == nil
ScratchPad.recorded.should == "5\n"
end

it "raises IOError on closed stream" do
68 changes: 3 additions & 65 deletions spec/ruby/core/kernel/puts_spec.rb
Original file line number Diff line number Diff line change
@@ -3,14 +3,12 @@

describe "Kernel#puts" do
before :each do
@before_separator = $/
@stdout = $stdout
@name = tmp("kernel_puts.txt")
$stdout = new_io @name
end

after :each do
$/ = @before_separator
$stdout.close
$stdout = @stdout
rm_r @name
@@ -20,69 +18,9 @@
Kernel.should have_private_instance_method(:puts)
end

it "writes just a newline when given no args" do
$stdout.should_receive(:write).with("\n")
Kernel.puts.should == nil
end

# Declared intentional in
# http://redmine.ruby-lang.org/issues/show/1748
it "writes a newline when given nil as an arg" do
$stdout.should_receive(:write).with('')
$stdout.should_receive(:write).with("\n")
Kernel.puts(nil).should == nil
end

it "calls to_s before writing non-string objects" do
object = mock('hola')
object.should_receive(:to_s).and_return("hola")

$stdout.should_receive(:write).with("hola")
$stdout.should_receive(:write).with("\n")
Kernel.puts(object).should == nil
end

it "writes each arg if given several" do
$stdout.should_receive(:write).with("1")
$stdout.should_receive(:write).with("two")
$stdout.should_receive(:write).with("3")
$stdout.should_receive(:write).with("\n").exactly(3).times
Kernel.puts(1, "two", 3).should == nil
end

it "flattens a nested array before writing it" do
$stdout.should_receive(:write).with("1")
$stdout.should_receive(:write).with("2")
$stdout.should_receive(:write).with("3")
$stdout.should_receive(:write).with("\n").exactly(3).times
Kernel.puts([1, 2, [3]]).should == nil
end

it "writes [...] for a recursive array arg" do
x = []
x << 2 << x
$stdout.should_receive(:write).with("2")
$stdout.should_receive(:write).with("[...]")
$stdout.should_receive(:write).with("\n").exactly(2).times
Kernel.puts(x).should == nil
end

it "writes a newline after objects that do not end in newlines" do
$stdout.should_receive(:write).with("5")
$stdout.should_receive(:write).with("\n")
Kernel.puts(5).should == nil
end

it "does not write a newline after objects that end in newlines" do
$stdout.should_receive(:write).with("5\n")
Kernel.puts("5\n").should == nil
end

it "ignores the $/ separator global" do
$/ = ":"
$stdout.should_receive(:write).with("5")
$stdout.should_receive(:write).with("\n")
Kernel.puts(5).should == nil
it "delegates to $stdout.puts" do
$stdout.should_receive(:puts).with(:arg)
puts :arg
end
end

1 change: 1 addition & 0 deletions spec/truffle/tags/core/io/reopen_tags.txt
Original file line number Diff line number Diff line change
@@ -3,3 +3,4 @@ fails:IO#reopen with a String opens a path after writing to the original file de
fails:IO#reopen with an IO reads from the beginning if the other IO has not been read from
fails:IO#reopen with an IO reads from the current position of the other IO's stream
fails:IO#reopen with an IO associates the IO instance with the other IO's stream
slow:IO#reopen with a String effects exec/system/fork performed after it