Occasionally I run into a mismatch of line numbers and filenames, (the line number is correct, but the filename isn't), and it differs from the stacktrace provided when running it without ncrunch.
I'm running ncrunch 1.44.0.11 in vs2012 update 1 on windows 8; the following code (with mstest) causes the problem for me:
Parent.cs:
Code:
namespace UnitTestProject
{
using System.Diagnostics.Contracts;
[ContractClass(typeof(ParentContracts))]
public abstract class Parent
{
public abstract void ChildThrowsException();
}
[ContractClassFor(typeof(Parent))]
public class ParentContracts : Parent
{
public override void ChildThrowsException()
{
Contract.Requires(true);
}
}
}
UnitTest.cs:
Code:
namespace UnitTestProject
{
using System.Diagnostics.Contracts;
[ContractClassFor(typeof(Parent))]
public class ParentContracts : Parent
{
public override void ChildThrowsException()
{
Contract.Requires(true);
}
}
[ContractClass(typeof(ParentContracts))]
public abstract class Parent
{
public abstract void ChildThrowsException();
}
}
Running it in ncrunch gives me the following stacktrace:
Code:
System.Exception: Exception of type 'System.Exception' was thrown.
at UnitTestProject.Child.ChildThrowsException() in D:\CSharpConsoleSandBox\UnitTestProject\Parent.cs:line 10#0
at UnitTestProject.UnitTest.TestMethod1() in D:\CSharpConsoleSandBox\UnitTestProject\UnitTest.cs:line 21#1
Along with this, navigation and markers don't work properly. The marker and navigation match the above stacktrace, so it takes me to the wrong file/line, and shows an 'x' on the line indicated in the stack trace (if possible/there happens to be a line of executable code there).
The line the exception was really thrown is indicated as being hit by code coverage, but not part of the exception path (filled red circle).
Running it in vs's test runner gives me the following stacktrace: (note the different filenames)
Code:
System.Exception: Exception of type 'System.Exception' was thrown.
Result StackTrace:
at UnitTestProject.Child.ChildThrowsException() in d:\CSharpConsoleSandBox\UnitTestProject\UnitTest.cs:line 10
at UnitTestProject.UnitTest.TestMethod1() in d:\CSharpConsoleSandBox\UnitTestProject\UnitTest.cs:line 21
If I move the ParentContracts class into the same file as the Child class, the files and line numbers match up in the stacktrace, and the navigation and line markers match up properly also.
If I remove the Contract.Requires(true); line above, or disable runtime contract checking (so cc's rewriter doesn't add any code that's really in ParentContracts to Child's method), the problem goes away then also.