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

Problem with Filter usage #20

Closed
sawilde opened this issue Jul 11, 2011 · 12 comments
Closed

Problem with Filter usage #20

sawilde opened this issue Jul 11, 2011 · 12 comments
Assignees

Comments

@sawilde
Copy link
Member

sawilde commented Jul 11, 2011

Hi,
class filterers on assemblies does not work for OpenCover.
eg : OpenCover.Console.exe -target:$(NUnit-ToolPath)\nunit-console.exe -targetargs:"/noshadow \path.dll

-filter:"+[Test.Weather]* -[*.WeatherEffects]" -output:Test.xml

Now when generating report i need to remove all WeatherEffects class coverage.But the filter does not work.Could you suggest if syntax is ok.

NOTE: Issue originally raised by https://github.com/guptkan as a comment to issue #16

@sawilde
Copy link
Member Author

sawilde commented Jul 11, 2011

not knowing the assembly and class names this is hard to guess but the syntax is

[assembly_name_filter]namespace_class_filter

so for you I would guess it would be

-filter:"+[Test.Weather]* -[Test.Weather]*.WeatherEffects"

exclusion filters take precedence over inclusion filters

@ghost ghost assigned sawilde Jul 11, 2011
@guptkan
Copy link

guptkan commented Jul 11, 2011

Hi,
I tried this syntax.It seems the filters do not work .

Eg. when we set the filter to only include only certain classes in the assembly
e.g -filter:"+[Weather.tools.WeatherClient]*.App]".The code coverage is shown for all the classes in the assembly.
Where as it should only include the App class for the assembly.

Similarly when i try to remove certain classes with -[]*.Tests this does not remove those Tests classes.

Is there a way to do this,please suggest .Its important as we are in tight deadlines.

@sawilde
Copy link
Member Author

sawilde commented Jul 11, 2011

Hi

the problem is I don't know the name of you assemblies or namespaces/classes to help you

First are you using the latest version?

Second could you run the coverage with the filter +[] only i.e. -filter:+[], and post the output on http://www.pastie.org/ that way I can see the report and then let you know what filters I would use.

Also are your tests in a different assembly of the same assembly as the code being tested?

@guptkan
Copy link

guptkan commented Jul 12, 2011

Hi,
I have pased the code.
I am not able to send the real code report due to data protection.But i have given an example as to what i am trying to do.
The tests in our case is in our case is in separate dll.

@sawilde
Copy link
Member Author

sawilde commented Jul 12, 2011

Okay if we use the output from opencover coverage as an example the command line

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

produced the following report (cut down for clarity) but you have access to the source and can build and run the dogfood test

<?xml version="1.0" encoding="utf-8"?>
<CoverageSession xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Modules>
    <Module>
      <FullName>P:\projects\opencover.git\working\main\bin\Debug\OpenCover.Framework.dll</FullName>
      <ModuleName>OpenCover.Framework</ModuleName>
      <Files>
        <File uid="1" fullPath="P:\projects\opencover.git\working\main\OpenCover.Framework\Persistance\BasePersistance.cs" />
        <File uid="5" fullPath="P:\projects\opencover.git\working\main\OpenCover.Framework\Persistance\FilePersistance.cs" />
        ...
        <File uid="29" fullPath="P:\projects\opencover.git\working\main\OpenCover.Framework\Communication\MarshalWapper.cs" />
      </Files>
      <Classes>
        <Class>
          <FullName>&lt;Module&gt;</FullName>
          <Methods />
        </Class>
        <Class>
          <FullName>OpenCover.Framework.Persistance.BasePersistance</FullName>
          <Methods>
            <Method cyclomaticComplexity="1">
              <MetadataToken>100663313</MetadataToken>
              <Name>System.Void OpenCover.Framework.Persistance.BasePersistance::.ctor()</Name>
              <FileRef uid="1" />
              <SequencePoints>
                <SequencePoint ordinal="0" offset="0" sl="10" sc="9" el="10" ec="33" vc="6" uspid="1" />
                <SequencePoint ordinal="1" offset="7" sl="11" sc="9" el="11" ec="10" vc="6" uspid="2" />
                <SequencePoint ordinal="2" offset="8" sl="12" sc="13" el="12" ec="53" vc="6" uspid="3" />
                <SequencePoint ordinal="3" offset="20" sl="13" sc="9" el="13" ec="10" vc="6" uspid="4" />
              </SequencePoints>
            </Method>
          <Methods>
        </Class>
        ...
      </Classes>
    </Module>
  </Modules>
  <VisitPoints />
</CoverageSession>

Then the assembly_name_filter is matched against //Module/ModuleName and the namespace_class_filter matches against
//Class/FullName

I hope that helps explain the filter

PS if data issues are a problem then you can send messages direct via github, though I doubt there is anything of sensitive nature in the reports as all we have are namespace and class names and sequence points (no code or data)

