ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:67609] [ruby-trunk - Bug #10745] [Open] Special combinations of parameters in assert_equal (test/unit) may cause exceptions
       [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
@ 2015-01-15 16:26 ` herwin
  2015-01-16  0:09 ` [ruby-core:67610] [ruby-trunk - Bug #10745] " sawadatsuyoshi
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: herwin @ 2015-01-15 16:26 UTC (permalink / raw
  To: ruby-core

Issue #10745 has been reported by Herwin ..

----------------------------------------
Bug #10745: Special combinations of parameters in assert_equal (test/unit) may cause exceptions
https://bugs.ruby-lang.org/issues/10745

* Author: Herwin .
* Status: Open
* Priority: Low
* Assignee: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~
require 'test/unit'
require 'ipaddr'

class TestX < Test::Unit::TestCase
  def test_x
    assert_equal([IPAddr.new('1.2.3.4')], [[1,2,3]])
  end
end
~~~

This results in the following trace:

~~~
NoMethodError: undefined method `to_i' for [1, 2, 3]:Array
    /usr/lib/ruby/2.1.0/ipaddr.rb:471:in `initialize'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `new'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `coerce_other'
    /usr/lib/ruby/2.1.0/ipaddr.rb:150:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `assert_equal'
~~~

I don't think the assert_equals is supposed to throw these kind of errors



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:67610] [ruby-trunk - Bug #10745] Special combinations of parameters in assert_equal (test/unit) may cause exceptions
       [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
  2015-01-15 16:26 ` [ruby-core:67609] [ruby-trunk - Bug #10745] [Open] Special combinations of parameters in assert_equal (test/unit) may cause exceptions herwin
@ 2015-01-16  0:09 ` sawadatsuyoshi
  2015-01-16  1:12 ` [ruby-core:67611] [ruby-trunk - Bug #10745] [Rejected] " nobu
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: sawadatsuyoshi @ 2015-01-16  0:09 UTC (permalink / raw
  To: ruby-core

Issue #10745 has been updated by Tsuyoshi Sawada.


An interesting case. `assert_equal` seems to be assuming that the `==` method on the relevant class (`IPAddr#==` here) does not raise an error, but that should not be taken for granted. It should be wrapped in a rescue block.

----------------------------------------
Bug #10745: Special combinations of parameters in assert_equal (test/unit) may cause exceptions
https://bugs.ruby-lang.org/issues/10745#change-51029

* Author: Herwin .
* Status: Open
* Priority: Low
* Assignee: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~
require 'test/unit'
require 'ipaddr'

class TestX < Test::Unit::TestCase
  def test_x
    assert_equal([IPAddr.new('1.2.3.4')], [[1,2,3]])
  end
end
~~~

This results in the following trace:

~~~
NoMethodError: undefined method `to_i' for [1, 2, 3]:Array
    /usr/lib/ruby/2.1.0/ipaddr.rb:471:in `initialize'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `new'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `coerce_other'
    /usr/lib/ruby/2.1.0/ipaddr.rb:150:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `assert_equal'
~~~

I don't think the assert_equals is supposed to throw these kind of errors



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:67611] [ruby-trunk - Bug #10745] [Rejected] Special combinations of parameters in assert_equal (test/unit) may cause exceptions
       [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
  2015-01-15 16:26 ` [ruby-core:67609] [ruby-trunk - Bug #10745] [Open] Special combinations of parameters in assert_equal (test/unit) may cause exceptions herwin
  2015-01-16  0:09 ` [ruby-core:67610] [ruby-trunk - Bug #10745] " sawadatsuyoshi
@ 2015-01-16  1:12 ` nobu
  2015-01-16 12:03 ` [ruby-core:67627] [ruby-trunk - Bug #10745] " kou
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: nobu @ 2015-01-16  1:12 UTC (permalink / raw
  To: ruby-core

Issue #10745 has been updated by Nobuyoshi Nakada.

Description updated
Status changed from Open to Rejected

----------------------------------------
Bug #10745: Special combinations of parameters in assert_equal (test/unit) may cause exceptions
https://bugs.ruby-lang.org/issues/10745#change-51030

* Author: Herwin .
* Status: Rejected
* Priority: Low
* Assignee: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
require 'test/unit'
require 'ipaddr'

class TestX < Test::Unit::TestCase
  def test_x
    assert_equal([IPAddr.new('1.2.3.4')], [[1,2,3]])
  end
end
~~~

This results in the following trace:

~~~
NoMethodError: undefined method `to_i' for [1, 2, 3]:Array
    /usr/lib/ruby/2.1.0/ipaddr.rb:471:in `initialize'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `new'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `coerce_other'
    /usr/lib/ruby/2.1.0/ipaddr.rb:150:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `assert_equal'
~~~

I don't think the `assert_equal` is supposed to throw these kind of errors



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:67627] [ruby-trunk - Bug #10745] Special combinations of parameters in assert_equal (test/unit) may cause exceptions
       [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-01-16  1:12 ` [ruby-core:67611] [ruby-trunk - Bug #10745] [Rejected] " nobu
@ 2015-01-16 12:03 ` kou
  2015-01-16 12:34 ` [ruby-core:67628] " eregontp
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: kou @ 2015-01-16 12:03 UTC (permalink / raw
  To: ruby-core

Issue #10745 has been updated by Kouhei Sutou.


I think that it should be fixed in ipaddr.

The following code should print false instead of raising an exception:

```
% /tmp/local/bin/ruby -v -r ipaddr -e 'puts(IPAddr.new == [])'
ruby 2.3.0dev (2015-01-16 trunk 49282) [x86_64-linux]
/tmp/local/lib/ruby/2.3.0/ipaddr.rb:471:in `initialize': undefined method `to_i' for []:Array (NoMethodError)
	from /tmp/local/lib/ruby/2.3.0/ipaddr.rb:516:in `new'
	from /tmp/local/lib/ruby/2.3.0/ipaddr.rb:516:in `coerce_other'
	from /tmp/local/lib/ruby/2.3.0/ipaddr.rb:150:in `=='
	from -e:1:in `<main>'
```

----------------------------------------
Bug #10745: Special combinations of parameters in assert_equal (test/unit) may cause exceptions
https://bugs.ruby-lang.org/issues/10745#change-51049

* Author: Herwin .
* Status: Rejected
* Priority: Low
* Assignee: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
require 'test/unit'
require 'ipaddr'

class TestX < Test::Unit::TestCase
  def test_x
    assert_equal([IPAddr.new('1.2.3.4')], [[1,2,3]])
  end
end
~~~

This results in the following trace:

~~~
NoMethodError: undefined method `to_i' for [1, 2, 3]:Array
    /usr/lib/ruby/2.1.0/ipaddr.rb:471:in `initialize'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `new'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `coerce_other'
    /usr/lib/ruby/2.1.0/ipaddr.rb:150:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `assert_equal'
~~~

I don't think the `assert_equal` is supposed to throw these kind of errors



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:67628] [ruby-trunk - Bug #10745] Special combinations of parameters in assert_equal (test/unit) may cause exceptions
       [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-01-16 12:03 ` [ruby-core:67627] [ruby-trunk - Bug #10745] " kou
@ 2015-01-16 12:34 ` eregontp
  2015-01-16 22:15 ` [ruby-core:67641] " ruby-core
  2015-01-17 23:05 ` [ruby-core:67663] " sawadatsuyoshi
  6 siblings, 0 replies; 7+ messages in thread
From: eregontp @ 2015-01-16 12:34 UTC (permalink / raw
  To: ruby-core

Issue #10745 has been updated by Benoit Daloze.


Tsuyoshi Sawada wrote:
> An interesting case. `assert_equal` seems to be assuming that the `==` method on the relevant class (`IPAddr#==` here) does not raise an error, but that should not be taken for granted. It should be wrapped in a rescue block.

I disagree, the exception is more useful as an error than just assert_equal returning false.

Kouhei Sutou wrote:
> I think that it should be fixed in ipaddr.

Indeed, the error from IPAddr could be clearer,

----------------------------------------
Bug #10745: Special combinations of parameters in assert_equal (test/unit) may cause exceptions
https://bugs.ruby-lang.org/issues/10745#change-51050

* Author: Herwin .
* Status: Rejected
* Priority: Low
* Assignee: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
require 'test/unit'
require 'ipaddr'

class TestX < Test::Unit::TestCase
  def test_x
    assert_equal([IPAddr.new('1.2.3.4')], [[1,2,3]])
  end
end
~~~

This results in the following trace:

~~~
NoMethodError: undefined method `to_i' for [1, 2, 3]:Array
    /usr/lib/ruby/2.1.0/ipaddr.rb:471:in `initialize'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `new'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `coerce_other'
    /usr/lib/ruby/2.1.0/ipaddr.rb:150:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `assert_equal'
~~~

I don't think the `assert_equal` is supposed to throw these kind of errors



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:67641] [ruby-trunk - Bug #10745] Special combinations of parameters in assert_equal (test/unit) may cause exceptions
       [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-01-16 12:34 ` [ruby-core:67628] " eregontp
@ 2015-01-16 22:15 ` ruby-core
  2015-01-17 23:05 ` [ruby-core:67663] " sawadatsuyoshi
  6 siblings, 0 replies; 7+ messages in thread
From: ruby-core @ 2015-01-16 22:15 UTC (permalink / raw
  To: ruby-core

Issue #10745 has been updated by Marc-Andre Lafortune.


Benoit Daloze wrote:
> Tsuyoshi Sawada wrote:
> > An interesting case. `assert_equal` seems to be assuming that the `==` method on the relevant class (`IPAddr#==` here) does not raise an error, but that should not be taken for granted. It should be wrapped in a rescue block.
> 
> I disagree, the exception is more useful as an error than just assert_equal returning false.

Agreed.

> Indeed, the error from IPAddr could be clearer,

Mmm, not quite. Calling `==` should never raise, so there should not be an error.

----------------------------------------
Bug #10745: Special combinations of parameters in assert_equal (test/unit) may cause exceptions
https://bugs.ruby-lang.org/issues/10745#change-51062

* Author: Herwin .
* Status: Rejected
* Priority: Low
* Assignee: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
require 'test/unit'
require 'ipaddr'

class TestX < Test::Unit::TestCase
  def test_x
    assert_equal([IPAddr.new('1.2.3.4')], [[1,2,3]])
  end
end
~~~

This results in the following trace:

~~~
NoMethodError: undefined method `to_i' for [1, 2, 3]:Array
    /usr/lib/ruby/2.1.0/ipaddr.rb:471:in `initialize'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `new'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `coerce_other'
    /usr/lib/ruby/2.1.0/ipaddr.rb:150:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `assert_equal'
~~~

I don't think the `assert_equal` is supposed to throw these kind of errors



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:67663] [ruby-trunk - Bug #10745] Special combinations of parameters in assert_equal (test/unit) may cause exceptions
       [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2015-01-16 22:15 ` [ruby-core:67641] " ruby-core
@ 2015-01-17 23:05 ` sawadatsuyoshi
  6 siblings, 0 replies; 7+ messages in thread
From: sawadatsuyoshi @ 2015-01-17 23:05 UTC (permalink / raw
  To: ruby-core

Issue #10745 has been updated by Tsuyoshi Sawada.


Benoit Daloze wrote:
>  I disagree, the exception is more useful as an error than just assert_equal returning false.

According to http://docs.ruby-lang.org/ja/2.1.0/method/Test=3a=3aUnit=3a=3aAssertions/i/assert_equal.html, it should raise `MiniTest::Assertion` error, which should wrap the message and backtrace from the `NoMethodError`. It should not raise a `NoMethodError`. This is a bug of minitest in that it could not properly handle the test object's (ipaddr) bug.

----------------------------------------
Bug #10745: Special combinations of parameters in assert_equal (test/unit) may cause exceptions
https://bugs.ruby-lang.org/issues/10745#change-51080

* Author: Herwin .
* Status: Rejected
* Priority: Low
* Assignee: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
require 'test/unit'
require 'ipaddr'

class TestX < Test::Unit::TestCase
  def test_x
    assert_equal([IPAddr.new('1.2.3.4')], [[1,2,3]])
  end
end
~~~

This results in the following trace:

~~~
NoMethodError: undefined method `to_i' for [1, 2, 3]:Array
    /usr/lib/ruby/2.1.0/ipaddr.rb:471:in `initialize'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `new'
    /usr/lib/ruby/2.1.0/ipaddr.rb:516:in `coerce_other'
    /usr/lib/ruby/2.1.0/ipaddr.rb:150:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `=='
    /usr/lib/ruby/2.1.0/test/unit/assertions.rb:250:in `assert_equal'
~~~

I don't think the `assert_equal` is supposed to throw these kind of errors



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-01-17 23:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-10745.20150115162601@ruby-lang.org>
2015-01-15 16:26 ` [ruby-core:67609] [ruby-trunk - Bug #10745] [Open] Special combinations of parameters in assert_equal (test/unit) may cause exceptions herwin
2015-01-16  0:09 ` [ruby-core:67610] [ruby-trunk - Bug #10745] " sawadatsuyoshi
2015-01-16  1:12 ` [ruby-core:67611] [ruby-trunk - Bug #10745] [Rejected] " nobu
2015-01-16 12:03 ` [ruby-core:67627] [ruby-trunk - Bug #10745] " kou
2015-01-16 12:34 ` [ruby-core:67628] " eregontp
2015-01-16 22:15 ` [ruby-core:67641] " ruby-core
2015-01-17 23:05 ` [ruby-core:67663] " sawadatsuyoshi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).