The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Do not trust irb exit status

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Paul Gross

Posts: 152
Nickname: pgross
Registered: Sep, 2007

Paul Gross is a software developer for ThoughtWorks.
Do not trust irb exit status Posted: Oct 9, 2007 10:06 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Paul Gross.
Original Post: Do not trust irb exit status
Feed Title: Paul Gross's Blog - Home
Feed URL: http://feeds.feedburner.com/pgrs
Feed Description: Posts mainly about ruby on rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Paul Gross
Latest Posts From Paul Gross's Blog - Home

Advertisement

Notice this strange behavior with exit status and irb. The $? variable holds the exit status of the last command.

In plain ruby, everything works as expected:

% ruby -e "exit 4" 
% echo $?
4

However, in irb, the exit status is 0:

% irb
irb(main):001:0> exit 4
% echo $?
0

It seems like irb ignores the exit status and always returns 0 (success). This introduces strange behavior around running tests. Test::Unit tests are run when the ruby process exits, and the exit status is non-zero if there were test failures. However, if the tests are run from irb, the exit status is 0 with failing tests.

In plain ruby:


% ruby failing_test.rb
Loaded suite failing_test
Started
E
Finished in 0.001127 seconds.

  1) Error:
test_fail(FailingTest):
RuntimeError:
    failing_test.rb:5:in `test_fail'

1 tests, 0 assertions, 0 failures, 1 errors

% echo $?
1

In irb:


% irb
>> require 'failing_test'
=> true
>> exit
Loaded suite irb
Started
E
Finished in 0.00077 seconds.

  1) Error:
test_fail(FailingTest):
RuntimeError:
    ./failing_test.rb:5:in `test_fail'

1 tests, 0 assertions, 0 failures, 1 errors
/usr/lib/ruby/1.8/irb.rb:76:in `throw': uncaught throw `IRB_EXIT' (NameError)
        from /usr/lib/ruby/1.8/irb.rb:76:in `irb_exit'
        from /usr/lib/ruby/1.8/irb/context.rb:226:in `exit'
        from /usr/lib/ruby/1.8/irb/extend-command.rb:24:in `exit'
        from /usr/lib/ruby/1.8/test/unit.rb:278
        from /usr/bin/irb:13

% echo $?
0

Read: Do not trust irb exit status

Topic: Useful unix tricks - part 2 Previous Topic   Next Topic Topic: Observing Fields With Rails in the Browser

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use