-
-
Notifications
You must be signed in to change notification settings - Fork 186
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 XUnit files #288
Changes from all commits
021246f
207304c
11b5ec7
e3b8d7f
95612ab
989d46a
64f1d85
f14fc8b
d09fcf7
1ae95bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- based on https://gist.github.com/cdroulers/e23eeb31d6c1c2cade6f680e321aed8d --> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<xsl:output method="xml" indent="yes"/> | ||
<xsl:template match="/"> | ||
<testsuites> | ||
<xsl:for-each select="//assembly"> | ||
<testsuite> | ||
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> | ||
<xsl:attribute name="tests"><xsl:value-of select="@total"/></xsl:attribute> | ||
<xsl:attribute name="failures"><xsl:value-of select="@failed"/></xsl:attribute> | ||
<xsl:if test="@errors"> | ||
<xsl:attribute name="errors"><xsl:value-of select="@errors"/></xsl:attribute> | ||
</xsl:if> | ||
<xsl:attribute name="time"><xsl:value-of select="@time"/></xsl:attribute> | ||
<xsl:attribute name="skipped"><xsl:value-of select="@skipped"/></xsl:attribute> | ||
<xsl:attribute name="timestamp"><xsl:value-of select="@run-date"/>T<xsl:value-of select="@run-time"/></xsl:attribute> | ||
|
||
<xsl:for-each select="collection | class"> | ||
<testsuite> | ||
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> | ||
<xsl:attribute name="tests"><xsl:value-of select="@total"/></xsl:attribute> | ||
<xsl:attribute name="failures"><xsl:value-of select="@failed"/></xsl:attribute> | ||
<xsl:if test="@errors"> | ||
<xsl:attribute name="errors"><xsl:value-of select="@errors"/></xsl:attribute> | ||
</xsl:if> | ||
<xsl:attribute name="time"><xsl:value-of select="@time"/></xsl:attribute> | ||
<xsl:attribute name="skipped"><xsl:value-of select="@skipped"/></xsl:attribute> | ||
|
||
<xsl:for-each select="test"> | ||
<testcase> | ||
<xsl:attribute name="name"><xsl:value-of select="@method"/></xsl:attribute> | ||
<xsl:attribute name="time"><xsl:value-of select="@time"/></xsl:attribute> | ||
<xsl:attribute name="classname"><xsl:value-of select="@type"/></xsl:attribute> | ||
<xsl:if test="reason"> | ||
<skipped> | ||
<xsl:attribute name="message"><xsl:value-of select="reason/text()"/></xsl:attribute> | ||
</skipped> | ||
</xsl:if> | ||
<xsl:apply-templates select="failure"/> | ||
</testcase> | ||
</xsl:for-each> | ||
|
||
</testsuite> | ||
</xsl:for-each> | ||
|
||
</testsuite> | ||
</xsl:for-each> | ||
</testsuites> | ||
</xsl:template> | ||
|
||
<xsl:template match="failure"> | ||
<failure> | ||
<xsl:if test="@exception-type"> | ||
<xsl:attribute name="type"><xsl:value-of select="@exception-type"/></xsl:attribute> | ||
</xsl:if> | ||
<xsl:attribute name="message"><xsl:value-of select="message"/></xsl:attribute> | ||
<xsl:value-of select="message"/> | ||
<xsl:value-of select="stack-trace"/> | ||
</failure> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import pathlib | ||
from typing import Iterable, Callable | ||
|
||
from lxml import etree | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. opt.semgrep.python.lang.security.use-defused-xml.use-defused-xml: Found use of the native Python XML libraries, which is vulnerable to XML external entity (XXE) (at-me in a reply with Was this a good recommendation? |
||
|
||
from publish.junit import JUnitTreeOrException, ParsedJUnitFile | ||
|
||
with (pathlib.Path(__file__).parent / 'xslt' / 'xunit-to-junit.xslt').open('r', encoding='utf-8') as r: | ||
transform_xunit_to_junit = etree.XSLT(etree.parse(r)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blacklist: Using lxml.etree.parse to parse untrusted XML data is known to be vulnerable to XML attacks. Replace lxml.etree.parse with its defusedxml equivalent function. (at-me in a reply with Was this a good recommendation? |
||
|
||
|
||
def parse_xunit_files(files: Iterable[str], | ||
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile] = lambda x: x) -> Iterable[ParsedJUnitFile]: | ||
"""Parses xunit files.""" | ||
def parse(path: str) -> JUnitTreeOrException: | ||
"""Parses an xunit file and returns either a JUnitTree or an Exception.""" | ||
if not os.path.exists(path): | ||
return FileNotFoundError(f'File does not exist.') | ||
if os.stat(path).st_size == 0: | ||
return Exception(f'File is empty.') | ||
|
||
try: | ||
trx = etree.parse(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blacklist: Using lxml.etree.parse to parse untrusted XML data is known to be vulnerable to XML attacks. Replace lxml.etree.parse with its defusedxml equivalent function. (at-me in a reply with Was this a good recommendation? |
||
return transform_xunit_to_junit(trx) | ||
except BaseException as e: | ||
return e | ||
|
||
return [progress((result_file, parse(result_file))) for result_file in files] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
base=$(dirname "$0") | ||
|
||
python $base/../test_junit.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SC2086: Double quote to prevent globbing and word splitting. (at-me in a reply with Was this a good recommendation? |
||
python $base/../test_xunit.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SC2086: Double quote to prevent globbing and word splitting. (at-me in a reply with Was this a good recommendation? |
||
python $base/../test_trx.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SC2086: Double quote to prevent globbing and word splitting. (at-me in a reply with Was this a good recommendation? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[mstest/fixie.xml](https://raw.githubusercontent.com/fixie/fixie/42b43dc6cc57476958eea8b507aa9d0d72cedae6/src/Fixie.Tests/Reports/XUnitXmlReport.xml) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<testsuites> | ||
<testsuite name="[assemblyLocation]" tests="7" failures="3" time="1.234" skipped="1" timestamp="YYYY-MM-DDTHH:MM:SS"> | ||
<testsuite name="[genericTestClass]" tests="3" failures="1" time="1.234" skipped="0"> | ||
<testcase name="ShouldBeString" time="1.234" classname="[genericTestClass]"/> | ||
<testcase name="ShouldBeString" time="1.234" classname="[genericTestClass]"/> | ||
<testcase name="ShouldBeString" time="1.234" classname="[genericTestClass]"> | ||
<failure type="Fixie.Tests.Assertions.AssertException" message="Expected: System.String Actual: System.Int32">Expected: System.String | ||
Actual: System.Int32 at [genericTestClassForStackTrace].ShouldBeString[T](T genericArgument) in [fileLocation]:line #</failure> | ||
</testcase> | ||
</testsuite> | ||
<testsuite name="[testClass]" tests="4" failures="2" time="1.234" skipped="1"> | ||
<testcase name="Fail" time="1.234" classname="[testClass]"> | ||
<failure type="Fixie.Tests.FailureException" message="'Fail' failed!">'Fail' failed! at [testClassForStackTrace].Fail() in [fileLocation]:line #</failure> | ||
</testcase> | ||
<testcase name="FailByAssertion" time="1.234" classname="[testClass]"> | ||
<failure type="Fixie.Tests.Assertions.AssertException" message="Expected: 2 Actual: 1">Expected: 2 | ||
Actual: 1 at [testClassForStackTrace].FailByAssertion() in [fileLocation]:line #</failure> | ||
</testcase> | ||
<testcase name="Pass" time="1.234" classname="[testClass]"/> | ||
<testcase name="Skip" time="1.234" classname="[testClass]"> | ||
<skipped message="⚠ Skipped with attribute."/> | ||
</testcase> | ||
</testsuite> | ||
</testsuite> | ||
</testsuites> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blacklist: Using etree to parse untrusted XML data is known to be vulnerable to XML attacks. Replace etree with the equivalent defusedxml package.
(at-me in a reply with
help
orignore
)Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]