@guptkan
Copy link

guptkan commented Jul 12, 2011

Ok .I have checked i cannot send the report.

But its quite a simple app i tried.I followed you filters example and tried.But didnt work

Example:
The exe name is WeatherApp.exe

Hello.cs

namespace SampleApplication
{
    class Hello
    {
        public void HelloHello()
        {
            Console.WriteLine("Hello");
        }
    }
}

Another class Calculate.cs same Namespace

namespace SampleApplication.Logic
{
    class Calculate
    {
        public void MultiplyResults()
        {
            Console.WriteLine("Weather is good");
        }

        public void GetResults()
        {
            Console.WriteLine("Weather is good");
        }
    }
}

Now to generate the coverage report ,i do not want Hello.cs to be included

So here is the filters cmd i use
lib\OpenCover\OpenCover.Console.exe -register:user -target:lib\NUnit\nunit-console.exe -targetargs:"SampleApplication\bin\AnyCPU\WeatherApp.exe /noshadow" -filter:"+[WeatherApp*]* -[SampleApplication.Hello*]*" -output:out\opencover.xml
ReportGenerator\ReportGenerator_1.1.0.0\bin\ReportGenerator.exe out\opencover.xml out\Report

Report Generated
Generated on: 12.07.2011-12.07.2011
Parser: OpenCoverParser
Assemblies: 1
Files: 5
Coverage: 66.7%
Covered lines: 30
Coverable lines: 45
Total lines: 136

Assemblies
WeatherApp.exe 66.7%

SampleApplication.Hello 0%

SampleApplication.Logic.Calculate 0%

SampleApplication.Program 0%

SampleApplication.Test1 87.5%

SampleApplicationTest.UnitTest1 100%

Here it shows coverage of SampleApplication.Hello 0%
which should not be there in the report

NOTE: Updated by sawilde to improve markup

@sawilde
Copy link
Member Author

sawilde commented Jul 12, 2011

I am assuming you are using the latest version of OpenCover as that has fixes for filters. Based on your details presented above the filter I would use would look something like this

As they are in different namespaces

-filter:"+[WeatherApp]SampleApplication.Logic.*"

if your sample was wrong and Hello and Calculate were in the same namespace

-filter:"+[WeatherApp]SampleApplication.Logic.Calculate"

or

-filter:"+[WeatherApp]SampleApplication.Logic.* -[WeatherApp]SampleApplication.Logic.Hello"

NOTE: Please note that GitHub uses markup and so it better to read these posts on the web site were it has been rendered

@guptkan
Copy link

guptkan commented Jul 13, 2011

Hi,
Tried to reinsatll opencover.1.0.508.msi .Seems the insallation packege throws an error when you run the msi.

Error: Anetwork error occured while attempting to read from the file C:\Users\Desktop\opencover 1.0.508.msi

Anyway i tried the filters with .506 version.Results were the same .But as you mentioned filters are fixed in .508
.Let me know if somethings wrong with the package or my pc has problem.

lib\OpenCover\OpenCover.Console.exe -register:user -target:lib\NUnit\nunit-console.exe -targetargs:"SampleApplication\bin\AnyCPU\WeatherApp.exe /noshadow" -filter:"+[WeatherApp]SampleApplication.* -[WeatherApp]SampleApplication.Logic.Calculate" -output:out\opencover.xml

@guptkan
Copy link

guptkan commented Jul 13, 2011

Ok..I did uninstall of previous version and then installed the new version 1.0.508.

But i get the same results .All classes are in same namespace.(SampleApplication.Hello and SampleApplication.Logic.Calculate)

lib\OpenCover\OpenCover.Console.exe -register:user -target:lib\NUnit\nunit-console.exe -targetargs:"SampleApplication\bin\AnyCPU\WeatherApp.exe /noshadow" -filter:"+[WeatherApp]SampleApplication.* -[WeatherApp]SampleApplication.Hello" -output:out\opencover.xml

Assemblies
WeatherApp.exe 46.7%

SampleApplication.Hello 0%

SampleApplication.Logic.Calculate 0%

SampleApplication.Program 0%

SampleApplication.Test1 87.5%

SampleApplicationTest.UnitTest1 0%

@sawilde
Copy link
Member Author

sawilde commented Jul 13, 2011

I see the problem now, sorry for the confusion. The issue is that filtered classes are still in the report when they should not be - though they are being left uninstrumented and as such the report looks worse than expected. I'll sort it as soon as

@sawilde
Copy link
Member Author

sawilde commented Jul 13, 2011

Uploaded a new version - please let me know if it solves your issue

@sawilde
Copy link
Member Author

sawilde commented Jul 14, 2011

It would appear you think the new version fixes this issue see #10

@sawilde sawilde closed this as completed Jul 14, 2011
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

2 participants