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

Notification

Icon
Error

NCrunch strips out conditional defines
ncrunchuser1
#1 Posted : Wednesday, July 29, 2015 2:50:00 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
I created a .targets file that is to be imported into .csproj files. This .targets file adds conditional defines based on settings it finds in the project file.

I imported this into the .csproj of a test project that verifies that the defines are set correctly but NCrunch is stripping out the new defines. I even tried manually added defines in Properties|Build but with the same result. The only define that survives is DEBUG - it's stripping out TRACE as well.

Is there some configuration that controls this behavior or is there a known limitation in NCrunch?

Environment:

VS 2015
SpecFlow (the SpecFlow runner passes the test correctly - MsTest as well)
Remco
#2 Posted : Wednesday, July 29, 2015 5:06:32 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for sharing this issue.

NCrunch does perform some manipulation of the project file when preparing for a build. It won't touch imported targets files.

Can you share any more details about the defines involved? Is it possible that this is just a case of configuration/platform difference? (see http://www.ncrunch.net/documentation/considerations-and-constraints_project-build-platform-and-configuration).
1 user thanked Remco for this useful post.
ncrunchuser1 on 7/29/2015(UTC)
ncrunchuser1
#3 Posted : Wednesday, July 29, 2015 3:04:45 PM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Thanks Remco!

You pointed me in the right direction and I figured it out after some digging. There were two issues.

1. Using the incorrect relative path to import the .targets file

The .targets file is located in the solution folder. I had the import as:
Quote:
<Import Project="$(MSBuildThisFileDirectory)..\CodeContracts.targets" />


I noticed in the NCrunch temporary folder that this file was not copied over. Changing to the following fixed the issue:
Quote:
<Import Project="..\CodeContracts.targets" />


Now the file gets copied to the NCrunch temporary folder in the correct relative location.

2. NCrunch does not see Configuration Manager settings.

The defines are different based on if building in Debug or Release mode. In the Configuration Manager, I specified the appropriate configuration for the project regardless of the active solution configuration. This works for mstest and SpecFlow but apparently, NCrunch does not see this configuration.

Fix: Changed the NCrunch configuration setting "Use build configuration" for the projects to Debug or Release as appropriate (only seems to be a problem with Release but I explicitly set Debug as well, just in case).


Quick followup question:

Is it possible to have NCrunch run the test using all the configurations? If not, this would be a great feature to have :)

Right now, I'm creating a separate project per configuration that I need - which is quite a few. It would be much nicer to have one project and several configurations.
ncrunchuser1
#6 Posted : Wednesday, July 29, 2015 6:26:57 PM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Remco,

I did find an inconsistency between NCrunch and Code Contracts. The "Perform Runtime Contract Checking" and "Perform Static Contract Checking" options are written by Code Contracts as:

Code:
<CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>
<CodeContractsEnableRuntimeChecking>False</CodeContractsEnableRuntimeChecking>
<CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
<CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis>


When disabling these with the NCrunch configuration items "Allow dynamic code contract checking" and "Allow static code contract checking", they end up being written as:

Code:
<CodeContractsEnableRuntimeChecking>false</CodeContractsEnableRuntimeChecking>
<CodeContractsRunCodeAnalysis>false</CodeContractsRunCodeAnalysis>


Code Contracts starts with an uppercase letter, NCrunch with a lowercase one. There's a simple workaround for me but just thought you should know.
Remco
#4 Posted : Wednesday, July 29, 2015 10:54:17 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
ncrunchuser1;7540 wrote:
Thanks Remco!
Quick followup question:

Is it possible to have NCrunch run the test using all the configurations? If not, this would be a great feature to have :)

Right now, I'm creating a separate project per configuration that I need - which is quite a few. It would be much nicer to have one project and several configurations.


I'm afraid that this would be extremely hard to implement given NCrunch in its current form, but it isn't impossible. You're welcome to request it as a feature if you like.
1 user thanked Remco for this useful post.
ncrunchuser1 on 7/30/2015(UTC)
Remco
#7 Posted : Wednesday, July 29, 2015 10:56:18 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
ncrunchuser1;7543 wrote:
Remco,

