Skip to content

Commit

Permalink
Now XSpec for XQuery, plus a format-neutral XProc step to run any XSp…
Browse files Browse the repository at this point in the history
…ec (dispatching to the correct type)
  • Loading branch information
wendellpiez committed Jun 25, 2024
1 parent ed57a95 commit efb73f6
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Run tests
run: |
./xp3.sh testing/HARDFAIL-XPROC3-HOUSE-RULES.xpl
./xp3.sh testing/BATCH-XSPEC-JUNIT.xpl
./xp3.sh testing/RUN_XSPEC-JUNIT_BATCH.xpl
id: exec_tests
- name: Upload test results
if: always()
Expand Down
2 changes: 1 addition & 1 deletion smoketest/SMOKETEST-SCHEMATRON.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
see https://spec.xproc.org/master/head/validation/#c.validate-with-schematron
-->
<p:validate-with-schematron assert-valid="true">
<p:with-input port="schema" href="doing-well.sch"/>
<p:with-input port="schema" href="src/doing-well.sch"/>
<p:with-input port="source">
<p:inline>
<CONGRATULATIONS>Schematron runs under XProc 3.0.</CONGRATULATIONS>
Expand Down
2 changes: 1 addition & 1 deletion smoketest/SMOKETEST-XSLT.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</p:inline>
</p:with-input>
<!-- inline XSLTs don't apparently work so well inside Morgana? -->
<p:with-input port="stylesheet" href="congratulations.xsl"/>
<p:with-input port="stylesheet" href="src/congratulations.xsl"/>
</p:xslt>

<p:namespace-delete prefixes="ox"/>
Expand Down
2 changes: 1 addition & 1 deletion smoketest/SMOKETEST-XSPEC.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p:import href="../xspec/xspec-execute.xpl"/>

<p:input port="source">
<p:document content-type="application/xml" href="congratulations-xslt.xspec"/>
<p:document content-type="application/xml" href="src/congratulations-xslt.xspec"/>
</p:input>

<p:identity message="[SMOKETEST-XSPEC] Testing XSpec by running ./congratulations-xslt.xspec"/>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions smoketest/src/shout-function.xqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module namespace ox = "http://csrc.nist.gov/ns/oscal-xproc3";

(: Simple function providing string manipulation :)
declare function ox:SHOUT ($s as xs:string?) as xs:string? { upper-case($s) || '!!!' };

(: ox:SHOUT('Hey world') :)
16 changes: 16 additions & 0 deletions smoketest/src/shout-xquery.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:ox="http://csrc.nist.gov/ns/oscal-xproc3"
query="http://csrc.nist.gov/ns/oscal-xproc3" query-at="shout-function.xqm">

<!-- Inspired by https://github.com/xspec/xspec/blob/master/tutorial/xquery-tutorial.xspec -->

<x:scenario label="Calling function capitalize-first">
<x:call function="ox:SHOUT">
<x:param select="'hello'"/>
</x:call>
<x:expect label="Appears in UPPER CASE!!!, with GRATUITOUS EXCLAMATION POINTS!!!" select="'HELLO!!!'"/>
<x:expect label="Exclaims quite loudly (whatever it says)" test="ends-with($x:result,'!!!')"/>
</x:scenario>

</x:description>
41 changes: 0 additions & 41 deletions testing/BATCH-SCH-XSPEC.xpl

This file was deleted.

9 changes: 4 additions & 5 deletions testing/FILESET_XPROC3_HOUSE-RULES.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
<p:document href="../lib/GRAB-SCHXSLT.xpl"/>
<p:document href="../lib/GRAB-XSPEC.xpl"/>

<p:document href="BATCH-XSLT-XSPEC.xpl"/>
<p:document href="BATCH-SCH-XSPEC.xpl"/>
<p:document href="BATCH-XSPEC-JUNIT.xpl"/>
<p:document href="BATCH-XPROC3-HOUSE-RULES.xpl"/>
<p:document href="RUN_XSPEC_BATCH.xpl"/>
<p:document href="RUN_XSPEC-JUNIT_BATCH.xpl"/>
<p:document href="RUN_XPROC3-HOUSE-RULES_BATCH.xpl"/>
<p:document href="HARDFAIL-XPROC3-HOUSE-RULES.xpl"/>
<p:document href="REPO-XPROC3-HOUSE-RULES.xpl"/>
<p:document href="FILESET_XPROC3_HOUSE-RULES.xpl"/>
<p:document href="FILESET_XSLT-XSPEC.xpl"/>
<p:document href="FILESET_XSPEC.xpl"/>

<p:document href="../template/GRAB-RESOURCES.xpl"/>

Expand Down
8 changes: 5 additions & 3 deletions testing/FILESET_XSLT-XSPEC.xpl → testing/FILESET_XSPEC.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="3.0"
xmlns:ox="http://csrc.nist.gov/ns/oscal-xproc3"
type="ox:FILESET_XSLT-XSPEC"
name="FILESET_XSLT-XSPEC">
type="ox:FILESET_XSPEC"
name="FILESET_XSPEC">

<!-- Pipeline to be called as subpipeline, delivering a sequence of XSpec files, parsed as XML -->

Expand All @@ -12,7 +12,9 @@

<p:input port="source" sequence="true">
<!-- We need content type because xspec suffix throws off the parser -->
<p:document href="../smoketest/congratulations-xslt.xspec" content-type="application/xml"/>
<p:document href="../smoketest/src/congratulations-xslt.xspec" content-type="application/xml"/>
<p:document href="../smoketest/src/doing-well-schematron.xspec" content-type="application/xml"/>
<p:document href="../smoketest/src/shout-xquery.xspec" content-type="application/xml"/>

</p:input>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="3.0"
xmlns:ox="http://csrc.nist.gov/ns/oscal-xproc3"
type="ox:BATCH-XPROC3-HOUSE-RULES"
name="BATCH-XPROC3-HOUSE-RULES"
type="ox:RUN_XPROC3-HOUSE-RULES_BATCH"
name="RUN_XPROC3-HOUSE-RULES_BATCH"
>

<!-- Note: this doesn't run without an available copy of SchXSLT -
Expand All @@ -24,7 +24,7 @@
<p:group name="validation">
<p:variable name="base" select="base-uri(/*)"/>
<!-- assert-valid='true' presents c:errors results when validation fails as 'no failed assertions or successful reports' -->
<p:validate-with-schematron assert-valid="true" message="[BATCH-XPROC3-HOUSE-RULES] Validating { $base } against { $schematron-path }">
<p:validate-with-schematron assert-valid="true" message="[RUN_XPROC3-HOUSE-RULES_BATCH] Validating { $base } against { $schematron-path }">
<p:with-input port="schema" href="{$schematron-path}"/>
</p:validate-with-schematron>

Expand All @@ -41,11 +41,11 @@

<p:wrap-sequence name="wrapup" wrapper="ALL-REPORTS"/>

<p:xslt name="assessment" message="[BATCH-XPROC3-HOUSE-RULES] Assessing ...">
<p:xslt name="assessment" message="[RUN_XPROC3-HOUSE-RULES_BATCH] Assessing ...">
<p:with-input port="stylesheet" href="src/validation-screener.xsl"/>
</p:xslt>

<p:xslt name="summary" message="[BATCH-XPROC3-HOUSE-RULES] Summarizing ...">
<p:xslt name="summary" message="[RUN_XPROC3-HOUSE-RULES_BATCH] Summarizing ...">
<p:with-input port="stylesheet" href="src/validation-summarizer.xsl"/>
</p:xslt>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="3.0"
xmlns:ox="http://csrc.nist.gov/ns/oscal-xproc3"
type="ox:BATCH-XSPEC"
name="BATCH-XSPEC-JUNIT">
type="ox:RUN_XSPEC-JUNIT_BATCH"
name="RUN_XSPEC-JUNIT_BATCH">

<!-- Executes available XSpecs writing only JUnit results -->

<p:import href="FILESET_XSLT-XSPEC.xpl"/>
<p:import href="FILESET_XSPEC.xpl"/>

<p:import href="../xspec/xspec-execute.xpl"/>

<p:variable name="repo-root" select="resolve-uri('.. ',static-base-uri()) => replace('^file:///','file:/')"/>

<p:variable name="outdir" select="'xspec-reports' => resolve-uri(static-base-uri())"/>

<ox:FILESET_XSLT-XSPEC name="test-set"/>
<ox:FILESET_XSPEC name="test-set"/>

<p:for-each>
<p:with-input pipe="xspec-files@test-set"/>
Expand All @@ -25,9 +25,9 @@
<p:variable name="html-report-path" select="replace($relative-path,'\.xspec$','') || '_report.html' "/>
<p:variable name="junit-report-path" select="replace($relative-path,'\.xspec$','') || '_junit.xml' "/>

