Microsoft Developer Network > Página principal de foros > Pex > StyleCop (or CodeCop) compilance of Code generated by PEX
Formular una preguntaFormular una pregunta
 

RespondidaStyleCop (or CodeCop) compilance of Code generated by PEX

  • lunes, 17 de noviembre de 2008 18:13TatworthMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.
    • EditadoTatworthMVPlunes, 17 de noviembre de 2008 18:15
    •  

Respuestas

  • lunes, 17 de noviembre de 2008 18:26PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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
  • lunes, 17 de noviembre de 2008 21:55PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
     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
  • martes, 18 de noviembre de 2008 6:53PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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

Todas las respuestas

  • lunes, 17 de noviembre de 2008 18:26PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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
  • lunes, 17 de noviembre de 2008 18:28PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • lunes, 17 de noviembre de 2008 21:55PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
     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
  • martes, 18 de noviembre de 2008 6:53PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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
  • miércoles, 19 de noviembre de 2008 9:35TatworthMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.
  • miércoles, 19 de noviembre de 2008 15:27PeliMSFT, PropietarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • miércoles, 19 de noviembre de 2008 16:11TatworthMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
     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.