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

end-to-end test for JUnit report #210

Merged
merged 6 commits into from May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/end-to-end/cases/expected/.gitignore
Expand Up @@ -2,3 +2,4 @@
/*.xml
/*.xsl
/*.xq
!/*-junit-norm.xml
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="schematron-01.xspec"><testsuite name="schematron-01" tests="3" failures="0"><testcase name="article should have a title not assert a001" status="passed"/><testcase name="section should have a title assert a002 /article[1]/section[2]" status="passed"/><testcase name="section should have a title assert a002 /article[1]/section[3]" status="passed"/></testsuite></testsuites>
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xquery-tutorial.xspec"><testsuite name="Calling function capitalize-first" tests="1" failures="0"><testcase name="should capitalize the first character of the string" status="passed"/></testsuite></testsuites>
1 change: 1 addition & 0 deletions test/end-to-end/cases/expected/xspec-50-junit-norm.xml
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-50.xspec"><testsuite name="Expecting xs:hexBinary('0123') when $x:result is xs:untypedAtomic('0123')" tests="1" failures="1"><testcase name="must generate a failure report HTML which reads [Result] =&#xA;&#x9;&#x9;&#x9;&#x9;&#34;xs:untypedAtomic('0123')&#34; and [Expected Result] = &#34;xs:hexBinary('0123')&#34;" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite></testsuites>
1 change: 1 addition & 0 deletions test/end-to-end/cases/expected/xspec-55-junit-norm.xml
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-55.xspec"><testsuite name="In a failure report HTML" tests="3" failures="3"><testcase name="[Expected Result] must represent xs:decimal(1) by &#34;1.0&#34; (numeric literal of&#xA;&#x9;&#x9;&#x9;&#x9;decimal)" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase><testcase name="[Expected Result] must represent xs:double(1) by &#34;xs:double('1')&#34; (constructor&#xA;&#x9;&#x9;&#x9;&#x9;of double)" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase><testcase name="[Expected Result] must represent xs:integer(1) by &#34;1&#34; (numeric literal of&#xA;&#x9;&#x9;&#x9;&#x9;integer)" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite></testsuites>
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-focus-1.xspec"><testsuite name="an unfocused correct scenario must be Pending" tests="1" failures="0"><testcase name="it would return Success if it were not Pending" status="skipped"><skipped>testing @focus</skipped></testcase></testsuite><testsuite name="an unfocused incorrect scenario must be Pending" tests="1" failures="0"><testcase name="it would return Failure if it were not Pending" status="skipped"><skipped>testing @focus</skipped></testcase></testsuite><testsuite name="a focused correct scenario" tests="1" failures="0"><testcase name="must execute the test and return Success" status="passed"/></testsuite><testsuite name="a focused incorrect scenario" tests="1" failures="1"><testcase name="must execute the test and return Failure" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite></testsuites>
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-function.xspec"><testsuite name="when calling a function and expecting correctly" tests="2" failures="0"><testcase name="expecting the correct value must return Success" status="passed"/><testcase name="expecting the correct type must return Success" status="passed"/></testsuite><testsuite name="when calling a function and expecting incorrectly" tests="2" failures="2"><testcase name="expecting an incorrect value must return Failure" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase><testcase name="expecting an incorrect type must return Failure" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite></testsuites>
1 change: 1 addition & 0 deletions test/end-to-end/cases/expected/xspec-import-junit-norm.xml
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-import.xspec"><testsuite name="when testing a correct scenario in an importing file" tests="2" failures="0"><testcase name="expecting the correct result must return Success" status="passed"/><testcase name="expecting the correct type must return Success" status="passed"/></testsuite><testsuite name="when testing an incorrect scenario in an importing file" tests="1" failures="1"><testcase name="it must return Failure" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite><testsuite name="a correct scenario in an imported file" tests="1" failures="0"><testcase name="must return Success" status="passed"/></testsuite><testsuite name="an incorrect scenario in an imported file" tests="1" failures="1"><testcase name="must return Failure" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite></testsuites>
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-imported.xspec"><testsuite name="a correct scenario in an imported file" tests="1" failures="0"><testcase name="must return Success" status="passed"/></testsuite><testsuite name="an incorrect scenario in an imported file" tests="1" failures="1"><testcase name="must return Failure" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite></testsuites>
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-pending.xspec"><testsuite name="a correct scenario in x:pending must be Pending" tests="1" failures="0"><testcase name="it would return Success if it were not Pending" status="skipped"><skipped>testing x:pending</skipped></testcase></testsuite><testsuite name="an incorrect scenario in x:pending must be Pending" tests="1" failures="0"><testcase name="it would return Failure if it were not Pending" status="skipped"><skipped>testing x:pending</skipped></testcase></testsuite><testsuite name="a non-pending correct scenario alongside a pending scenario" tests="1" failures="0"><testcase name="must execute the test and return Success" status="passed"/></testsuite><testsuite name="a non-pending incorrect scenario alongside a pending scenario" tests="1" failures="1"><testcase name="must execute the test and return Failure" status="failed"><failure message="expect assertion failed">Expected: </failure></testcase></testsuite><testsuite name="a correct scenario with @pending must be Pending" tests="1" failures="0"><testcase name="it would return Success if it were not Pending" status="skipped"><skipped>testing @pending</skipped></testcase></testsuite><testsuite name="an incorrect scenario with @pending must be Pending" tests="1" failures="0"><testcase name="it would return Failure if it were not Pending" status="skipped"><skipped>testing @pending</skipped></testcase></testsuite></testsuites>
3 changes: 3 additions & 0 deletions test/end-to-end/cases/expected/xspec-rule-junit-norm.xml
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites name="xspec-rule.xspec"><testsuite name="x:context with correct x:expect" tests="1" failures="0"><testcase name="must return Success" status="passed"/></testsuite><testsuite name="x:context with incorrect x:expect" tests="1" failures="1"><testcase name="must return Failure" status="failed"><failure message="expect assertion failed">&lt;x:expect xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:test="http://www.jenitennison.com/xslt/unit-test" xmlns:x="http://www.jenitennison.com/xslt/xspec" xmlns:t="http://www.jenitennison.com/xslt/xspec"&gt;
&lt;erroneous/&gt;
&lt;/x:expect&gt;</failure></testcase></testsuite><testsuite name="x:apply with correct x:expect" tests="1" failures="0"><testcase name="must return Success" status="skipped"><skipped>not implemented yet</skipped></testcase></testsuite><testsuite name="x:apply with incorrect x:expect" tests="1" failures="0"><testcase name="must return Failure" status="skipped"><skipped>not implemented yet</skipped></testcase></testsuite></testsuites>
10 changes: 10 additions & 0 deletions test/end-to-end/cases/expected/xspec-three-dots-junit-norm.xml

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions test/end-to-end/generate-expected.cmd
Expand Up @@ -39,17 +39,22 @@ for %%I in ("%CASES_DIR%\*.xspec") do (
rem
call :check_test_type "%%~nI"
if errorlevel 2 (
"%COMSPEC%" /c ..\..\bin\xspec.bat -s "%%~I"
"%COMSPEC%" /c ..\..\bin\xspec.bat -j -s "%%~I"
) else if errorlevel 1 (
"%COMSPEC%" /c ..\..\bin\xspec.bat -q "%%~I"
"%COMSPEC%" /c ..\..\bin\xspec.bat -j -q "%%~I"
) else (
"%COMSPEC%" /c ..\..\bin\xspec.bat "%%~I"
"%COMSPEC%" /c ..\..\bin\xspec.bat -j "%%~I"
)

rem
rem Normalize the report HTML
rem
java -classpath "%SAXON_CP%" net.sf.saxon.Transform -o:"%TEST_DIR%\%%~nI-result-norm.html" -s:"%TEST_DIR%\%%~nI-result.html" -xsl:processor\normalize.xsl

rem
rem Normalize the JUnit report
rem
java -classpath "%SAXON_CP%" net.sf.saxon.Transform -o:"%TEST_DIR%\%%~nI-junit-norm.xml" -s:"%TEST_DIR%\%%~nI-junit.xml" -xsl:processor\normalize-junit.xsl
)

rem
Expand Down
9 changes: 6 additions & 3 deletions test/end-to-end/generate-expected.sh
Expand Up @@ -20,13 +20,16 @@ do

# Generate the report HTML
if test "${CASE_FILENAME:0:10}" = "schematron"; then
../../bin/xspec.sh -s ${CASE_FILEPATH}
../../bin/xspec.sh -j -s ${CASE_FILEPATH}
elif test "${CASE_FILENAME:0:6}" = "xquery"; then
../../bin/xspec.sh -q ${CASE_FILEPATH}
../../bin/xspec.sh -j -q ${CASE_FILEPATH}
else
../../bin/xspec.sh ${CASE_FILEPATH}
../../bin/xspec.sh -j ${CASE_FILEPATH}
fi

# Normalize the report HTML
java -classpath ${SAXON_CP} net.sf.saxon.Transform -o:${TEST_DIR}/${CASE_BASENAME}-result-norm.html -s:${TEST_DIR}/${CASE_BASENAME}-result.html -xsl:processor/normalize.xsl

# Normalize the JUnit report
java -classpath ${SAXON_CP} net.sf.saxon.Transform -o:${TEST_DIR}/${CASE_BASENAME}-junit-norm.xml -s:${TEST_DIR}/${CASE_BASENAME}-junit.xml -xsl:processor/normalize-junit.xsl
done
149 changes: 0 additions & 149 deletions test/end-to-end/processor/_normalizer.xsl
Expand Up @@ -40,153 +40,4 @@
<xsl:template as="empty-sequence()" match="comment() | processing-instruction()"
mode="local:normalize" />

<!--
Normalizes the title text
Example:
in: <title>Test Report for /path/to/tested.xsl (passed: 2 / pending: 0 / failed: 1 / total: 3)</title>
out: <title>Test Report for tested.xsl (passed: 2 / pending: 0 / failed: 1 / total: 3)</title>
-->
<xsl:template as="text()" match="/html/head/title/text()" mode="local:normalize">
<xsl:analyze-string regex="^(Test Report for) (.+) (\([a-z0-9/: ]+\))$" select=".">
<xsl:matching-substring>
<xsl:value-of
select="
regex-group(1),
util:filename-and-extension(regex-group(2)),
regex-group(3)"
separator=" " />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>

<!--
Replaces the embedded CSS with the link to its source
For brevity. The details of style are not critical anyway.
-->
<xsl:template as="element(link)" match="/html/head/style" mode="local:normalize">
<link rel="stylesheet" type="text/css" xmlns="http://www.w3.org/1999/xhtml">
<xsl:attribute name="href">
<!-- Relative path to XSPEC_HOME from XSPEC_HOME/test/end-to-end/cases/*/*.html -->
<xsl:text>../../../../</xsl:text>

