-
Notifications
You must be signed in to change notification settings - Fork 248
Quotes are not working for target or targetargs #140
Comments
The environment variables are expanded before being passed to opencover and it looks like you have spaces in your path name. The Usage Wiki describes that arguments with spaces in them have to be escaped with ". I recommend you create a new variable with escaped paths for use with OpenCover. |
That also doesn't work.
I get the following error...
I triple checked the path and it is correct. The target and the targetArgs just should support the quotes just like the output does. When I remove the spaces from my path then it just works as expected. |
Okay, I'll see if I can repeat. Have you tried without using variables and then working backwards to variables? Also you could also try
or
|
I have found several ways to resolve this using a path to my nunit-console runner with a space in the path
expands and runs properly Alternatively
expands and runs properly I think you just need to work on the batch script - perhaps see what the environment variable are expanding to |
My batch file is correct. Opencover just can't handle the spaces/quotes. When I echo my variable it shows me the complete directory. So my variables are correct. The same variables do work with mspecrunner, nunit etc. For me it can't be more than clear OpenCover is the issue. |
Well it does handle spaces as I have shown above so the issue isn't as clear cut as you think. Perhaps you should supply me with a "complete" sample of what doesn't work as I obviously can't repeat your issue. |
I'm running into some same issues using opencover in msbuild. I have tried a lot using quotes in different ways for target args, target etc.. However I can't figure out what is going wrong. Can you please help me? I also tried to find some docs about the usage of the msbuild target file to execute opencover, so this could also be an option for the solution, because this is also included in the nuget package. Hoping you can help me out with this one. <Target Name="CodeCoverage" DependsOnTargets="Clean;LoadNuGetPackages;Compile">
<!-- Include all assemblies that end in Tests.dll (This is convention based) -->
<CreateItem Include="**\Bin\Debug\*Tests*.dll" Exclude="**\Bin\$(Configuration)\*Tests*.mm.dll">
<Output TaskParameter="Include" ItemName="TestAssemblies" />
</CreateItem>
<PropertyGroup>
<OpenCoverCommand>"$(OpenCoverPath)\$(OpenCoverExe)" -register:user "-target:"$(MSpecPath)\$(MSpecExe)"" "-targetargs:"@(TestAssemblies, '" "')"" "-filter:$(OpenCoverFilter)" "-output:$(OpenCoverOutputFile)"</OpenCoverCommand>
<ReportGeneratorCommand>"$(ReportGeneratorPath)\$(ReportGeneratorExe)" "-reports:$(OpenCoverOutputFile)" "-targetdir:$(CoverageReport)" "-reporttypes:html;xml"</ReportGeneratorCommand>
</PropertyGroup>
<Message Importance="high" Text="------------------------------------------------"/>
<Message Importance="high" Text="Running code coverage"/>
<Message Importance="high" Text="------------------------------------------------"/>
<Exec Command="$(OpenCoverCommand)" />
<Message Importance="high" Text="------------------------------------------------"/>
<Message Importance="high" Text="Generate report"/>
<Message Importance="high" Text="------------------------------------------------"/>
<Exec Command="$(ReportGeneratorCommand)" />
<!-- Report Generator has no way to name the output file so rename it by copying and deleting the original file -->
<Copy SourceFiles="$(CoverageReport)\Summary.xml" DestinationFiles="$(ReportGeneratorSummary)"></Copy>
<Delete Files="$(CoverageReport)\Summary.xml"></Delete>
</Target> |
The source code to the MSBuild task (community contribution) is available to view (https://github.com/sawilde/opencover/tree/master/main/OpenCover.MSBuild). I don't use msbuild to run opencover but instead use nant/cmd/powershell so I have never had to use the task. Other people use it quite effectively I understand. As for quotes you may need to escape those that are inside other quotes as described in the wiki (https://github.com/sawilde/opencover/wiki/Usage) i.e.
becomes something like
|
- nunit output - opencover output - reportgenerator output - escaped quotes for opencover targetargs, cf.: OpenCover/opencover#140
I ran into this "spaces in directory path" issue when using PowerShell:
But this other approach seemed to work when using a plain Command Prompt:
|
@summea we have a section in the wiki about spaces - https://github.com/OpenCover/opencover/wiki/Usage#notes-on-spaces-in-arguments |
@sawilde Thank you for your reply! I did read that section on the wiki page, but the only combination that seemed to work in my case was the approach described in my last comment. As you can see in my PowerShell attempt from earlier, the quotes were indeed surrounding the entire If you see a reason why this wasn't working from my earlier example, though, please let me know! |
@sawilde I've experienced the same issue as @summea here: #140 (comment) As in, I was unable to get double quotes needed within targetArgs to work properly using powershell by using the technique of escaped double quotes with a backslash. E.g. Using
The result is the following error:
Is there any workaround to get spaces to work properly in powershell or any other recommended workarounds? |
It looks like there is an argument named |
I'm using the following line in my batch file
"%OPENC%" -register:user -target:"%mspecrunner%" -targetargs:"%unittests%" %FILTER% -output:"%RPT_DIR%\UnitTests\opencovertests.xml"
However I wrapped all my things in quotes (") I get the following error.
So my directory gets cut off here D:\Users\A500535\Documents\Projecten\Blue ..................
I can't find why it does this. I get at least an opencovertests.xml in my output so it seems the target or target args are failing.
When running my msspec tests with the same variables everything goes ok.
The text was updated successfully, but these errors were encountered: