skaliber / mb-unit

Automatically exported from code.google.com/p/mb-unit
0 stars 0 forks source link

Compare files of FileAssert by clicking a hyperlink #275

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I often use file comparison in my unit tests but the representation of the 
result isn’t what I want. When I use FileAssert.AreEqual(@"C:
\FileA.txt",@"C:\FileB.txt") and files are different the result is 
following:

  Expected Stream length 66 but was 96.
   at NUnit.Framework.Assert.That(Object actual, Constraint constraint, 
String message, Object[] args)
   at NUnit.Framework.FileAssert.AreEqual(String expected, String actual, 
String message, Object[] args)
   at NUnit.Framework.FileAssert.AreEqual(String expected, String actual, 
String message)
   at utSession.utSessionWriter.TestSavingSessionFolder() in D:\PROJECTS
\dicc71083\source\UnitTests\utSession\utSessionWriter.cs:line 77

However, I’d like to know what the difference is and be able to compare 
the files quickly. For my case following assert is more informative, 
because at least it writes out string fragments where files differ:
Assert.AreEqual(
  File.ReadAllText(@"C:\FileA.txt"), 
  File.ReadAllText(@"C:\FileB.txt")
);

  Expected string length 66 but was 96. Strings differ at index 48.
  Expected: "...\n1234\r\n1234\r\n1234\r\n1234\r\n1234\r\n"
  But was:  "...\n1234\r\n1234\r\n6789\r\n6789\r\n6789\r\n6789\r\n6789\r
\n1234\r\n1234\r\n1234\r\n"
  --------------------------------^
   at NUnit.Framework.Assert.That(Object actual, Constraint constraint, 
String message, Object[] args)
   at NUnit.Framework.Assert.AreEqual(Object expected, Object actual, 
String message)
   at utSession.utSessionWriter.TestSavingSessionFolder() in D:\PROJECTS
\dicc71083\source\UnitTests\utSession\utSessionWriter.cs:line 77

Nevertheless, it is still not satisfactory because the information 
provided is incomplete and I can’t compare files quickly. In order to 
tackle the problem I suggest providing of a hyperlink mechanism in the 
GUI. The message may look as following (see the image attached).

As a first step, this could be done by virtue of the assert message:

FileAssert.AreEqual(
  @"C:\FileA.txt",
  @"C:\FileB.txt", 
 Files {0} and {1} are different (link:compare(‘click to compare’, ‘{0}’, 
‘{1}’))
);

In future this can be a default message for this kind of asserts.

The link definition (link:compare(‘click to compare’, ‘C:\FileA.txt’, 
‘C:
\FileB.txt’) can be parsed and shown as a hyperlink. A hyperlink handler 
may work like that:

void HandleHyperLink(a_actionId, object[] a_params)
{
  if (a_actionId == “compare”) {
    RunDiffTool(params[0] as string, params[1] as string);
  } else if ...
}

Potentially, it opens the way for future extensions based on hyperlinks.

Original issue reported on code.google.com by ncuxua...@gmail.com on 16 Jul 2008 at 12:55

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry, certainly this is not a defect, but rather a wish

Original comment by ncuxua...@gmail.com on 16 Jul 2008 at 12:58

GoogleCodeExporter commented 8 years ago
What do you expect to happen when you click the link? Both files opened, or 
something
more advanced? (a visual diff maybe?).

Original comment by grahamr...@gmail.com on 19 Jul 2008 at 9:24

GoogleCodeExporter commented 8 years ago
I'd like to run an application or a script specified somewhere in the settings. 
It 
is supposed to be a visual diff application but anyway this setting must be up 
to 
user. There are lots of diff-like applications such as Araxis Merge (this one I 
use), WinDiff and so on.

Original comment by ncuxua...@gmail.com on 21 Jul 2008 at 12:08

GoogleCodeExporter commented 8 years ago
Gallio now has a DiffSet class providing diffs.
The diffs can also be written to the report with highlighting and other goodies.

So now we have the means to implement this enhancement.

Original comment by jeff.br...@gmail.com on 18 Sep 2008 at 8:40

GoogleCodeExporter commented 8 years ago

Original comment by jeff.br...@gmail.com on 19 Nov 2008 at 11:58