<!-- and down to the CSS source -->
<xsl:text>src/reporter/test-report.css</xsl:text>
</xsl:attribute>
</link>
</xsl:template>

<!--
Normalizes the link to the tested module
Example:
in: <a href="file:/path/to/tested.xsl">/path/to/tested.xsl</a>
out: <a href="tested.xsl">tested.xsl</a>
-->
<xsl:template as="element(a)" match="/html/body/p[position() = (1, 2)]/a" mode="local:normalize">
<xsl:copy>
<xsl:apply-templates mode="#current" select="attribute()" />
<xsl:attribute name="href" select="util:filename-and-extension(@href)" />

<xsl:value-of select="util:filename-and-extension(.)" />
</xsl:copy>
</xsl:template>

<!--
Normalizes datetime
Example:
in: <p>Tested: 23 February 2017 at 11:18</p>
out: <p>Tested: ONCE-UPON-A-TIME</p>
-->
<xsl:template as="text()" match="/html/body/p[3]/text()" mode="local:normalize">
<!-- Use analyze-string() so that the transformation will fail when nothing matches -->
<xsl:analyze-string regex="^(Tested:) .+$" select=".">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1), 'ONCE-UPON-A-TIME'" />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>

<!-- Makes @id predictable -->
<xsl:template as="attribute(id)" match="@id" mode="local:normalize"
name="normalize-id-attribute">
<xsl:attribute name="{local-name()}" namespace="{namespace-uri()}"
select="local:generate-predictable-id(parent::element())" />
</xsl:template>