I did find an inconsistency between NCrunch and Code Contracts. The "Perform Runtime Contract Checking" and "Perform Static Contract Checking" options are written by Code Contracts as:

Code:
<CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>
<CodeContractsEnableRuntimeChecking>False</CodeContractsEnableRuntimeChecking>
<CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
<CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis>


When disabling these with the NCrunch configuration items "Allow dynamic code contract checking" and "Allow static code contract checking", they end up being written as:

Code:
<CodeContractsEnableRuntimeChecking>false</CodeContractsEnableRuntimeChecking>
<CodeContractsRunCodeAnalysis>false</CodeContractsRunCodeAnalysis>


Code Contracts starts with an uppercase letter, NCrunch with a lowercase one. There's a simple workaround for me but just thought you should know.


Are you able to confirm whether this caused any operational problems in how these flags are recognised? I would have thought that the build tasks wouldn't care. I'm fairly certain these overrides were thoroughly tested .. Hopefully we're not seeing some kind of version-specific behaviour here. It would be rather annoying to need to adjust capitalisation based on the version of Code Contracts that's in use.
ncrunchuser1
#8 Posted : Thursday, July 30, 2015 3:49:40 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
I didn't check if it affected the operation of Code Contracts - my code is doing the standard " '$(var)' == 'False' " - which is why I caught it. It's possible their code only checks for 'True' and since NCrunch only ever sets to 'false' (at least that's what I've deduced), it would be OK. I'm in the middle of a bunch of changes right now. Once I'm done I'll test and let you know. Hopefully within the next day or two.
1 user thanked ncrunchuser1 for this useful post.
Remco on 7/30/2015(UTC)
ncrunchuser1
#9 Posted : Saturday, August 1, 2015 8:49:13 PM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Remco,

I tested the "Allow dynamic code contract checking" setting and got the following results:


  1. Calling Contract.Requires() - NCrunch shows an assert dialog
  2. Calling Contract.Requires<E>() - NCrunch shows a dialog that Code Contracts needs to be enabled


I'm not sure how to test the "Allow static code contract checking" setting because the "Fail build on warnings" setting seems to be broken in Code Contracts for VS 2015.
Remco
#10 Posted : Saturday, August 1, 2015 10:13:49 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Does enabling both settings make any difference? There is the possibility that one setting is reliant on the other.
ncrunchuser1
#11 Posted : Sunday, August 2, 2015 3:07:25 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Which two settings are you referring to? If you are talking about the Code Contracts page and the "Perform Static Contract Checking" and "Fail build on warnings", they are both checked. When I close the page and re-open it, the "Fail build on warnings" setting is grayed out (but still checked). The build doesn't fail even though there are static analysis warnings. This is without even running NCrunch.
ncrunchuser1
#12 Posted : Sunday, August 2, 2015 3:52:30 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
I did get the "Fail build on warnings" setting to work - there was another setting, "Check in background" that needed to be unchecked. Once this was on, turning on the NCrunch setting "Allow static code contract checking" fails the test with the following:

Code:

NCrunch experienced an unexpected error while trying to process results from this build: System.Exception: Unable to retrieve property values from expression in build output: $(OutDir)$(TargetName)$(TargetExt)
   at .  (IList`1 )
   at ..( )
   at nCrunch.Common.Containers.ListExtensions.Do[T](IEnumerable`1 list, Action`1 action)
   at .(IList`1 )
   at  .(IList`1 )
   at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)


Not the most informative but it gets the job done.
Remco
#13 Posted : Sunday, August 2, 2015 11:40:38 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
The error message you're receiving is likely because of the way that code contracts reports errors. It does, unfortunately, have some consistently problems in the way it does this.

Normally I recommend leaving code contracts disabled, because it has a massive impact on build times. The static checking in particular can greatly slow down NCrunch response times.
ncrunchuser1
#14 Posted : Sunday, August 2, 2015 1:41:17 PM(UTC)
Rank: Member

Groups: Registered
Joined: 7/21/2015(UTC)
Posts: 13

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Thanks Remco. Normally I would leave it off. This set of tests is for a library I created to allow switching between Code Contracts and legacy if-then-throw and asserts so unfortunately, I need it on.
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.083 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download