Microsoft Developer Network > 포럼 홈 > Pex > StyleCop (or CodeCop) compilance of Code generated by PEX
질문하기질문하기
 

답변됨StyleCop (or CodeCop) compilance of Code generated by PEX

  • 2008년 11월 17일 월요일 오후 6: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.
    • 편집됨TatworthMVP2008년 11월 17일 월요일 오후 6:15
    •  

답변

  • 2008년 11월 17일 월요일 오후 6: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
  • 2008년 11월 17일 월요일 오후 9: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
  • 2008년 11월 18일 화요일 오전 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

모든 응답

  • 2008년 11월 17일 월요일 오후 6: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
  • 2008년 11월 17일 월요일 오후 6: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
  • 2008년 11월 17일 월요일 오후 9: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
  • 2008년 11월 18일 화요일 오전 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
  • 2008년 11월 19일 수요일 오전 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.
  • 2008년 11월 19일 수요일 오후 3: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
  • 2008년 11월 19일 수요일 오후 4: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.