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

Notification

Icon
Error

Bug with combination of catch-when and params arguments
jarlelin
#1 Posted : Wednesday, September 14, 2016 11:56:59 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/17/2015(UTC)
Posts: 4
Location: Norway

I was getting the "System.InvalidProgramException : Common Language Runtime detected an invalid program" in some of my tests when running ncrunch, but I don't get that problem when using other test runners.

Disabling "Instrument Output Assembly" works and the tests run, but I lose my code coverage visibility and exception inspection via ncrunch pills.

I could not find any information on this issue, but I have narrowed the problem down to a comination of the catch() when() syntax and using the params keyword (if you pass more than 1 item to the params array). This is particularly a problem because we often want to log something in our catches and the logger often uses params for templates.


Quote:
//THIS TEST PASSES
[Test]
public void NoCatchWhen()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) //when (e.Message == "1")
{
Console.WriteLine("Testing problem with {0} in {1}", "clr", "ncrunch");
}
}

//THIS TEST PASSES
[Test]
public void CatchWenAndNoLoggingOfParamArgs()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) when (e.Message == "1")
{
Console.WriteLine("logstatement");
}
}

//THIS TEST PASSES
[Test]
public void WithCatchWhenAndLoggingOfASingleParamArgument()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) when (e.Message == "1")
{
Console.WriteLine("Testing problem with {0}", "ncrunch-clr");
}
}

//THIS TEST FAILS
[Test]
public void WithCatchWhenAndLoggingOfAMultipleParamArgument()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) when (e.Message == "1")
{
//attempting to pass 2 or more arguments into the params array in any method results in the whole method returning CLR-error
Console.WriteLine("Testing problem with {0} in {1} because {2}", "clr", "ncrunch", "resons");
}
}



Is there a better fix to this than disabling ncrunch instrumentation?
jarlelin
#2 Posted : Wednesday, September 14, 2016 12:06:37 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/17/2015(UTC)
Posts: 4
Location: Norway

I'm running nCrunch 2.23.0.2 with Visual Studio 2015 Update 3 and using NUnit for my testing needs.
Remco
#3 Posted : Wednesday, September 14, 2016 8:54:00 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi,

Thanks for sharing this issue. I'm fairly certain this is being caused by an IL sequence that is being affected by NCrunch's instrumentation. You can work around the problem by placing code coverage suppression comments around the code block, for example:

//THIS TEST FAILS
[Test]
public void WithCatchWhenAndLoggingOfAMultipleParamArgument()
{
try
{
throw new ApplicationException("1");
}//ncrunch: no coverage start
catch (ApplicationException e) when (e.Message == "1")
{
//attempting to pass 2 or more arguments into the params array in any method results in the whole method returning CLR-error
Console.WriteLine("Testing problem with {0} in {1} because {2}", "clr", "ncrunch", "resons");
}//ncrunch: no coverage end
}

I've been having trouble reproducing this problem myself. I'm wondering if you can share some more details about your environment. Which version of .NET are you running under? Which O/S are you on?
jarlelin
#4 Posted : Thursday, September 15, 2016 12:42:46 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/17/2015(UTC)
Posts: 4
Location: Norway

Using ncrunch-specific code suppression comments is not going to cut it I'm afraid.

The projects are running .NET 4.6.1, but I tried a couple more just to check.
I'm running windows 10 (Ent). I'm afraid I won't be able to easily test this on other OSes.
jarlelin
#5 Posted : Thursday, September 15, 2016 1:37:43 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/17/2015(UTC)
Posts: 4
Location: Norway

I tried to reproduce it in a new solution and couldn't. Not until I turned ON "Instrunment assembly outbut", but OFF "Analyse line execution times".

So with those settings changed I managed to reproduce the failure of the last test in my example in a completely fresh solution on windows 10 under .net 4.6.1.
Remco
#6 Posted : Thursday, September 15, 2016 10:29:27 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Ok, that did the trick. I can reproduce this problem now. Thanks for letting me know about it. I'll see what I can do about getting it fixed. The following options can be used as workarounds:

- Code coverage suppression comments around the 'when'
- Turning off instrumentation
- Turning on Analyse line execution times
adandy
#7 Posted : Monday, November 28, 2016 4:57:08 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/27/2014(UTC)
Posts: 2
Location: United States of America

Thanks: 1 times
I also ran into this issue but was only able to test my project by turning off instrumentation. I would really like to use the coverage feature to help debug test failures in this code.
Remco
#8 Posted : Monday, November 28, 2016 9:51:19 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
A fix for this problem is being released today with V3.
1 user thanked Remco for this useful post.
adandy on 11/28/2016(UTC)
adandy
#9 Posted : Monday, November 28, 2016 11:46:51 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/27/2014(UTC)
Posts: 2
Location: United States of America

Thanks: 1 times
Awesome. Have a gif: http://i.imgur.com/fcI43vR.gifv !
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.056 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download