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

Notification

Icon
Error

NCrunch doesn't assign default values to nullable types
derfel
#1 Posted : Wednesday, December 5, 2012 4:16:16 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/5/2012(UTC)
Posts: 6
Location: Australia

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
I'm using NCrunch 1.42.0.12 with VS 2012.

I've seen a strange issue where nullable types aren't assigned default values (for optional params in C#)

public void HasValue(bool? yes = true)
{
if(!yes.HasValue)
throw new Exception("yes is not true");
}


When invoking this method with HasValue(); you'd expected the parameter 'yes' to be set.
Running this through Resharper the optional parameter is set, but through NCrunch it comes out as a null.

I've disabled parallel running of tests as well. I submitted this as a bug report but though I'd get to see any progress/comments here instead.
Remco
#2 Posted : Wednesday, December 5, 2012 4:26:36 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for reporting this problem.

The issue appears to be related to NCrunch's instrumentation of the assembly containing this method. For some reason, the instrumentation is dropping a critical piece of metadata (namely, the '= true') from the parameter. Methods calling 'HasValue' will work normally if they are inside the same assembly as this method, although they fail if they call it across assembly boundaries.

I'll see if I can get a fix for this included in 1.43, which is due out within the next few days. Thanks again for reporting the issue and providing the clear steps to reproduce it.


Cheers,

Remco
derfel
#3 Posted : Wednesday, December 5, 2012 4:36:31 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/5/2012(UTC)
Posts: 6
Location: Australia

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Thanks for the swift response.

Just to add a note, default values work with reference types.

Therefore running the following method works as expected, with bar being assigned the default value "ncrunch"

public void Foo (string bar = "ncrunch") {

}
1 user thanked derfel for this useful post.
Remco on 12/5/2012(UTC)
Remco
#4 Posted : Monday, December 10, 2012 4:51:36 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
For anyone interested, 1.43 has just been released with a fix for the above problem.
1 user thanked Remco for this useful post.
derfel on 12/11/2012(UTC)
derfel
#5 Posted : Tuesday, December 11, 2012 3:41:30 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/5/2012(UTC)
Posts: 6
Location: Australia

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Remco;3385 wrote:
For anyone interested, 1.43 has just been released with a fix for the above problem.


I can confirm this has been fixed. Thanks Remco!
1 user thanked derfel for this useful post.
Remco on 12/11/2012(UTC)
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.038 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download