Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch added extra bytes to file when moving
CThule
#1 Posted : Friday, August 9, 2013 8:57:36 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/2/2013(UTC)
Posts: 3
Location: Denmark

Thanks: 2 times
Hi NCrunch.

Yesterday I experienced a weird issue.
When I used a local path (Resources\folder\data.txt) the file was 7583 bytes, whereas when I used the full path (C:\source\project\Resources\folder\data.txt) the file was 7580 bytes.
I know NCrunch moves the files to some user\appdata\ location, but when this happend, the file was also altered in some way.

I ran the exact same test with resharper to verify, that this was a NCrunch issue.
The test was pretty simple:

var bytes =
File.ReadAllBytes(
@"C:\source\project\Resources\folder\data.txt"); //I also tried with the bin/debug folder, same result
var bytes2 =
File.ReadAllBytes(
@"Resources\folder\data.txt");
Assert.AreEqual(bytes, bytes2);

Resharper ran this test and succeeded, however NCrunch added 3 bytes to the relative path file, the one it moved, so the test failed.

I cannot reproduce this, as a restart of visual studio fixed the problem.
Remco
#2 Posted : Friday, August 9, 2013 12:11:36 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi,

Thanks for posting!

I suspect this is the result of an encoding issue. Was the file open in the IDE at the time you were executing this test?

One of the unfortunate drawbacks of synchronising text file content with the IDE is that NCrunch has no clear knowledge of the encoding of the file was it used to be on disk before it was loaded by the IDE. Instead, it simply takes the text that the IDE provides and tries to reconstruct the file inside the workspace. If the text file isn't open in a Visual Studio editor, this process is much simpler as NCrunch can just make a binary copy of the file.

Because of the loss of information caused by the IDE loading the file, I recommend that you avoid performing binary comparisons on text content that can be opened in the IDE. Either treat the file as a binary resource (i.e. never open it), or adjust the test to perform the comparison using appropriate string load/compare functions.
2 users thanked Remco for this useful post.
CThule on 8/9/2013(UTC), yanglee on 8/9/2013(UTC)
CThule
#3 Posted : Friday, August 9, 2013 12:56:17 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/2/2013(UTC)
Posts: 3
Location: Denmark

Thanks: 2 times
I successfully reconstructed the case after your post.
If I open the file in the IDE (VS), remove a sign, type it again, save, then the test fails.
If I close the file again the test passes.

Thank you for your solution and explanation
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.034 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download