<ox:xslt-xspec-execute name="execute-xspec"/>
<ox:xspec-execute name="execute-xspec"/>

<p:store message="[BATCH-XSPEC-JUNIT] storing JUnit report in {$outdir}/{$junit-report-path}" href="{$outdir}/{$junit-report-path}">
<p:store message="[RUN_XSPEC-JUNIT_BATCH] storing JUnit report in {$outdir}/{$junit-report-path}" href="{$outdir}/{$junit-report-path}">
<p:with-input port="source" pipe="xspec-junit-report@execute-xspec"/>
</p:store>
<p:sink/>
Expand Down
12 changes: 6 additions & 6 deletions testing/BATCH-XSLT-XSPEC.xpl → testing/RUN_XSPEC_BATCH.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="3.0"
xmlns:ox="http://csrc.nist.gov/ns/oscal-xproc3"
type="ox:BATCH-XSLT-XSPEC"
name="BATCH-XSLT-XSPEC"
type="ox:RUN_XSPEC_BATCH"
name="RUN_XSPEC_BATCH"
>

<!-- Executes available XSpecs -->

<p:import href="FILESET_XSLT-XSPEC.xpl"/>
<p:import href="FILESET_XSPEC.xpl"/>

<p:import href="../xspec/xspec-execute.xpl"/>

<p:variable name="repo-root" select="resolve-uri('.. ',static-base-uri()) => replace('^file:///','file:/')"/>

<p:variable name="outdir" select="'xspec-reports' => resolve-uri(static-base-uri())"/>

<ox:FILESET_XSLT-XSPEC name="test-set"/>
<ox:FILESET_XSPEC name="test-set"/>

<p:for-each>
<p:with-input pipe="xspec-files@test-set"/>
Expand All @@ -28,10 +28,10 @@

<ox:xslt-xspec-execute name="execute-xspec"/>

<p:store message="[BATCH-XSLT-XSPEC] storing HTML report in {$outdir}/{$html-report-path}" href="{$outdir}/{$html-report-path}">
<p:store message="[RUN_XSPEC_BATCH] storing HTML report in {$outdir}/{$html-report-path}" href="{$outdir}/{$html-report-path}">
<p:with-input port="source" pipe="xspec-html-report@execute-xspec"/>
</p:store>
<p:store message="[BATCH-XSLT-XSPEC] storing JUnit report in {$outdir}/{$junit-report-path}" href="{$outdir}/{$junit-report-path}">
<p:store message="[RUN_XSPEC_BATCH] storing JUnit report in {$outdir}/{$junit-report-path}" href="{$outdir}/{$junit-report-path}">
<p:with-input port="source" pipe="xspec-junit-report@execute-xspec"/>
</p:store>
<p:sink/>
Expand Down
4 changes: 2 additions & 2 deletions testing/xproc3-house-rules.sch
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@
<sch:let name="type-uri" value="namespace-uri-for-prefix($type-prefix, .)"/>
<sch:let name="typename-given" value="@type/tokenize(., ':')[last()]"/>

<sch:assert sqf:fix="sqf-repair-step-type" test="contains($basename, $typename-given) or contains($typename-given, $basename)">Unexpected declared type <sch:value-of select="$typename-given"/> for the file named <sch:value-of select="$filename"/></sch:assert>
<sch:assert sqf:fix="sqf-repair-step-type" test="contains($basename, $typename-given) or contains($typename-given, $basename) or exists(/p:library)">Unexpected declared type <sch:value-of select="$typename-given"/> for the file named <sch:value-of select="$filename"/></sch:assert>
<sch:assert sqf:fix="sqf-repair-step-type" test="$type-uri = 'http://csrc.nist.gov/ns/oscal-xproc3'">XProc step @type is not given in namespace 'http://csrc.nist.gov/ns/oscal-xproc3'</sch:assert>
<sch:assert sqf:fix="sqf-repair-step-name" test="(@name = $basename) or not(. is /*)">XProc step @name does not match the file name '<sch:value-of select="$filename"/>'</sch:assert>
<sch:assert sqf:fix="sqf-repair-step-name" test="(@name = $basename) or exists(/p:library)">XProc step @name does not match the file name '<sch:value-of select="$filename"/>'</sch:assert>
</sch:rule>

<sch:rule context="p:load | p:store">
Expand Down
Loading

0 comments on commit efb73f6

Please sign in to comment.