From 070cde7bb7ed01dd6e2c76aed900e0a70ef14c07 Mon Sep 17 00:00:00 2001 From: Sandro Cirulli Date: Sun, 14 Aug 2016 16:03:38 +0100 Subject: [PATCH 1/3] # This is a combination of 4 commits. # The first commit's message is: #2 initial commit # This is the 2nd commit message: add saxon9he # This is the 3rd commit message: remove cat and saxon # This is the 4th commit message: add tests --- bin/xspec.sh | 13 +++++- src/reporter/junit-report.xsl | 88 +++++++++++++++++++++++++++++++++++ test/xspec-junit.xspec | 87 ++++++++++++++++++++++++++++++++++ test/xspec.bats | 55 ++++++++++++++++++++++ 4 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 src/reporter/junit-report.xsl create mode 100644 test/xspec-junit.xspec create mode 100644 test/xspec.bats diff --git a/bin/xspec.sh b/bin/xspec.sh index 541f3d52a..f03cb974c 100755 --- a/bin/xspec.sh +++ b/bin/xspec.sh @@ -36,12 +36,13 @@ usage() { echo "$1" echo; fi - echo "Usage: xspec [-t|-q|-c|-h] filename [coverage]" + echo "Usage: xspec [-t|-q|-c|-j|-h] filename [coverage]" echo echo " filename the XSpec document" echo " -t test an XSLT stylesheet (the default)" echo " -q test an XQuery module (mutually exclusive with -t)" echo " -c output test coverage report" + echo " -j output JUnit report" echo " -h display this help message" echo " coverage deprecated, use -c instead" } @@ -167,6 +168,9 @@ while echo "$1" | grep -- ^- >/dev/null 2>&1; do # Coverage -c) COVERAGE=1;; + # JUnit report + -j) + JUNIT=1;; # Help! -h) usage @@ -219,6 +223,7 @@ COVERAGE_XML=$TEST_DIR/$TARGET_FILE_NAME-coverage.xml COVERAGE_HTML=$TEST_DIR/$TARGET_FILE_NAME-coverage.html RESULT=$TEST_DIR/$TARGET_FILE_NAME-result.xml HTML=$TEST_DIR/$TARGET_FILE_NAME-result.html +JUNIT_RESULT=$TEST_DIR/$TARGET_FILE_NAME-junit.xml COVERAGE_CLASS=com.jenitennison.xslt.tests.XSLTCoverageTraceListener if [ ! -d "$TEST_DIR" ]; then @@ -293,6 +298,12 @@ if test -n "$COVERAGE"; then || die "Error formating the coverage report" echo "Report available at $COVERAGE_HTML" #$OPEN "$COVERAGE_HTML" +elif test -n "$JUNIT"; then + xslt -o:"$JUNIT_RESULT" \ + -s:"$RESULT" \ + -xsl:"$XSPEC_HOME/src/reporter/junit-report.xsl" \ + || die "Error formating the JUnit report" + echo "Report available at $JUNIT_RESULT" else echo "Report available at $HTML" #$OPEN "$HTML" diff --git a/src/reporter/junit-report.xsl b/src/reporter/junit-report.xsl new file mode 100644 index 000000000..ed53cc3a8 --- /dev/null +++ b/src/reporter/junit-report.xsl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + skipped + passed + failed + + + + + + + + + + + + + + + Expected: + + + + + + + diff --git a/test/xspec-junit.xspec b/test/xspec-junit.xspec new file mode 100644 index 000000000..bbff26ac4 --- /dev/null +++ b/test/xspec-junit.xspec @@ -0,0 +1,87 @@ + + + + + + + Successful test + +

Foo

+
+ +

Foo

+
+
+
+ + + + +
+ + + + + + failing test + +

Foo

+
+ +

Bar

+
+
+
+ + + + <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"> + <p>Bar</p> +</x:expect> + + +
+ + + + + + Successful test + +

Foo

+
+ +

Foo

+
+
+ + Failing test + +

Foo

+
+ +

Bar

