Skip to content

Commit

Permalink
Merge pull request #2 from chrisdicarlo/pest-integration
Browse files Browse the repository at this point in the history
Pest Integration
  • Loading branch information
chrisdicarlo authored Nov 23, 2022
2 parents 96ae6b3 + 53e1031 commit 788c60d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 38 deletions.
4 changes: 0 additions & 4 deletions .styleci.yml

This file was deleted.

3 changes: 2 additions & 1 deletion count-failed.xsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- count-failed.xsl -->
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<xsl:value-of select="count(tests/test[@status='3'])" />
<xsl:value-of select="count(tests/test)" />
</xsl:template>
</xsl:stylesheet>
33 changes: 31 additions & 2 deletions failed-tests.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,36 @@
<xsl:apply-templates />
</xsl:template>

<xsl:template match="tests">
<xsl:template match="tests">
<xsl:apply-templates select="./test" />
</xsl:template>

<xsl:template match="test">
<xsl:call-template name="backslashescape">
<xsl:with-param name="str" select="." />
</xsl:call-template>

<xsl:if test="position() != last()">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:template>

<xsl:template name="backslashescape">
<xsl:param name="str" select="."/>
<xsl:choose>
<xsl:when test="contains($str, '\')">
<xsl:value-of select="concat(substring-before($str, '\'), '\\' )"/>
<xsl:call-template name="backslashescape">
<xsl:with-param name="str" select="substring-after($str, '\')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- <xsl:template match="tests">
<xsl:apply-templates select="./test[@status = '3']" />
</xsl:template>
Expand All @@ -15,5 +44,5 @@
<xsl:if test="position() != last()">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:template>
</xsl:template> -->
</xsl:stylesheet>
42 changes: 17 additions & 25 deletions phpunit-failed-runner
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
#!/bin/bash

logfile=./testdox.xml
logfile=./junit.xml

if test -f "$logfile"; then
echo "Logfile found. Searching for failed tests..."
if [ -f "./vendor/bin/pest" ]; then
runner="./vendor/bin/pest"
else
runner="./vendor/bin/phpunit"
fi

# Strip out everything except the failed tests just in
# case they were run using a different tool or script
xmlstarlet tr ./vendor/chrisdicarlo/phpunit-failed-runner/prune.xsl testdox.xml > testdoxTMP.xml
mv testdoxTMP.xml testdox.xml
if test -f "$logfile"; then
echo -e "Logfile found. Searching for previously failing tests... \U23F3"

failed_tests="$(xmlstarlet tr --omit-decl ./vendor/chrisdicarlo/phpunit-failed-runner/failed-tests.xsl testdox.xml)"
count_failed_tests="$(xmlstarlet tr ./vendor/chrisdicarlo/phpunit-failed-runner/prune.xsl junit.xml | xmlstarlet tr --omit-decl ./vendor/chrisdicarlo/phpunit-failed-runner/count-failed.xsl)"

if [ "$failed_tests" = "" ]; then
echo "No failed tests! Great job!"
if [ "$count_failed_tests" = "0" ]; then
echo -e "No failed tests! Great job! \U1F44D \U1F389"
rm "$logfile"
exit 0
else
echo "Found failed tests, filtering..."
./vendor/bin/phpunit --filter "'$failed_tests'"
echo -e "Found $count_failed_tests previously failing tests, filtering... \U1F97A"
filter=$(xmlstarlet tr ./vendor/chrisdicarlo/phpunit-failed-runner/prune.xsl junit.xml | xmlstarlet tr --omit-decl ./vendor/chrisdicarlo/phpunit-failed-runner/failed-tests.xsl); "$runner" --filter "$filter" --log-junit junit.xml
fi
else
echo "Logfile not found. Running the full test suite..."
./vendor/bin/phpunit
fi

# Strip out everything except the failed tests
xmlstarlet tr ./vendor/chrisdicarlo/phpunit-failed-runner/prune.xsl testdox.xml > testdoxTMP.xml
mv testdoxTMP.xml testdox.xml

# If there are no more failed tests, remove the log file
count_failed_tests="$(xmlstarlet tr --omit-decl ./vendor/chrisdicarlo/phpunit-failed-runner/count-failed.xsl testdox.xml)"

if [ "$count_failed_tests" = "0" ]; then
rm ./testdox.xml
echo -e "Logfile not found. Running the full test suite... \U1F91E"
"$runner" --log-junit junit.xml
fi

exit 0
21 changes: 15 additions & 6 deletions prune.xsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output omit-xml-declaration="no" indent="yes"/>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
<xsl:template match="/">
<tests>
<xsl:apply-templates />
</tests>
</xsl:template>

<xsl:template match="test[not(@status='3')]"/>
<xsl:template match="/testsuite">
<tests>
<xsl:apply-templates select="testcase" />
</tests>
</xsl:template>

<xsl:template match="testcase[error|failure]">
<test>
<xsl:value-of select="@class"/>::<xsl:value-of select="@name"/>
</test>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 788c60d

Please sign in to comment.