← Back to team overview

nunit-core team mailing list archive

[Bug 1051847] Re: self contained item in array causes stack overflow

 

Hello Simone

As I wrote, I'm trying to infer the correct behavior of Contains from the current documentation.
As Contains is now documented as identity assertion, yes, I expect it should check identity equality.

I guess that if it was implemented like this, this bug would disappear.

Whether Contains does identity or equality checking is a design
decision. Apparently, equality checking is more difficult to do.

The implementation now seems to perform equality checking, where the
documentation indicates it should do identity checking. If the final
resolution was to stick with equality checking, I'd expect Contains to
be documented in the equality asserts section, no longer in the identity
asserts section.

Checking for identity is easier to implement. But doing so is a breaking
change. So I cannot give a final suggestion.

-- 
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/1051847

Title:
  self contained item in array causes stack overflow

Status in NUnit V2 Test Framework:
  Confirmed

Bug description:
  using System.Collections;
  using System.Collections.Generic;
  using NUnit.Framework;

  [TestFixture]
  public class Reproduction {
  	class SelfContainer : IEnumerable { public IEnumerator GetEnumerator() { yield return this; } }

  	[Test]
  	public void SelfContainedItemFoundInArray() {
  		var item = new SelfContainer();
  		var items = new SelfContainer[] { new SelfContainer(), item };

  		// work around
  		Assert.True(((ICollection<SelfContainer>)items).Contains(item));

  		// causes StackOverflowException
  		Assert.Contains(item, items);
  	}
  }

  Reproduced in NUnit 2.6.1

  See also bug #491300

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunitv2/+bug/1051847/+subscriptions


References