<!--
Makes the in-page link follow its target element
@id of the target element is normalized by the 'normalize-id-attribute' template. So @href has to follow it.
-->
<xsl:template as="attribute(href)" match="@href[starts-with(., '#')]" mode="local:normalize">
<!-- Substring after '#' -->
<xsl:variable as="xs:string" name="original-id" select="substring(., 2)" />

<xsl:variable as="element()?" name="target-element"
select="local:element-by-id(., $original-id)" />

<xsl:variable as="xs:string" name="predictable-id">
<xsl:choose>
<xsl:when test="$target-element">
<xsl:sequence select="local:generate-predictable-id($target-element)" />
</xsl:when>

<!-- @href's target element may not exist for pending scenarios: xspec/xspec#85 -->
<xsl:when test="parent::a/parent::th/parent::tr/@class eq 'pending'">
<!-- Assume that @href is always unique when the scenario is pending -->
<xsl:if test="count(//@href[. eq current()]) eq 1">
<!-- Use the current element's ID, prefixing 'PENDING_' to it -->
<xsl:sequence
select="concat('PENDING_', local:generate-predictable-id(parent::element()))"
/>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:variable>

<xsl:attribute name="{local-name()}" namespace="{namespace-uri()}"
select="concat('#', $predictable-id)" />
</xsl:template>

<!--
Private utility functions
-->

<!-- Gets the positional index (1~) of element -->
<xsl:function as="xs:integer" name="local:element-index">
<xsl:param as="element()" name="element" />

<xsl:sequence select="count($element/preceding::element()) + 1" />
</xsl:function>

<!--
Returns the element whose original @id is equal to the specified ID
If multiple elements satisfy the condition, returns the first element.
-->
<xsl:function as="element()?" name="local:element-by-id">
<xsl:param as="node()" name="context-node" />
<xsl:param as="xs:string" name="id" />

<xsl:variable as="document-node()" name="doc" select="root($context-node)" />
<xsl:sequence select="$doc/descendant::element()[@id eq $id][1]" />
</xsl:function>

<!--
Generates ID for element
Unlike fn:generate-id(), ID is generated solely from the element's positional index. So the ID value is predictable.
-->
<xsl:function as="xs:string" name="local:generate-predictable-id">
<xsl:param as="element()" name="element" />

<!--
Unfortunately the original @id is not always unique: xspec/xspec#78
So, for calculating the element index, you can't simply use the specified element. You have to determine which element to use.
-->
<xsl:variable as="element()" name="index-element"
select="
if ($element/@id) then
local:element-by-id($element, $element/@id)
else
$element" />

<xsl:sequence select="concat('ELEM-', local:element-index($index-element))" />
</xsl:function>
</xsl:stylesheet>