ToString not working properly for some properties

Bug #605432 reported by Dale King
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
High
Charlie Poole
NUnit V2
Fix Released
Critical
Charlie Poole

Bug Description

The following code:

            Console.WriteLine(Has.Property("foo").EqualTo("bar"));
            Console.WriteLine(Has.Property("foo").EqualTo("bar").And.Property("baz").EqualTo("qux"));
            Console.WriteLine(Has.Property("foo").EqualTo("bar") & Has.Property("baz").EqualTo("qux"));

prints the following

<equal "bar">
<equal "qux">
<and <property foo <equal "bar">> <property baz <equal "qux">>>

Only the last one is correct.

Related branches

Revision history for this message
Dale King (dalewking) wrote :

Looking through the code it appears the problem here is that Constraint.ToString does not check to see if the constaint has a builder. I believe that if builder is not null then it needs to call ToString on the builder.

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Ah. That makes it less serious than I feared. In our tests, ToString is normally only called on a constraint that has been resolved... I'll see if your suggestion works. If not, I'll put some indication in the output that it's an unresolved constraint. We definitely don't want ToString() to resolve the constraint as a side effect.

Changed in nunitv2:
importance: Undecided → Critical
status: New → Triaged
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.5.6
Revision history for this message
Charlie Poole (charlie.poole) wrote :

After giving it some thought, I fixed this by having ToString() produce output that clearly indicates the constraint is unresolved. So, for example, Console.WriteLine( Is.Not.All.EqualTo(5).ToString() ) produces <unresolved <equal 5>>

While not giving all the info, this clearly warns the person using ToString() that something is amiss.

The repeatability issue, which is related to this problem, will be fixed separately.

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

Other bug subscribers