SteveGilham / altcover

Cross-platform coverage gathering and processing tool set for dotnet/.Net Framework and Mono
MIT License
494 stars 17 forks source link

Request configurable InstrumentedDirectory #185

Closed CasperNLD closed 1 year ago

CasperNLD commented 1 year ago

Hi,

I hereby would like to request a new feature: I would like to have the InstrumentedDirectory configurable. In the current version 8.6.45 this property is set in the AltCover.targets file .

I would like to have this targets file changed: if AltCoverInstrumentedDirectory is already set as property, then use this. Suggestion: <AltCoverInstrumentedDirectory Condition="'$(AltCoverInstrumentedDirectory)'=''">$([System.IO.Path]::Combine($(TargetDir), '__Instrumented'))</AltCoverInstrumentedDirectory>

I hope this can be added soon.

In my case we have separated production and test projects, and the production code under test uses a relative path. By making the instrumental folder a subfolder, the lookup fails.

Thanks for taking this into advisement.

SteveGilham commented 1 year ago

This looks like the use-case for which the in-place option was created - copying the as-built test code to one side, and instrumenting back into the original location to run the tests, activated by adding

<AltCoverInPlace>true</AltCoverInPlace>

If a third place is in fact necessary, the actual change will have to be more pervasive than the one-liner above as it implicitly adds to the customisation API.

As a workround overriding the VSTest target again in your project file and specifying the AltCoverInstrumentedDirectory property there should serve your purpose

  <!-- Override Microsoft.TestPlatform.targets to do coverage work -->
  <Target Name="VSTest" DependsOnTargets="ShowInfoMessageIfProjectHasNoIsTestProjectProperty">
  <PropertyGroup>
    <AltCoverInstrumentedDirectory>Your value goes here</AltCoverInstrumentedDirectory>
  </PropertyGroup>

    <CallTarget Targets="AltCoverVSTestPreFlight" ContinueOnError="ErrorAndStop" />
    <CallTarget Targets="AltCoverVSTestCore" />
  </Target>
CasperNLD commented 1 year ago

Hi, Thanks for the reply. I have already tried the --inplace option, however it does not tests everything and gives 'already instrumented' warnings. I haven't investigated mitigating these problems via an other way, Using a separate 'instrumented' directory did work as preferred. If you do not prefer such a change, I have to look into why I they are already instrumented. (seems a lot more work) I was hoping to do all these in one pipeline step and not to create a entire extra build and test step to evade this warning and incomplete tests.

Using props and targets files is in our case not an preferred option: We build own own environment separate and adding such files is my last option.

Is adding the AltCoverInstrumentedDirectory option to the API a possible one?

SteveGilham commented 1 year ago

Adding to the API is no big deal - it's really a question if whether it was necessary or not.

CasperNLD commented 1 year ago

Hmm, I'll try your suggestion first (overriding VStest). Thanks.