+
+
+
+ + + + + <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"> + <p>Bar</p> +</x:expect> + + +
+ + +
diff --git a/test/xspec.bats b/test/xspec.bats new file mode 100644 index 000000000..de98a345d --- /dev/null +++ b/test/xspec.bats @@ -0,0 +1,55 @@ + +#!/usr/bin/env bats +#=============================================================================== +# +# USAGE: bats xspec.bats +# +# DESCRIPTION: Unit tests for script bin/xspec.sh +# +# INPUT: N/A +# +# OUTPUT: Unit tests results +# +# DEPENDENCIES: This script requires bats (https://github.com/sstephenson/bats) +# +# AUTHOR: Sandro Cirulli, github.com/cirulls +# +# LICENSE: MIT License (https://opensource.org/licenses/MIT) +# +#=============================================================================== + +@test "invoking xspec without arguments prints usage" { + run ../bin/xspec.sh + [ "$status" -eq 1 ] + [ "${lines[2]}" = "Usage: xspec [-t|-q|-c|-j|-h] filename [coverage]" ] +} + +@test "invoking xspec generates XML report file" { + run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec + run stat ../tutorial/xspec/escape-for-regex-result.xml + [ "$status" -eq 0 ] +} + +@test "invoking xspec generates HTML report file" { + run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec + run stat ../tutorial/xspec/escape-for-regex-result.html + [ "$status" -eq 0 ] +} + +@test "invoking xspec with -j option generates message with JUnit report location" { + run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec + [ "$status" -eq 0 ] + [ "${lines[18]}" = "Report available at ../tutorial/xspec/escape-for-regex-junit.xml" ] +} + +@test "invoking xspec with -j option generates XML report file" { + run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec + run stat ../tutorial/xspec/escape-for-regex-result.xml + [ "$status" -eq 0 ] +} + +@test "invoking xspec with -j option generates JUnit report file" { + run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec + run stat ../tutorial/xspec/escape-for-regex-junit.xml + [ "$status" -eq 0 ] +} From 3c40268d4e5f1bd819fd631c23b65c8eecddca1e Mon Sep 17 00:00:00 2001 From: Sandro Cirulli Date: Sun, 14 Aug 2016 16:03:38 +0100 Subject: [PATCH 2/3] implement JUnit report (#2) --- bin/xspec.sh | 4 ++++ test/xspec.bats | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/bin/xspec.sh b/bin/xspec.sh index f03cb974c..4474c2605 100755 --- a/bin/xspec.sh +++ b/bin/xspec.sh @@ -170,6 +170,10 @@ while echo "$1" | grep -- ^- >/dev/null 2>&1; do COVERAGE=1;; # JUnit report -j) + if [[ ${SAXON_CP} != *"saxon9pe"* && ${SAXON_CP} != *"saxon9ee"* ]]; then + echo "JUnit report requires Saxon extension functions which are available only under Saxon9EE or Saxon9PE." + exit 1 + fi JUNIT=1;; # Help! -h) diff --git a/test/xspec.bats b/test/xspec.bats index de98a345d..e320ebedc 100644 --- a/test/xspec.bats +++ b/test/xspec.bats @@ -24,6 +24,7 @@ [ "${lines[2]}" = "Usage: xspec [-t|-q|-c|-j|-h] filename [coverage]" ] } + @test "invoking xspec generates XML report file" { run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec run stat ../tutorial/xspec/escape-for-regex-result.xml @@ -36,6 +37,14 @@ [ "$status" -eq 0 ] } +@test "invoking xspec with -j option with Saxon9HE returns error message" { + export SAXON_CP=/path/to/saxon9he.jar + run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec + [ "$status" -eq 1 ] + [ "${lines[1]}" = "JUnit report requires Saxon extension functions which are available only under Saxon9EE or Saxon9PE." ] +} + + @test "invoking xspec with -j option generates message with JUnit report location" { run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec [ "$status" -eq 0 ] From feb001cde346daec66b1229622bc1e3da3a94ab7 Mon Sep 17 00:00:00 2001 From: Sandro Cirulli Date: Wed, 17 Aug 2016 21:13:32 +0100 Subject: [PATCH 3/3] replace saxon:serialize() with fn:serialize #81 - replace saxon:serialize() with fn:serialize and use XSLT 3.0 - output error message for Saxon8 and Saxon8-SA - update XSpec unit test (unit test requires support for XSLT 3.0 to run as requested in #74) - update bats unit test --- bin/xspec.sh | 4 ++-- src/reporter/junit-report.xsl | 11 +++++------ test/xspec-junit.xspec | 23 +++++++---------------- test/xspec.bats | 14 +++++++++++--- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/bin/xspec.sh b/bin/xspec.sh index 4474c2605..dade08447 100755 --- a/bin/xspec.sh +++ b/bin/xspec.sh @@ -170,8 +170,8 @@ while echo "$1" | grep -- ^- >/dev/null 2>&1; do COVERAGE=1;; # JUnit report -j) - if [[ ${SAXON_CP} != *"saxon9pe"* && ${SAXON_CP} != *"saxon9ee"* ]]; then - echo "JUnit report requires Saxon extension functions which are available only under Saxon9EE or Saxon9PE." + if [[ ${SAXON_CP} == *"saxon8"* || ${SAXON_CP} == *"saxon8sa"* ]]; then + echo "Saxon8 detected. JUnit report requires Saxon9." exit 1 fi JUNIT=1;; diff --git a/src/reporter/junit-report.xsl b/src/reporter/junit-report.xsl index ed53cc3a8..6b2ca203c 100644 --- a/src/reporter/junit-report.xsl +++ b/src/reporter/junit-report.xsl @@ -9,22 +9,21 @@ Executed from bin/xspec.sh Input: XSpec XML report Output: JUnit report - Dependencies: This XSLT requires Saxon9EE or Saxon9PE - as it uses the extension function saxon:serialize() + Dependencies: It requires XSLT 3.0 for function fn:serialize() Authors: Kal Ahmed, github.com/kal Sandro Cirulli, github.com/cirulls License: MIT License (https://opensource.org/licenses/MIT) ======================================================================== --> - + xmlns:fn="http://www.w3.org/2005/xpath-functions" + exclude-result-prefixes="x xs test pkg xhtml fn"> @@ -82,7 +81,7 @@ - + diff --git a/test/xspec-junit.xspec b/test/xspec-junit.xspec index bbff26ac4..9e10616d4 100644 --- a/test/xspec-junit.xspec +++ b/test/xspec-junit.xspec @@ -1,5 +1,5 @@ - + @@ -33,16 +33,12 @@ + - - <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"> - <p>Bar</p> -</x:expect> - + <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"><p>Bar</p></x:expect> + @@ -73,13 +69,8 @@ - <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"> - <p>Bar</p> -</x:expect> - + <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"><p>Bar</p></x:expect> + diff --git a/test/xspec.bats b/test/xspec.bats index e320ebedc..7c4998a5c 100644 --- a/test/xspec.bats +++ b/test/xspec.bats @@ -37,11 +37,19 @@ [ "$status" -eq 0 ] } -@test "invoking xspec with -j option with Saxon9HE returns error message" { - export SAXON_CP=/path/to/saxon9he.jar +@test "invoking xspec with -j option with Saxon8 returns error message" { + export SAXON_CP=/path/to/saxon8.jar run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec [ "$status" -eq 1 ] - [ "${lines[1]}" = "JUnit report requires Saxon extension functions which are available only under Saxon9EE or Saxon9PE." ] + [ "${lines[1]}" = "Saxon8 detected. JUnit report requires Saxon9." ] +} + + +@test "invoking xspec with -j option with Saxon8-SA returns error message" { + export SAXON_CP=/path/to/saxon8sa.jar + run ../bin/xspec.sh -j ../tutorial/escape-for-regex.xspec + [ "$status" -eq 1 ] + [ "${lines[1]}" = "Saxon8 detected. JUnit report requires Saxon9." ] }