[#8815] Segfault in libc strlen, via rb_str_new2 — "Sean E. Russell" <ser@...>

Howdy,

12 messages 2006/09/09
[#8817] Re: Segfault in libc strlen, via rb_str_new2 — Eric Hodel <drbrain@...7.net> 2006/09/09

On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

Re: test/unit doesn't rescue a Exception

From: Eric Hodel <drbrain@...7.net>
Date: 2006-09-03 19:10:35 UTC
List: ruby-core #8784
On Sep 3, 2006, at 8:21 AM, Tanaka Akira wrote:

> In article <87ac5hv4bo.fsf@fsij.org>,
>   Tanaka Akira <akr@fsij.org> writes:
>
>> Oops.  It seems that the class hierarchy is not appropriate
>> to classify them for unit test.
>
> I investigated the class hierarchy on second thought.
>
> * Exception
>   * NoMemoryError
>   * ScriptError
>   * SignalException
>     * Interrupt
>       * Timeout::Error
>   * StandardError
>   * SystemExit
>
> Now I think NoMemoryError, SignalException, Interrupt,
> SystemExit should terminate the test runner.
>
> * NoMemoryError is too dangerous.  I think it is better to
>   reduce memory consumption by terminating the process.
>
> * SignalException and Interrupt should terminate the test
>   runner because it may be caused by the user.
>
> * SystemExit is caused by exit.  If exit is called
>   explicitly, I have no reason to prevent it.

I have expected tests to raise SystemExit for example when testing a  
method like #usage for ARGV handling.  I added an assert_raise for  
this, and I would expect others to do this too.

> So I think Exception, ScriptError, StandardError and all
> non-builtin exceptions should be caught.
>
> Index: lib/test/unit/testcase.rb
> ===================================================================
> RCS file: /src/ruby/lib/test/unit/testcase.rb,v
> retrieving revision 1.7
> diff -u -p -r1.7 testcase.rb
> --- lib/test/unit/testcase.rb	4 Aug 2006 18:05:45 -0000	1.7
> +++ lib/test/unit/testcase.rb	3 Sep 2006 15:20:18 -0000
> @@ -70,7 +70,8 @@ module Test
>            __send__(@method_name)
>          rescue AssertionFailedError => e
>            add_failure(e.message, e.backtrace)
> -        rescue StandardError, ScriptError
> +        rescue Exception
> +          raise if [NoMemoryError, SignalException, Interrupt,  
> SystemExit].include? $!.class
>            add_error($!)
>          ensure
>            begin

I think the same code should be added to the teardown rescue.

-- 
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com



In This Thread