Menu

#3 approved.txt files created without byte order mark

open
nobody
None
5
2012-05-01
2012-05-01
Tom Hunter
No

I'm running new tests without first creating an approved.txt file and I'm finding that when the GenericDiffReporter creates the approved.txt file it's empty (which is fine), but that the diff tool (both Tortoise and BeyondCompare) treat it as an ANSI file. Using the diff tool I then copy all the lines from the received file (encoded in UTF-8) to the approved file and save it. Next time I run the test I expect the test to pass but it doesn't because the received file is encoded as UTF-8 and the approved file is encoded as ANSI.

I've amended the FileUtilities.EnsureFileExists method as follows to ensure the approved file is created as UTF-8 (by writing a UTF-8 BOM):

public static void EnsureFileExists(string approved)
{
if (!File.Exists(approved))
{
using (var f = File.Create(approved))
{
byte[] bom = (new UTF8Encoding(true)).GetPreamble();
f.Write(bom, 0, bom.Length);
}
}
}

Discussion