MSDN > 論壇首頁 > Pex > StyleCop (or CodeCop) compilance of Code generated by PEX
發問發問
 

已答覆StyleCop (or CodeCop) compilance of Code generated by PEX

  • Monday, 17 November, 2008 18:13TatworthMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I found the code generated by Pex had a large number of warnings according to StyleCop (or CodeCop as we sometimes call it). Can the autogenerated code be generated in a more StyleCop friendly manner? The version I am using is Microsoft.StyleCop 4.3

    Possibly I used the wrong prompt, but it would be useful if there was a dialog that allowed selection of classes within a project.  I already have a large number of classes already thoroughly unit tested and just wanted to examine the remaining classes.

解答

  • Monday, 17 November, 2008 18:26PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Tatworth said:
    Possibly I used the wrong prompt, but it would be useful if there was a dialog that allowed selection of classes within a project.  I already have a large number of classes already thoroughly unit tested and just wanted to examine the remaining classes.

    If you right-click inside the class you want to test, and select Pex -> Create Parameterized Unit Test Stubs, Pex will set up the filters to generate stubs for this class only. The filters use a simply syntax documented here:

    http://research.microsoft.com/pex/wiki/Command%20Line%20Filters%20Syntax.html

    Jonathan de Halleux
  • Monday, 17 November, 2008 21:55PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
     It seems that most of the issues are fixable. StyleCop already ignores .g.cs files out of the box. To reduace noise on other files, add this comment at the top of the file:

    // <auto-generated/>
    Jonathan de Halleux
  • Tuesday, 18 November, 2008 6:53PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    StyleCop has requirements that are incompatible with the Visual Studio object model*, so we will do a best effort but there's no guarantee it will will 100% clean.

    *'using' clauses in a namespace scope are not supported by the Visual Studio object model, therefore we cannot correctly update the namespaces.

    Jonathan de Halleux

所有回覆

  • Monday, 17 November, 2008 18:26PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Tatworth said:
    Possibly I used the wrong prompt, but it would be useful if there was a dialog that allowed selection of classes within a project.  I already have a large number of classes already thoroughly unit tested and just wanted to examine the remaining classes.

    If you right-click inside the class you want to test, and select Pex -> Create Parameterized Unit Test Stubs, Pex will set up the filters to generate stubs for this class only. The filters use a simply syntax documented here:

    http://research.microsoft.com/pex/wiki/Command%20Line%20Filters%20Syntax.html

    Jonathan de Halleux
  • Monday, 17 November, 2008 18:28PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Tatworth said:

    I found the code generated by Pex had a large number of warnings according to StyleCop (or CodeCop as we sometimes call it). Can the autogenerated code be generated in a more StyleCop friendly manner? The version I am using is Microsoft.StyleCop 4.


    The quality of our generated code is very important to us, so we will consider this issue in the future. However, generating correct and pretty code IS an amazingly complicated task so we cannot guarantee we ever get fully StyleCop compliant (at least the generated unit tests).


    Jonathan de Halleux
  • Monday, 17 November, 2008 21:55PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
     It seems that most of the issues are fixable. StyleCop already ignores .g.cs files out of the box. To reduace noise on other files, add this comment at the top of the file:

    // <auto-generated/>
    Jonathan de Halleux
  • Tuesday, 18 November, 2008 6:53PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    StyleCop has requirements that are incompatible with the Visual Studio object model*, so we will do a best effort but there's no guarantee it will will 100% clean.

    *'using' clauses in a namespace scope are not supported by the Visual Studio object model, therefore we cannot correctly update the namespaces.

    Jonathan de Halleux
  • Wednesday, 19 November, 2008 9:35TatworthMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    It would be beneficial if the code output by PEX is also FXCOP compliant or at least we have some guidance on the errors that are safe to ignore.
  • Wednesday, 19 November, 2008 15:27PeliMSFT, 擁有者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I'm seeing 3 violations: CLSCompliant (fixable), CA2210 (not fixable), CA1822 (by design).

    CA2210 (strongly typed assembly): you will have to sign the generated assembly yourself,
    CA1822: test frameworks require instance methods but we never access the 'this'.  Emitting a SuppressMessage on each generated test seems like an overkill.

    Are you seeing other FxCop violations?
    Jonathan de Halleux
  • Wednesday, 19 November, 2008 16:11TatworthMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
     I will have to recheck when I next generate a PEX test class. 

    We are in the throws of implementing FXCOP / StyleCop with an almost zero-tolerance policy on all new code, hence the need for your guidance on which errors are legitimate to suppress.

    Anything you can do to eliminate problems in the next release would be appreciated.