Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Quotes are not working for target or targetargs #140

Closed
marcofranssen opened this issue Dec 28, 2012 · 13 comments
Closed

Quotes are not working for target or targetargs #140

marcofranssen opened this issue Dec 28, 2012 · 13 comments

Comments

@marcofranssen
Copy link

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.

Missing Assembly: D:\Users\A500535\Documents\Projecten\Blue
Committing...
No results - no assemblies that matched the supplied filter were instrumented
this could be due to missing PDBs for the assemblies that match the filter
please review the output file and refer to the Usage guide (Usage.rtf)`

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.

@sawilde
Copy link
Member

sawilde commented Dec 29, 2012

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.

@marcofranssen
Copy link
Author

That also doesn't work.

set escapedmspecrunner="\"%mspecrunner%\""
set escapedunittests="\"%unittests%\""
"%OPENC%" -register:user -target:%escapedmspecrunner% -targetargs:%escapedunittests% %FILTER% -output:"%RPT_DIR%\UnitTests\opencovertests.xml" 

I get the following error...

Target '"D:\Users\A500535\Documents\Projecten\Blue Lagoon Environment\src\sources_1.0.5\BlueLagoon.Connector\packages\Machine.Specifications.0.5.10\tools\mspec-clr4.exe"' cannot be found - have you specified your arguments correctly?

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.

@sawilde
Copy link
Member

sawilde commented Dec 31, 2012

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

"-target:%mspecrunner%"

or

"-target:\"%mspecrunner%\""

@sawilde
Copy link
Member

sawilde commented Jan 2, 2013

I have found several ways to resolve this using a path to my nunit-console runner with a space in the path

set nunitpath=..\..\..\tools\NUnit 2.6.0.12051\bin\nunit-console-x86.exe
OpenCover.Console.exe -register:user "-target:%nunitpath%" -targetargs:"OpenCover.Test.dll /noshadow" -filter:"+[Open*]* -[OpenCover.T*]*" -output:opencovertests.xml

expands and runs properly

Alternatively

set nunitpath=..\..\..\tools\NUnit 2.6.0.12051\bin\nunit-console-x86.exe
set nunitpath_quotes="%nunitpath%"
OpenCover.Console.exe -register:user -target:%nunitpath_quotes% -targetargs:"OpenCover.Test.dll /noshadow" -filter:"+[Open*]* -[OpenCover.T*]*" -output:opencovertests.xml

expands and runs properly

I think you just need to work on the batch script - perhaps see what the environment variable are expanding to

@sawilde sawilde closed this as completed Jan 2, 2013
@marcofranssen
Copy link
Author

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.

@sawilde
Copy link
Member

sawilde commented Jan 3, 2013

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.

@marcofranssen
Copy link
Author

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>&quot;$(OpenCoverPath)\$(OpenCoverExe)&quot; -register:user &quot;-target:&quot;$(MSpecPath)\$(MSpecExe)&quot;&quot; &quot;-targetargs:&quot;@(TestAssemblies, '&quot; &quot;')&quot;&quot; &quot;-filter:$(OpenCoverFilter)&quot; &quot;-output:$(OpenCoverOutputFile)&quot;</OpenCoverCommand>
      <ReportGeneratorCommand>&quot;$(ReportGeneratorPath)\$(ReportGeneratorExe)&quot; &quot;-reports:$(OpenCoverOutputFile)&quot; &quot;-targetdir:$(CoverageReport)&quot; &quot;-reporttypes:html;xml&quot;</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>

@sawilde
Copy link
Member

sawilde commented Apr 22, 2013

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.

  &quot;-target:&quot;$(MSpecPath)\$(MSpecExe)&quot;&quot;

becomes something like

  &quot;-target:\&quot;$(MSpecPath)\$(MSpecExe)\&quot;&quot;

mkoertgen added a commit to awesome-inc/OneClickBuild that referenced this issue Aug 30, 2015
- nunit output
- opencover output
- reportgenerator output
- escaped quotes for opencover targetargs, cf.: OpenCover/opencover#140
@summea
Copy link

summea commented Mar 24, 2017

I ran into this "spaces in directory path" issue when using PowerShell:

PS C:\> C:\Users\username\OpenCover\OpenCover.Console.exe "-target:C:\Users\username\NUnit.Console-3.6.1\nunit3-console.exe" "-targetargs:\"C:\Users\username\Documents\Visual Studio 2015\Projects\RabbitMQ\RabbitMQTests\bin\Debug\RabbitMQTests.dll\"" -output:coverage.xml -register:user

Incorrect Arguments: The argument 'C:\Users\username\Documents\Visual' is not recognised

But this other approach seemed to work when using a plain Command Prompt:

set nunitpath=C:\Users\username\Documents\Visual Studio 2015\Projects\RabbitMQ\RabbitMQTests\bin\Debug

C:\Users\username\OpenCover\OpenCover.Console.exe "-target:C:\Users\username\NUnit.Console-3.6.1\nunit3-console.exe" "-targetargs:\"%nunitpath%\"\RabbitMQTests.dll" -output:coverage.xml -register:user

@sawilde
Copy link
Member

sawilde commented Mar 24, 2017

@summea we have a section in the wiki about spaces - https://github.com/OpenCover/opencover/wiki/Usage#notes-on-spaces-in-arguments

@summea
Copy link

summea commented Mar 27, 2017

@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 "-targetargs: ..." option, as the wiki page seems to suggest, as well as having inner quotes around the path to the .dll.

If you see a reason why this wasn't working from my earlier example, though, please let me know!

@smithmw
Copy link

smithmw commented Jan 6, 2021

@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 \" where a " is needed.
E.g.:

"-targetArgs:\"C:\My Path With Spaces\Test.dll\" /logger:trx"

The result is the following error:

Incorrect Arguments: The argument Source is not recognised

Is there any workaround to get spaces to work properly in powershell or any other recommended workarounds?

@sawilde
Copy link
Member

sawilde commented Jan 6, 2021

It looks like there is an argument named -Source and that is not an opencover argument
I would need to see the whole command to even start to help

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants