Throws.Nothing doesn't work properly

Bug #666800 reported by Michael Naumov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Fix Released
Low
Charlie Poole

Bug Description

The folowing Assert shouldn't fail but it fails

[Test]
public void NotThrown()
{
    Assert.That(() => null, Throws.Nothing);
}

NUnitBug.Tester.NotThrown:
System.ArgumentException : The actual value must be a TestDelegate
Parameter name: actual

at NUnit.Framework.Constraints.ThrowsNothingConstraint.Matches(Object actual)
at NUnit.Framework.Constraints.Constraint.Matches(ActualValueDelegate del)
at NUnitBug.Tester.NotThrown()

Tags: easy

Related branches

Revision history for this message
Michael Naumov (mnaoumov) wrote :

Tested on the latest version of NUnit: 2.5.8.10295

Due to source code it seems to be issue in the fact that
ThrowsNothingConstraint class doesn't override the following method from Constraint class

public virtual bool Matches(ActualValueDelegate del)
{
    return this.Matches(del());
}

it's should be overriden with

 public override bool Matches(ActualValueDelegate del)
    {
      TestDelegate actual = delegate {
        del();
      };
      return this.Matches(actual);
    }

(like in ThrowsConstraint class)

Changed in nunitv2:
status: New → Triaged
importance: Undecided → Low
tags: added: easy
Changed in nunitv2:
milestone: none → 2.5.9
assignee: nobody → Charlie Poole (charlie.poole)
Changed in nunitv2:
status: Triaged → Fix Committed
Changed in nunitv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.