[Ironruby-core] Code Review: Fix for File.print misbehavior

Jim Deville jdeville at microsoft.com
Sat May 16 19:05:58 EDT 2009


I would be opposed to making the MSpec runner depend on any more stdlibs. I would suggest making a helper that swaps the IOStub with the real stdout for the duration of a block.

JD

....there is no try
Sent from my phone. Please excuse typos and txtspk.

-----Original Message-----
From: Shri Borde <Shri.Borde at microsoft.com>
Sent: May 16, 2009 3:11 PM
To: ironruby-core at rubyforge.org <ironruby-core at rubyforge.org>
Subject: Re: [Ironruby-core] Code Review: Fix for File.print misbehavior


The problem is because of mspec itself. In External.LCA_RESTRICTED\Languages\IronRuby\mspec\mspec\lib\mspec\matchers\output.rb, the code sets $stdout to a helper class (IOStub) so that it can capture the output. However, what this means is that calls to $stdout.print that the test makes now go to IOStub#print rather than to the real implementation of IO#print, and this masks the bug.

A better solution would be to use StringIO in matchers\output.rb rather than IOStub. If you are included to pursue this (which would be great), you could try the change and/or send email to http://groups.google.com/group/rubyspec to discuss the change. However, since this is a preexisting issue, you could leave it for another day if you want.

So consider your change code-reviewed, and you can chose separately to pursue (or not) the issue with matchers\output.rb.

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shay Friedman
Sent: Saturday, May 16, 2009 12:46 AM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Code Review: Fix for File.print misbehavior

I couldn't follow the code exactly but what I did find, was that this
test never reached the code inside IOOps.Print.
The behavior is really strange, I tried to print the value on the screen
and the value were really incorrect (the $\ delimiter is added after
each argument) but the $stdout.print call inside the lambda expression
got it correctly...

I did that:

  it "writes each obj.to_s to the stream and appends $\\ (if any) given
multiple

objects" do
    o, o2 = Object.new, Object.new
    def o.to_s(); 'o'; end
    def o2.to_s(); 'o2'; end

    puts $stdout.print(o, o2)

    lambda { $stdout.print(o, o2) }.should
output("#{o.to_s}#{o2.to_s}#{$\}")
  end


And it wrote "o->o2->nil" on the screen... But when I changed the output
it to "123" the test failed and told me:
Expected:
  $stdout: "123"
      got:
  $stdout: "oo2->"

So I'm really confused... like I said, my breakpoint inside the print
method never gets hit so I can't really tell which "print" method is
invoked...

Shay.
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core



More information about the Ironruby-core mailing list