DevLabs > DevLabs Forums > Pex > How to only include a single type in stub generation?
Ask a questionAsk a question
 

AnswerHow to only include a single type in stub generation?

  • Wednesday, September 30, 2009 9:38 PMxor88 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    How can i include a single type in my Assemblies1.stubx? The filters seem a bit strange to me. I couldn't get it to work.

    <Stubs xmlns="http://schemas.microsoft.com/stubs/2008/">
    
      <Assembly Name="CK" />
    
      <StubGeneration>
    
        <TypeFilter ExcludedNamespace="C*"/>
    
        <TypeFilter SkipClasses="true" SkipObsolete="true" TypeName="CK.Models.IWebEnvironment"/>
    
      </StubGeneration>
    
      <MoleGeneration>
    
        <TypeFilter ExcludedNamespace="C*"/>
    
        <TypeFilter ExcludedNamespace="S*"/>
    
      </MoleGeneration>
    
    </Stubs>
    
    
    
    

    I want to do this: .Where(t => t.Name == "IWebEnvironment")

    Suggestion: Place a small descirption in the default stubx file.

Answers

All Replies

  • Wednesday, September 30, 2009 9:45 PMxor88 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Got it:
    <Stubs xmlns="http://schemas.microsoft.com/stubs/2008/">
      <Assembly Name="CK" />
      <StubGeneration>
        <TypeFilter TypeName="IWebEnvironment"/>
      </StubGeneration>
      <MoleGeneration Disable="true">
      </MoleGeneration>
    </Stubs>
    
    

    Was a bit frustrating though.
  • Thursday, October 01, 2009 4:17 AMPeliMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The reason the first approach did not work is that there is a bug when we generate the filter. Instance of a disjunction, we group the 'TypeFilter' as a conjunction.... so no types are generated. This issue will be fixed in the next release.

    Are you suggesting a boiler plate filter (commented) in the initial stubx file?
    Jonathan "Peli" de Halleux - Give us your input about Pex!
  • Thursday, October 01, 2009 9:01 AMxor88 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    That would be nice. I was thinking of a descriptive text in xml comments at the top of the file. How are multiple filter entries applied anyway? Is it like NTFS ACLs top to bottom first match or top to bottom last match? One of those would make most sense to me as one could select very fine-grained. I would also recommend naming TypeName => IncludetypeName in order to be symmtrical to excludetypename.
  • Friday, October 02, 2009 3:14 AMPeliMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It is top to bottom first match. Do you get the intellisense from the XSD schema?
    Jonathan "Peli" de Halleux - Give us your input about Pex!
  • Friday, October 02, 2009 8:38 AMxor88 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Yes intellisense for schema is there. Just no documentation about the sematics. btw, top to bottom does not work:

    <?xml version="1.0" encoding="utf-8" ?>
    <!--
    This file is used by Microsoft.Stubs to generate stubs for all the interfaces in the assembly under test.
    -->
    <Stubs xmlns="http://schemas.microsoft.com/stubs/2008/">
      <Assembly Name="CK" />
      <StubGeneration>
        <TypeFilter TypeName="IWebEnvironment"/>
        <TypeFilter TypeName="UserServiceBase"/>
      </StubGeneration>
      <MoleGeneration Disable="true">
      </MoleGeneration>
    </Stubs>
    
    
    This produces an empty .designer.cs file. I now  have split the stubx file into two files, one for each type. This works. How does the filter behave if none of the TypeFilter-Elements match? Is the type included or excluded?

    Suggesiton: Allow an "empty filter" ("*") for exclude or include to customize if everything is matched or not-matched by default.
  • Friday, October 02, 2009 2:18 PMPeliMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    As mentionned above, to-bottom does not work because of a bug in the way we combine the filters (conjunction vs disjunction). I'll beef up the schema intellisense.
    Jonathan "Peli" de Halleux - Give us your input about Pex!
  • Thursday, October 29, 2009 4:04 AMPeliMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This issue is fixed in 0.18. Please reopen if you find another issue.
    Jonathan "Peli" de Halleux - Give us your input about Pex!