Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JUnit format #20

Open
calebcartwright opened this issue Mar 23, 2019 · 1 comment
Open

Add support for JUnit format #20

calebcartwright opened this issue Mar 23, 2019 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@calebcartwright
Copy link
Member

calebcartwright commented Mar 23, 2019

ShellCheck does not natively support the JUnit XML format.

Seems the best way to go about adding JUnit support (per ShellCheck docs) is to utilize the checkstyle xml format (i.e. -f checkstyle) and then use an xslt to transform that to JUnit xml format.

@calebcartwright calebcartwright added the enhancement New feature or request label Mar 23, 2019
@calebcartwright calebcartwright added this to the 1.x Release milestone Mar 23, 2019
@calebcartwright calebcartwright added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 28, 2019
@calebcartwright
Copy link
Member Author

Here's some info on how we could go about implementing the solution recommended in the ShellCheck docs:

We would need some additional logic here so that when the user selects JUnit as the format that we will pass checkstyle to shellcheck (otherwise we should just pass whatever format was selected).

Then this line that executes shellcheck can be tweaked to get access to the checkstyle xml output so that we can then perform the transform.

This npm package looks like the best/most lightweight dependency we can incorporate to do the transform.

Here's the XSLT to use:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output encoding="UTF-8" method="xml"></xsl:output>

  <xsl:template match="/">
    <testsuite>
      <xsl:attribute name="tests">
        <xsl:value-of select="count(.//file)" />
      </xsl:attribute>
      <xsl:attribute name="failures">
        <xsl:value-of select="count(.//error)" />
      </xsl:attribute>
      <xsl:for-each select="//checkstyle">
        <xsl:apply-templates />
      </xsl:for-each>
    </testsuite>
  </xsl:template>

  <xsl:template match="file">
    <testcase>
      <xsl:attribute name="classname">
        <xsl:value-of select="@name" />
      </xsl:attribute>
      <xsl:attribute name="name">
        <xsl:value-of select="@name" />
      </xsl:attribute>
      <xsl:apply-templates select="node()" />
    </testcase>
  </xsl:template>

  <xsl:template match="error">
    <failure>
      <xsl:attribute name="type">
        <xsl:value-of select="@source" />
      </xsl:attribute>
      <xsl:text>Line </xsl:text>
      <xsl:value-of select="@line" />
      <xsl:text>: </xsl:text>
      <xsl:value-of select="@message" />
      <xsl:text> See https://www.shellcheck.net/wiki/</xsl:text>
      <xsl:value-of select="substring(@source, '12')" />
    </failure>
  </xsl:template>
</xsl:stylesheet>

Obviously we'd also need to add JUnit in a couple other places, like the OutputFormat Enum, the task.json manifest to expose JUnit as an option, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant