On Tue, Jul 01, 2003 at 10:06:46PM +0900, Andrey Kulinich wrote:
> I was talking about test/unit.
> Why when I'm using it in such code ruby can't detect infinite loop? In 
> my opinion this is test/unit's bug.

I don't think Ruby really "detects" infinite loops; it simply runs out of
memory and reports it.

When I run your code from RubyTalk:74829 I get:

$ ruby x.rb 2>&1 | head -20
Loaded suite x
Started
..
Error!!!
test_1(Tests):
SystemStackError: stack level too deep
        x.rb:6:in `new'
        x.rb:6:in `new'
        x.rb:6:in `new'
        x.rb:6:in `new'
        x.rb:6:in `new'
        x.rb:6:in `new'
... etc

Now if I strip out the test/unit stuff I get almost exactly the same error:

$ cat x.rb
#!/usr/local/bin/ruby
module Recur
     def self.new
         Recur.new
     end
end

Recur.new

$ ruby x.rb 2>&1
x.rb:4:in `New': stack level too deep (SystemStackError)
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:4:in `New'
         ... 66668 levels...
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:4:in `New'
        from x.rb:8

The only difference seems to be that the error report has this optimisation
of "... 66668 levels..." in there (This is ruby-1.6.8, incidentally)

test/unit traps exceptions, so that
(a) it can count errors, and
(b) it can display errors in the appropriate place (you might be running
    with a GTk testrunner, for example)

So I wouldn't expect it to give *exactly* the same output as Ruby's default
exception handler. It does seem pretty close to me though.

If you don't think test/unit is doing the right thing, can you post the
output of running your test program under test/unit, the output when run
without test/unit, and how you think it should be changed?

Regards,

Brian.