zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #15857
[Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
Sorin Marian Nasoi has proposed merging lp:~zorba-coders/zorba/fots_driver into lp:zorba.
Commit message:
Added FOTS driver.
Requested reviews:
Cezar Andrei (cezar-andrei)
Paul J. Lucas (paul-lucas)
Ghislain Fourny (gislenius)
Chris Hillery (ceejatec)
Zorba Coders (zorba-coders)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/fots_driver/+merge/133988
Added FOTS driver.
--
https://code.launchpad.net/~zorba-coders/zorba/fots_driver/+merge/133988
Your team Zorba Coders is requested to review the proposed merge of lp:~zorba-coders/zorba/fots_driver into lp:zorba.
=== added directory 'test/fots_driver'
=== added file 'test/fots_driver/FOTSZorbaManifest.xml'
--- test/fots_driver/FOTSZorbaManifest.xml 1970-01-01 00:00:00 +0000
+++ test/fots_driver/FOTSZorbaManifest.xml 2012-11-12 20:35:24 +0000
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FOTS-test-suite-result xmlns="http://www.w3.org/2010/09/qt-fots-catalog">
+ <implementation name="Zorba" version="trunk" anonymous-result-column="false">
+ <organization name="http://www.zorba-xquery.com" anonymous="false"/>
+ <submitter name="Sorin Nasoi" email="spungi@xxxxxxxxx"/>
+ </implementation>
+ <dependencies-satisfied>
+ <dependency type="feature" value="collection-stability" satisfied="true"/> <!-- Is this correct? -->
+ <dependency type="feature" value="directory-as-collection-uri" satisfied="true"/> <!-- Is this correct? -->
+ <dependency type="feature" value="higherOrderFunctions" satisfied="false"/>
+ <dependency type="feature" value="moduleImport" satisfied="true"/>
+ <dependency type="feature" value="namespace-axis" satisfied="false"/> <!-- Is this correct? -->
+ <dependency type="feature" value="schema-location-hint" satisfied="false"/> <!-- Is this correct? -->
+ <dependency type="feature" value="schemaAware" satisfied="true"/>
+ <dependency type="feature" value="schemaImport" satisfied="true"/>
+ <dependency type="feature" value="schemaValidation" satisfied="true"/>
+ <dependency type="feature" value="staticTyping" satisfied="false"/>
+ <dependency type="feature" value="xpath-1.0-compatibility" satisfied="true"/> <!-- Is this correct? -->
+
+ <dependency type="spec" value="XP10 XQ10" satisfied="true"/>
+ <dependency type="spec" value="XP10+" satisfied="true"/>
+ <dependency type="spec" value="XP20 XQ10" satisfied="true"/>
+ <dependency type="spec" value="XP20+" satisfied="true"/>
+ <dependency type="spec" value="XP30+" satisfied="true"/>
+ <dependency type="spec" value="XP30+ XQ10+" satisfied="true"/>
+ <dependency type="spec" value="XP30+ XQ30+" satisfied="true"/>
+ <dependency type="spec" value="XQ10" satisfied="true"/>
+ <dependency type="spec" value="XQ10 XP20" satisfied="true"/>
+ <dependency type="spec" value="XQ10+" satisfied="true"/>
+ <dependency type="spec" value="XQ10+ XP20+" satisfied="true"/>
+ <dependency type="spec" value="XQ10+ XP30+" satisfied="true"/>
+ <dependency type="spec" value="XQ30" satisfied="true"/>
+ <dependency type="spec" value="XQ30 XP30" satisfied="true"/>
+ <dependency type="spec" value="XQ30+" satisfied="true"/>
+ <dependency type="spec" value="XQ30+ XP30+" satisfied="true"/>
+ <dependency type="spec" value="XT30+" satisfied="false"/>
+
+ <dependency type="xml-version" value="1.0" satisfied="true"/>
+ <dependency type="xml-version" value="1.0:4-" satisfied="true"/>
+ <dependency type="xml-version" value="1.0:5+ 1.1" satisfied="false"/>
+ <dependency type="xml-version" value="1.1" satisfied="false"/>
+
+ <dependency type="language" value="de" satisfied="false"/> <!-- Is this correct? -->
+ <dependency type="language" value="en" satisfied="true"/>
+ <dependency type="language" value="xib" satisfied="false"/> <!-- Is this correct? -->
+
+ <!-- Are these correct? -->
+ <dependency type="limits" value="year_lt_0" satisfied="true"/>
+ <dependency type="calendar" value="CB" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="Α" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="α" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="١" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="①" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="⑴" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="⒈" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="一" satisfied="true"/>
+ <dependency type="format-integer-sequence" value="ﯴ" satisfied="true"/>
+ <dependency type="default-language" value="en" satisfied="true"/>
+ <dependency type="unicode-normalization-form" value="FULLY-NORMALIZED" satisfied="true"/>
+ <dependency type="unicode-normalization-form" value="NFD" satisfied="true"/>
+ <dependency type="unicode-normalization-form" value="NFKC" satisfied="true"/>
+ <dependency type="unicode-normalization-form" value="NFKD" satisfied="true"/>
+ <dependency type="xsd-version" value="1.0" satisfied="true"/>
+ <dependency type="xsd-version" value="1.1" satisfied="false"/>
+ </dependencies-satisfied>
+</FOTS-test-suite-result>
=== added file 'test/fots_driver/README.TXT'
--- test/fots_driver/README.TXT 1970-01-01 00:00:00 +0000
+++ test/fots_driver/README.TXT 2012-11-12 20:35:24 +0000
@@ -0,0 +1,47 @@
+Information about the W3C XQuery/XPath/XSLT 3.* Test Suite can be found here: http://dev.w3.org/2011/QT3-test-suite.
+
+In order to use the Zorba FOTS driver (written in XQuery) one has to follow these steps:
+
+0) Build Zorba with ZORBA_WITH_BIG_INTEGER flag set to ON.
+
+ For example with CMake:
+ cmake -DZORBA_WITH_BIG_INTEGER=ON ..
+ make
+
+1) Download the FOTS testsuite from W3C
+ Since currently there is no official release, a simple "cvs get" will do:
+
+ $ export CVSROOT=":pserver:anonymous@xxxxxxxxxx:/sources/public"
+ $ cvs login
+ (Logging in to anonymous@xxxxxxxxxx)
+ CVS password: anonymous
+ $ cvs get 2011/QT3-test-suite
+
+3) run
+ ./zorba -f
+ -q ../../test/fots_driver/cli.xq
+
+Zorba FOTS driver usage examples:
+If you run Zorba from a checkout of the trunk and the build/bin folder,
+- /path/to/cli.xq can be set to ../../test/fots_driver/cli.xq
+
+Always try to run the CLI and output the result back to an XML file with nice indentation.
+./zorba -f
+ -q ../../test/fots_driver/cli.xq
+ -e SET_CLI_OPTIONS_HERE
+ -o output.xml
+ --indent
+ This way you will see trace information in the CLI window and detailed results of the tests in the 'output.xml'.
+
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e fotsZorbaManifestPath:=/path/to/Zorba_manifest.xml -e mode:=list-test-sets
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets -e verbose:=true
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets -e testSetPrefixes:=prod,app
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-cases -e testSetPrefixes:=prod-Literal
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-matching-test-cases -e pattern:=catch
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-sets -e testSetPrefixes:=prod-Literal -o result.xml --indent
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-sets -e testSetPrefixes:=prod-Literal -e verbose:=false -o result.xml --indent
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-cases -e testSetPrefixes:=prod-Literal -e testCasePrefixes:=Literal -o result.xml --indent
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-cases -e assertType:=assert-count -e testSetPrefixes:=fn-innermost -o result.xml --indent
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-cases -e assertType:=assert-count -o result.xml --indent
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-and-report -o report.xml --indent
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=report -e failuresFilePath:=failures.xml -e verbose:=false -o report.xml --indent
\ No newline at end of file
=== added file 'test/fots_driver/cli.xq'
--- test/fots_driver/cli.xq 1970-01-01 00:00:00 +0000
+++ test/fots_driver/cli.xq 2012-11-12 20:35:24 +0000
@@ -0,0 +1,166 @@
+(:
+ : Copyright 2006-2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : Zorba FOTS driver CLI
+ : @author Ghislain Fourny, Sorin Nasoi
+ :)
+
+(:declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";:)
+
+import module namespace driver = "http://www.zorba-xquery.com/fots-driver" at "fots-driver.xq";
+import module namespace reporting = "http://www.zorba-xquery.com/fots-driver/reporting" at "reporting.xq";
+import module namespace fots-err = "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
+
+(:~ path to the place where FOTS can be found :)
+declare variable $fotsPath as xs:string external := "";
+
+(:~ path to the place where the FOTS Zorba manifest can be found :)
+declare variable $fotsZorbaManifestPath as xs:string external := "FOTSZorbaManifest.xml";
+
+(:~ The path to the results from a previous run :)
+declare variable $failuresFilePath as xs:string external := "";
+
+(:~ choose the CLI option you want to run :)
+declare variable $mode as xs:string external := "";
+
+(:~ name/criteria for the test sets :)
+declare variable $testSetPrefixes as xs:string external := "";
+
+(:~ name/criteria for the test cases :)
+declare variable $testCasePrefixes as xs:string external := "";
+
+(:~ Enable or disable verbose output :)
+declare variable $verbose as xs:string external := "true";
+
+(:~
+ Enable or disable showing the actual query result in the output.
+ True by default.
+:)
+declare variable $showResult as xs:string external := "true";
+
+(:~ list of assertion types :)
+declare variable $assertType as xs:string external := "";
+
+(:~ regex for the tests in the 'list-matching-test-cases' option :)
+declare variable $pattern as xs:string external := "";
+
+(:~ flags for the tests in the 'list-matching-test-cases' option :)
+declare variable $flags as xs:string external := "";
+
+declare %private function local:tokenize-comma-or-empty-string(
+ $input as xs:string
+) as xs:string*
+{
+ let $tokens := tokenize($input, ",")
+ return if (exists($tokens)) then $tokens else ""
+};
+
+declare function local:usage() as xs:string
+{
+ string-join((
+ "Zorba FOTS driver usage examples:",
+ "If you run Zorba from a checkout of the trunk and the build/bin folder,",
+ "- /path/to/cli.xq can be set to ../../test/fots_driver/cli.xq",
+ "",
+ "Always try to run the CLI and output the result back to an XML file with nice indentation.",
+ "./zorba -f",
+ " -q ../../test/fots_driver/cli.xq",
+ " -e SET_CLI_OPTIONS_HERE",
+ " -o output.xml",
+ " --indent",
+ " This way you will see trace information in the CLI window and detailed results of the tests in the 'output.xml'.",
+ "",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e fotsZorbaManifestPath:=/path/to/Zorba_manifest.xml -e mode:=list-test-sets",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets -e verbose:=true",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets -e testSetPrefixes:=prod,app",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-cases -e testSetPrefixes:=prod-Literal",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-matching-test-cases -e pattern:=catch",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-sets -e testSetPrefixes:=prod-Literal -o result.xml --indent",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-sets -e testSetPrefixes:=prod-Literal -e verbose:=false -o result.xml --indent",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-cases -e testSetPrefixes:=prod-Literal -e testCasePrefixes:=Literal -o result.xml --indent",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-cases -e assertType:=assert-count -e testSetPrefixes:=fn-innermost -o result.xml --indent",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-cases -e assertType:=assert-count -o result.xml --indent",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-and-report -o report.xml --indent",
+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=report -e failuresFilePath:=failures.xml -e verbose:=false -o report.xml --indent",
+ ""
+ ), "
")
+};
+
+(:~ The test cases in this list have bugs assigned already and should not be run :)
+variable $exceptedTestCases := (
+ "cbcl-subsequence-011", "cbcl-subsequence-012", "cbcl-subsequence-013", "cbcl-subsequence-014" (:see bug lp:1069794 :)
+, "re00975", "re00976", "re00976a" (:see bug lp:1070533 :)
+, "fn-unparsed-text-lines-052" (:see bug lp:1073175 :)
+);
+
+(:~ The test in this list have bugs assigned already and should not be run :)
+variable $exceptedTestSets := ();
+
+switch ($mode)
+case "list-test-sets"
+ return string-join((driver:list-test-sets(trace($fotsPath,"The path to FOTS catalog.xml was set to: "),
+ local:tokenize-comma-or-empty-string(trace($testSetPrefixes,"'testSetPrefixes' was set to: ")))),
+ "
")
+case "list-test-cases"
+ return string-join((driver:list-test-cases(trace($fotsPath,"The path to FOTS catalog.xml was set to: "),
+ local:tokenize-comma-or-empty-string(trace($testSetPrefixes,"'testSetPrefixes' was set to: "))), ""),
+ "
")
+case "list-matching-test-cases"
+ return string-join((driver:list-matching-test-cases(trace($fotsPath,"The path to FOTS catalog.xml was set to: "),
+ trace($pattern, "pattern was set to: "),
+ trace($flags, "flags were set to: ")), ""),
+ "
")
+case "run-test-sets"
+ return driver:run-fots( $fotsPath,
+ $fotsZorbaManifestPath,
+ driver:list-test-sets($fotsPath,
+ local:tokenize-comma-or-empty-string(trace($testSetPrefixes,"'testSetPrefixes' was set to: "))),
+ trace('',"'testCasePrefixes' was set to: "),
+ $exceptedTestCases,
+ $exceptedTestSets,
+ $assertType,
+ xs:boolean($verbose),
+ xs:boolean($showResult))
+case "run-test-cases"
+ return driver:run-fots( $fotsPath,
+ $fotsZorbaManifestPath,
+ local:tokenize-comma-or-empty-string(trace($testSetPrefixes,"'testSetPrefixes' was set to: ")),
+ local:tokenize-comma-or-empty-string(trace($testCasePrefixes,"'testCasePrefixes' was set to: ")),
+ $exceptedTestCases,
+ $exceptedTestSets,
+ $assertType,
+ xs:boolean($verbose),
+ xs:boolean($showResult))
+case "run-and-report"
+ return reporting:run-and-report($fotsPath,
+ $fotsZorbaManifestPath,
+ driver:list-test-sets($fotsPath,
+ local:tokenize-comma-or-empty-string($testSetPrefixes)),
+ '',
+ $exceptedTestCases,
+ $exceptedTestSets,
+ $assertType,
+ fn:false(), (: the reports to W3C are always generated with verbose set to false:)
+ xs:boolean($showResult))
+case "report"
+ return reporting:report($fotsPath,
+ $failuresFilePath,
+ $exceptedTestCases,
+ $exceptedTestSets,
+ xs:boolean($verbose))
+default
+ return local:usage()
=== added file 'test/fots_driver/environment.xq'
--- test/fots_driver/environment.xq 1970-01-01 00:00:00 +0000
+++ test/fots_driver/environment.xq 2012-11-12 20:35:24 +0000
@@ -0,0 +1,427 @@
+(:
+ : Copyright 2006-2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : Zorba FOTS driver environment
+ : @author Sorin Nasoi
+ :)
+
+module namespace env = "http://www.zorba-xquery.com/fots-driver/environment";
+
+import module namespace xqxq = "http://www.zorba-xquery.com/modules/xqxq";
+import module namespace util = "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
+
+declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";
+
+
+declare variable $env:hof as xs:string :=
+ string-join(( "declare namespace op = 'http://www.zorba-xquery.com/options/features';",
+ "declare namespace f = 'http://www.zorba-xquery.com/features';",
+ "declare option op:enable 'f:hof';")
+ ,"
");
+
+(:~
+ : Retrieves the environment from a test-set or catalog given an environment name.
+ : @param $catalog FOTS catalog file.
+ : @param $testSet test set.
+ : @param $envName name of the environment.
+ : @return the environment with the given name.
+ :)
+declare function env:get-environment (
+ $catalog,
+ $testSet as element (fots:test-set),
+ $envName as xs:string
+) as element(fots:environment)? {
+ let $envTestSet := $testSet/test-set//environment[@name = $envName]
+ return
+ if (fn:empty($envTestSet))
+ then $catalog/catalog//environment[@name = $envName]
+ else $envTestSet
+};
+
+declare %ann:nondeterministic function env:add-var-decl(
+ $env as element(fots:environment)?,
+ $case as element(fots:test-case)
+) as xs:string? {
+ fn:concat(env:var-decl-with-value($env, $case/fots:environment),
+ env:var-decl-without-value($env, $case/fots:environment))
+};
+
+(: if defined, returns the string for setting the context item :)
+declare function env:set-context-item(
+ $env as element(fots:environment)?,
+ $envBaseURI as xs:anyURI?
+) as xs:string? {
+ if(empty($env)) then ()
+ else if(data($env/@name) = 'empty') then ()
+ else if (fn:exists($env/fots:source[@role = "."])) then
+ string-join((env:declare-context-item($env, $envBaseURI),
+ 'xqxq:bind-context-item($queryID, $contextItem);')
+ ,"
")
+ else ()
+};
+
+(:~
+ : Returns the strings for variable binding in XQXQ.
+ :
+ : @param $env the environment of the catalog or the test-set (given with 'ref').
+ : @param $envCase the environment of the test-case.
+ : @param $envBaseURI the relative URI for the environment.
+ : @return the queryKey after the variables were bound.
+ :)
+declare function env:set-variables(
+ $env as element(fots:environment)?,
+ $envBaseURI as xs:anyURI
+) as xs:string? {
+ if(empty($env)) then ()
+ else
+ let $srcNames := for $source in $env/fots:source
+ where fn:starts-with(fn:data($source/@role),"$")
+ return substring-after(fn:data($source/@role),"$"),
+ $srcValues := for $srcName in $srcNames
+ return concat('fn:doc("',
+ resolve-uri($env/fots:source[@role = concat("$",$srcName)]/@file, $envBaseURI),
+ '")')
+ return
+ string-join((for $srcName in $srcNames
+ let $index := index-of($srcNames, $srcName)
+ return
+ concat('xqxq:bind-variable( $queryID, xs:QName("', $srcName, '")',
+ ', ', $srcValues[$index], ');'),
+
+ for $param in $env/fots:param
+ let $select:= fn:data($param/@select)
+ let $varValue := if(starts-with($select, "'") and ends-with($select, "'")) then
+ concat('"',
+ resolve-uri($env/fots:source[@uri = fn:translate($param/@select, "'", "")]/@file, $envBaseURI),
+ '"')
+ else $select
+ let $varName := fn:data($param/@name)
+ return
+ concat('xqxq:bind-variable( $queryID, xs:QName("', fn:data($param/@name), '")',
+ ', ', $varValue, ');')
+ ), "
")
+};
+
+(:~
+ : Adds the necessary declare namespace statements.
+ :
+ : @param $env the environment of the catalog or the test-set (given with 'ref').
+ : @param $case the test-case.
+ : @param $testSetBaseURI the URI of the test set file.
+ : @return the declare namespace statements.
+ :)
+declare %ann:nondeterministic function env:decl-namespaces(
+ $env as element(fots:environment)?,
+ $case as element(fots:test-case),
+ $testSetBaseURI as xs:anyURI
+) as xs:string? {
+ string-join(for $ns in ($env/fots:namespace, $case/fots:environment/fots:namespace)
+ where fn:not($ns[@prefix=""]) and not(env:is-schema-prefix-bound(fn:data($ns/@prefix), $case, $testSetBaseURI))
+ return concat('declare namespace ',
+ fn:data($ns/@prefix),
+ ' = "',
+ fn:data($ns/@uri),
+ '";')
+ ," ")
+};
+
+(:~
+ : Sets the declared default element namespace.
+ :
+ : @param $env the environment of the catalog or the test-set (given with 'ref').
+ : @param $envCase the environment of the test-case.
+ : @return the declare default element namespace.
+ :)
+declare function env:decl-def-elem-namespace(
+ $env as element(fots:environment)?,
+ $envCase as element(fots:environment)?
+) as xs:string? {
+ for $ns in ($env/fots:namespace, $envCase/fots:namespace)
+ where $ns[@prefix=""]
+ return concat('declare default element namespace "',
+ fn:data($ns/@uri),
+ '";')
+};
+
+(:~
+ : Sets the static base uri.
+ :
+ : @param $env the environment of the catalog or the test-set (given with 'ref').
+ : @param $envCase the environment of the test-case.
+ : @return the declare base-uri prolog statement.
+ :)
+declare function env:decl-base-uri(
+ $env as element(fots:environment)?,
+ $envCase as element(fots:environment)?
+) as xs:string? {
+ for $baseURI in ($env/fots:static-base-uri, $envCase/fots:static-base-uri)
+ return concat("declare base-uri '",
+ fn:data($baseURI/@uri),
+ "';")
+};
+(:~
+ : Return true if the prefix will be bound to a schema in the Query
+ : It's a bug in the FOTS if this function returns true: I have reported the issue and made this fix until relevant FOTS tests are fixed.
+ :)
+declare %private %ann:nondeterministic function env:is-schema-prefix-bound(
+ $prefix as xs:string,
+ $case as element(fots:test-case),
+ $testSetBaseURI as xs:anyURI
+) as xs:boolean {
+ contains( util:get-value($case, $testSetBaseURI, "test"),
+ concat("import schema namespace ", $prefix))
+};
+
+declare %private function env:get-schema-import (
+ $env as element(fots:environment)?
+) as xs:string {
+ if (empty($env)) then ""
+ else
+ let $namespace := $env/fots:namespace[@uri = fn:data($env/fots:schema/@uri)]
+ let $prefix as xs:string := if(exists($namespace)) then xs:string(fn:data($namespace/@prefix)) else "p"
+ return
+ if($prefix = "")
+ then concat('import schema default element namespace "',
+ $env/fots:schema/@uri,
+ '";
')
+ else concat('import schema namespace ',
+ $prefix,
+ ' = "',
+ $env/fots:schema/@uri,
+ '";
')
+};
+
+declare %private function env:var-decl-with-value(
+ $env as element(fots:environment)?,
+ $envCase as element(fots:environment)?
+) as xs:string? {
+ fn:string-join(
+ for $param in ($env/fots:param, $envCase/fots:param)
+ where fn:exists(fn:data($param/@select))
+ and not(starts-with(fn:data($param/@select),"'"))
+ and empty(fn:data($param[@declared="true"]))
+ return concat("declare variable $",
+ fn:data($param/@name),
+ " := ",
+ fn:data($param/@select),";")
+ ," ")
+};
+
+declare %private function env:var-decl-without-value(
+ $env as element(fots:environment)?,
+ $envCase as element(fots:environment)?
+) as xs:string? {
+ fn:string-join(
+ (for $param in ($env/fots:param, $envCase/fots:param)
+ where (fn:empty(fn:data($param/@select)) or
+ (fn:exists(fn:data($param/@select))
+ and starts-with(fn:data($param/@select),"'")))
+ and empty(fn:data($param[@declared="true"]))
+ return concat("declare variable $",
+ fn:data($param/@name),
+ " external;"),
+ for $source in ($env/fots:source, $envCase/fots:source)
+ where fn:starts-with(fn:data($source/@role),"$")
+ return concat("declare variable ",
+ fn:data($source/@role),
+ " external;"))
+ ," ")
+};
+
+declare %private function env:declare-context-item(
+ $env as element(fots:environment)?,
+ $envBaseURI as xs:anyURI?
+) as xs:string {
+ let $ciURI := resolve-uri($env/fots:source[@role = "."]/@file, $envBaseURI)
+ return
+ if(empty($env/fots:source[@validation = "strict"])) then
+ concat('variable $contextItem := doc("', $ciURI, '");')
+ else
+ string-join(("
","variable $contextItemQuery := xqxq:prepare-main-module('",
+ env:get-schema-import($env),
+ concat('validate { doc("', $ciURI, '")', "}',", " "),
+ "resolver:url-resolver#2, ());",
+ "variable $contextItem := xqxq:evaluate($contextItemQuery);")
+ ,"
")
+};
+
+(:~
+ : Returns the needed XQXQ URL resolver declaration.
+ : @param $case the test case.
+ : @param $env the environment.
+ : @param $envBaseURI URI of the environment.
+ : @param $testSetBaseURI URI to the test set that defines the test case.
+ : @return the needed XQXQ URL resolver declaration.
+ :)
+declare function env:resolver(
+ $case as element(fots:test-case),
+ $env as element(fots:environment)?,
+ $envBaseURI as xs:anyURI?,
+ $testSetBaseURI as xs:anyURI
+) as xs:string?
+{
+ let $envSchema := $env/fots:schema,
+ $tcSchema := $case/fots:environment/fots:schema,
+ $schemas := ($envSchema, $tcSchema),
+ $modules := $case/fots:module,
+ $resources := ($env/fots:resource, $case/fots:environment/fots:schema)
+ return
+ if (empty($schemas) and empty($modules) and empty($resources)) then ()
+ else
+ string-join(("declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';",
+ $env:hof,
+ "declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {",
+ "switch($entity)",
+ if (exists($schemas)) then
+ string-join(("case 'schema'",
+ " return switch($namespace)",
+ (for $schema in $envSchema
+ return concat(" case '",
+ data($schema/@uri),
+ "' return doc('",
+ resolve-uri($schema/@file, $envBaseURI),
+ "')"),
+ for $schema in $tcSchema
+ return concat(" case '",
+ data($schema/@uri),
+ "' return doc('",
+ resolve-uri($schema/@file, $testSetBaseURI),
+ "')")),
+ " default return ()")
+ ,"
")
+ else (),
+ if (exists($modules)) then
+ string-join(("case 'module'",
+ " return switch($namespace)",
+ for $module in $modules
+ return concat(" case '",
+ data($module/@uri),
+ "' return fn:unparsed-text('",
+ resolve-uri($module/@file, $testSetBaseURI),
+ "') "),
+ " default return ()")
+ ,"
")
+ else (),
+ if (exists($resources)) then
+ string-join(("case ''",
+ " return switch($namespace)",
+ for $resource in $resources
+ return concat(" case '",
+ data($resource/@uri),
+ "' return fn:unparsed-text('",
+ resolve-uri($resource/@file, $envBaseURI),
+ "'",
+ if(exists($resource/@encoding)) then concat (",'", data($resource/@encoding),"'")
+ else (),
+ ") "),
+ " default return ()")
+ ,"
")
+ else ()
+ , "default return ()","};"),
+ "
")
+};
+
+(:~
+ : Check if an XQuery version declaration needs to be added.
+ :
+ : @param $deps the dependencies of the test set and test case.
+ : @param $test the Query test.
+ : @return if necessary the XQuery version declaration.
+ :)
+declare function env:add-xquery-30(
+ $deps as element(fots:dependency)*,
+ $test as xs:string
+) as xs:string? {
+ let $dependencies := string-join(distinct-values( for $dep in $deps
+ where $dep[@type="spec"]
+ return data($dep/@value)),"")
+ return
+ if ((contains($dependencies,"XQ30") or contains($dependencies,"XP30")) and
+ not(contains($test, "xquery version ")))
+ then "xquery version '3.0';"
+ else ()
+};
+
+(:~
+ : If there is a dependency on XQuery 3.0 and there is at least one HOF function in the test, return the strings for enabling the HOF feature.
+ :
+ : @param $deps the dependencies of the test set and test case
+ : @param $test the Query test.
+ : @return if necessary the strings for enabling the HOF feature
+ :)
+declare function env:enable-HOF-feature(
+ $deps as element(fots:dependency)*,
+ $test as xs:string
+) as xs:string? {
+ let $depSpec := string-join(distinct-values( for $dep in $deps
+ where $dep[@type="spec"]
+ return data($dep/@value)),""),
+ $depFeature := string-join(distinct-values( for $dep in $deps
+ where $dep[@type="feature"]
+ return data($dep/@value)),"")
+ return
+ if ((contains($depSpec,"XQ30") or contains($depSpec,"XP30")) and
+ contains($depFeature,"higherOrderFunctions"))
+ then $env:hof else ()
+};
+
+declare function env:check-dependencies(
+ $deps as element(fots:dependency)*,
+ $zorbaManifest
+) as xs:string* {
+ if(empty($deps)) then ()
+ else
+ for $dep in $deps
+ let $satisfied := if(exists($dep/@satisfied)) then data($dep/@satisfied) else "true"
+ let $zorbaDep := $zorbaManifest//fots:dependency[@type = $dep/@type and @value = $dep/@value and @satisfied = $satisfied]
+ return
+ if(empty($zorbaDep)) then concat("Dependency (type=", $dep/@type, ", value=", $dep/@value, ", satisfied=", $satisfied, ") was not met. ")
+ else ()
+};
+
+declare %private function env:set-properties(
+ $decimal-format as element(fots:decimal-format)
+) as xs:string* {
+ for $att in $decimal-format/attribute::*
+ let $name := node-name($att)
+ let $value := fn:data($att)
+ return
+ if(exists(index-of(("decimal-separator", "grouping-separator", "infinity",
+ "minus-sign", "NaN", "percent", "per-mille", "zero-digit",
+ "digit", "pattern-separator"),xs:string($name))))
+ then concat($name, '="' , $value, '"')
+ else ()
+};
+
+declare function env:decl-decimal-formats(
+ $decimal-formats as element(fots:decimal-format)*
+) as xs:string* {
+ if(empty($decimal-formats)) then ()
+ else
+ for $tmp in $decimal-formats
+ let $default := if(exists($tmp/@name)) then () else "default"
+ let $name := if(exists($tmp/@name)) then data($tmp/@name) else ()
+ return
+ string-join(("declare",
+ $default,
+ "decimal-format",
+ $name,
+ env:set-properties($tmp),
+ ";"),' ')
+};
=== added file 'test/fots_driver/errors.xq'
--- test/fots_driver/errors.xq 1970-01-01 00:00:00 +0000
+++ test/fots_driver/errors.xq 2012-11-12 20:35:24 +0000
@@ -0,0 +1,32 @@
+(:
+ : Copyright 2006-2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : Zorba FOTS driver errors
+ : @author Sorin Nasoi
+ :)
+
+module namespace err = "http://www.zorba-xquery.com/fots-driver/errors";
+
+(:~
+ : Errors namespace URI.
+:)
+declare variable $err:errNS as xs:string := "http://www.zorba-xquery.com/fots-driver/errors";
+
+(:~
+ : xs:QName with namespace URI="http://www.w3.org/2010/09/qt-fots-catalog/errors" and local name "err:errNA"
+:)
+declare variable $err:errNA as xs:QName := fn:QName($err:errNS, "check:errNA");
\ No newline at end of file
=== added file 'test/fots_driver/evaluate.xq'
--- test/fots_driver/evaluate.xq 1970-01-01 00:00:00 +0000
+++ test/fots_driver/evaluate.xq 2012-11-12 20:35:24 +0000
@@ -0,0 +1,415 @@
+(:
+ : Copyright 2006-2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : Zorba FOTS driver evaluate
+ : @author Sorin Nasoi
+ :)
+
+module namespace eval = "http://www.zorba-xquery.com/fots-driver/evaluate";
+
+import schema namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
+
+import module namespace xqxq = "http://www.zorba-xquery.com/modules/xqxq";
+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
+
+import module namespace fots-err = "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
+import module namespace util = "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
+
+declare namespace err = "http://www.w3.org/2005/xqt-errors";
+declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";
+
+declare namespace features = "http://www.zorba-xquery.com/options/features";
+declare option features:enable "hof";
+
+declare %ann:sequential function eval:result(
+ $result as item()*,
+ $expResult as element(),
+ $showResult as xs:boolean?
+) as element()? {
+ let $err := eval:check-assertion($result, $expResult, (), "", $showResult)
+ return if(empty($err)) then () else
+ <out>
+ <expected-result>{$expResult}</expected-result>
+ {
+ if($showResult) then <result>{$result}</result>
+ else ()
+ }
+ {
+ if($showResult) then <errors>{$err}</errors>
+ else ()
+ }
+ </out>
+};
+
+declare %ann:sequential function eval:error(
+ $result as item()*,
+ $expResult as element(),
+ $code as xs:QName?,
+ $errorDescription as xs:string?,
+ $showResult as xs:boolean?
+) as xs:string* {
+ if(empty($result)) then
+ let $err := eval:error-code($code,
+ $errorDescription,
+ $expResult)
+ return
+ if(empty($err)) then () else $err
+ else
+ concat("Expected error 
",
+ data($expResult/@code),
+ ",
 found result ",
+ if ($showResult) then string-join(util:serialize-result($result),' ')
+ else ())
+};
+
+declare %private %ann:sequential function eval:error-code(
+ $code as xs:QName?,
+ $errorDescription as xs:string?,
+ $expResult as element()
+) as xs:string* {
+ let $assertName := local-name($expResult)
+ return
+ if( $assertName = "error") then
+ if (exists($expResult[@code = "*"]) or
+ exists($expResult[@code = fn:local-name-from-QName($code)])) then ()
+ else
+ concat("Expected error: ", fn:data($expResult/@code),
+ ". Found error: ", fn:local-name-from-QName($code))
+ else if (($assertName = "any-of") or ($assertName = "all-of")) then
+ eval:check-assertion((), $expResult, $code, $errorDescription, fn:true())
+ else
+ concat("Expected result: 
", fn:data($expResult),
+ ".
 Found error ", fn:local-name-from-QName($code), " - ", $errorDescription)
+};
+declare %private %ann:sequential function eval:check-assertion(
+ $result as item()*,
+ $expResult as element(),
+ $code as xs:QName?,
+ $errorDescription as xs:string?,
+ $showResult as xs:boolean?
+) as xs:string* {
+ let $test := local-name($expResult)
+ return switch($test)
+ case 'all-of'
+ return eval:assert-all-of($result, $expResult, $code, $errorDescription, $showResult)
+ case 'any-of'
+ return eval:assert-any-of($result, $expResult, $code, $errorDescription, $showResult)
+ case 'assert'
+ return eval:assert($result, $expResult)
+ case 'assert-count'
+ return eval:assert-count($result, $expResult)
+ case 'assert-deep-eq'
+ return eval:assert-deep-eq($result, $expResult)
+ case 'assert-empty'
+ return eval:assert-empty($result)
+ case 'assert-eq'
+ return eval:assert-eq($result, $expResult)
+ case 'assert-false'
+ return eval:assert-false($result)
+ case 'assert-permutation'
+ return eval:assert-permutation($result, $expResult)
+ case 'assert-xml'
+ return eval:assert-xml($result, $expResult)
+ case 'assert-serialization-error'
+ return eval:assert-serialization-error($result, $expResult)
+ case 'assert-string-value'
+ return eval:assert-string-value($result, $expResult)
+ case 'assert-true'
+ return eval:assert-true($result)
+ case 'assert-type'
+ return eval:assert-type($result, $expResult)
+ case 'serialization-matches'
+ return eval:serialization-matches($result, $expResult)
+ case 'error'
+ return eval:error($result, $expResult, $code, $errorDescription, $showResult)
+ default return fn:error($fots-err:errNA, "
The requested assertion type is not implemented.")
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_any-of :)
+declare %private %ann:sequential function eval:assert-any-of(
+ $result as item()*,
+ $expResult as element(),
+ $code as xs:QName?,
+ $errorDescription as xs:string?,
+ $showResult as xs:boolean
+) as xs:string? {
+ let $emptyResults := for $tmp in $expResult/*
+ return empty(eval:check-assertion($result, $tmp, $code, $errorDescription, $showResult)),
+ $results := for $tmp in $expResult/*
+ return eval:check-assertion($result, $tmp, $code, $errorDescription, $showResult)
+ return
+ if (some $result in $emptyResults satisfies $result)
+ then ()
+ else concat("
Assert-any-of returned: ", string-join(util:serialize-result($results),' '))
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_all-of :)
+declare %private %ann:sequential function eval:assert-all-of(
+ $result as item()*,
+ $expResult as element(),
+ $code as xs:QName?,
+ $errorDescription as xs:string?,
+ $showResult as xs:boolean
+) as xs:string* {
+ for $tmp in $expResult/*
+ return eval:check-assertion($result, $tmp, $code, $errorDescription, $showResult)
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert :)
+declare %private %ann:sequential function eval:assert(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ try {
+ {
+ variable $queryText := concat(
+ "xquery version '3.0';",
+ "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
+ "declare option o:enable 'hof';",
+ "declare variable $result external; ",
+ xs:string($expResult)),
+ $queryKey := xqxq:prepare-main-module($queryText),
+ $queryKeyResult := xqxq:bind-variable($queryKey, xs:QName('result'), $result),
+ $queryResult := xqxq:evaluate($queryKey);
+ if($queryResult) then ()
+ else concat("Assertion ", $expResult, " failed")
+ }
+ } catch * {
+ concat("
Assertion '",
+ $expResult,
+ "'
 failed with error ",
+ $err:code, " : ", $err:description)
+ }
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-count :)
+declare %private function eval:assert-count(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ if(count($result) eq xs:integer($expResult)) then ()
+ else "The number of items found is different than the expected number of items."
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-deep-eq :)
+declare %private %ann:sequential function eval:assert-deep-eq(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ try {
+ {
+ variable $queryText := concat(
+ "xquery version '3.0';",
+ "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
+ "declare option o:enable 'hof';",
+ "declare variable $x external;",
+ "let $y := (",fn:string(fn:data($expResult)),") return ",
+ "every $i in 1 to max((count($x),count($y))) satisfies deep-equal($x[$i],$y[$i])"),
+ $queryKey := xqxq:prepare-main-module($queryText),
+ $queryKeyResult := xqxq:bind-variable($queryKey, xs:QName('x'), $result),
+ $queryResult := xqxq:evaluate($queryKey);
+ if($queryResult) then ()
+ else concat("
Result is not deep-equal to '", $expResult, "'
")
+ }
+ } catch * {
+ concat("
Assert-deep-eq '", $expResult, "'
 failed with error ",
+ $err:code, " : ", $err:description)
+ }
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-empty :)
+declare %private function eval:assert-empty(
+ $result as item()*
+) as xs:string? {
+ if(empty($result)) then ()
+ else "
Result is not empty as expected"
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-eq :)
+declare %private %ann:sequential function eval:assert-eq(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ try {
+ {
+ variable $type := if (empty($result[1]) or (count($result) gt 1)) then ()
+ else
+ let $tmp := xs:string(schema:schema-type($result[1]))
+ (: add exception for the types defined in schemas available in the environment of the tests :)
+ return
+ if (starts-with($tmp, 'xs:')) then $tmp else ();
+ variable $queryText := concat(
+ "declare variable $x external;",
+ "$x eq ",
+ if (starts-with(data($expResult), $type)) then data($expResult)
+ else concat($type,"(", data($expResult), ")"));
+ variable $queryKey := xqxq:prepare-main-module($queryText);
+ xqxq:bind-variable($queryKey, xs:QName('x'), $result);
+ variable $queryResult := xqxq:evaluate($queryKey);
+ if($queryResult) then ()
+ else concat("
Assert-eq: Result '", string-join(util:serialize-result($result),' '),
+ "' 
doesn't match expected item '", xs:string($expResult), "'.")
+ }
+} catch * {
+ concat("
Comparison to '", $expResult/text(), "' failed with error: ",
+ $err:code ," : ", $err:description)
+ }
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-true :)
+declare %private function eval:assert-true(
+ $result as item()*
+) as xs:string? {
+ if($result eq fn:true()) then ()
+ else "
Query doesn't evaluate to true."
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-false :)
+declare %private function eval:assert-false(
+ $result as item()*
+) as xs:string? {
+ if($result eq fn:false()) then ()
+ else "
Query doesn't evaluate to false."
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-permutation :)
+declare %private %ann:sequential function eval:assert-permutation(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ try {
+ {
+ variable $queryText := concat(
+ "xquery version '3.0';",
+ "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
+ "declare option o:enable 'hof';",
+ "declare variable $x external;",
+ "let $y := (",fn:string(fn:data($expResult)),") return ",
+ (: if count(intersection(M1,M2)) = count(union(M1,M2)) = count(M1) then the sequences are identical :)
+ "(count(distinct-values($x[ . = $y])) = count(fn:distinct-values(($x, $y)))) = count(fn:distinct-values($x))"),
+ $queryKey := xqxq:prepare-main-module($queryText),
+ $queryKeyResult := xqxq:bind-variable($queryKey, xs:QName('x'), $result),
+ $queryResult := xqxq:evaluate($queryKey);
+ if($queryResult) then ()
+ else concat("
Result isn't a permutation of '", $expResult, "'
")
+ }
+ } catch * {
+ concat("
Assert-permutation failed with error: ",
+ $err:code ," : ", $err:description)
+ }
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-xml :)
+declare %private function eval:assert-xml(
+ $result as item()*,
+ $expResult as element()
+) {
+(:TODO call xml-canonicalization after bug #1076919 is implemented.:)
+ try {
+ let $serRes := util:serialize-result($result),
+ $result1 as xs:string := string-join($serRes,''),
+ $result2 as xs:string := string-join($serRes,' ')
+ return
+ (:if(document{$serializedResult} eq document{string($expResult)}):)
+ if((normalize-space($result1) eq normalize-space(string($expResult))) or
+ (normalize-space($result2) eq normalize-space(string($expResult))))
+ then ()
+ else concat("
Result '", $result1 ,"'
 is different from the expected result 
'", string($expResult),"'.")
+ } catch * {
+ concat("
Assert-xml failed with error:",
+ $err:code, " : ", $err:description)
+ }
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-serialization-error :)
+declare %private %ann:sequential function eval:assert-serialization-error(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ try {
+ let $serializedResult as xs:string := string-join(util:serialize-result($result),'')
+ return
+ fn:concat("
Expected serialization error but got result: ", $serializedResult)
+ } catch * {
+ eval:error((),
+ $expResult,
+ $err:code,
+ $err:description,
+ fn:true())
+ }
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_serialization-matches :)
+declare %private function eval:serialization-matches(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ let $serResult := string-join(util:serialize-result($result, $util:serParamXml), ''),
+ $serExpResult := string-join(util:serialize-result(data($expResult), $util:serParamXml), '')
+ let $matchesFlags := data($expResult/@flags)
+ return
+ if(exists($matchesFlags)) then
+ if(matches($serResult, $serExpResult, $matchesFlags)) then ()
+ else fn:concat("
Expected '", $serResult, "'
 does not match 
'", $serExpResult, "' with flags '", $matchesFlags, "'")
+ else
+ if(matches($serResult, $serExpResult)) then ()
+ else fn:concat("
Expected ", $serResult, "'
 does not match 
'", $serExpResult, "'")
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-string-value :)
+declare %private function eval:assert-string-value(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ try {
+ let $serRes := string-join(util:serialize-result($result),' '),
+ $res := if (empty($expResult[@normalize-space="true"]))
+ then $serRes
+ else fn:normalize-space($serRes),
+ $expRes := if (empty($expResult[@normalize-space="true"]))
+ then xs:string($expResult)
+ else fn:normalize-space(xs:string($expResult))
+ return if($res eq $expRes) then ()
+ else fn:concat("
Expected '", $expRes, "'
 found 
'", $res, "'")
+ } catch * {
+ fn:concat("
String-value failed with error: ",
+ $err:code, " : ", $err:description)
+ }
+};
+
+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-type :)
+declare %private %ann:sequential function eval:assert-type(
+ $result as item()*,
+ $expResult as element()
+) as xs:string? {
+ try {
+ {
+ variable $queryText := concat( "declare variable $x external; $x instance of ",fn:data($expResult)),
+ $queryKey := xqxq:prepare-main-module($queryText),
+ $queryKeyResult := xqxq:bind-variable($queryKey, xs:QName('x'), $result),
+ $queryResult := xqxq:evaluate($queryKey);
+ if($queryResult) then ()
+ else concat("
Result doesn't have type '", fn:data($expResult), "'")
+ }
+ } catch * {
+ fn:concat("
Assert-type failed with error: ",
+ $err:code, " : ", $err:description)
+ }
+};
+
=== added file 'test/fots_driver/fots-driver.xq'
--- test/fots_driver/fots-driver.xq 1970-01-01 00:00:00 +0000
+++ test/fots_driver/fots-driver.xq 2012-11-12 20:35:24 +0000
@@ -0,0 +1,608 @@
+(:
+ : Copyright 2006-2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : Zorba FOTS driver
+ : @author Sorin Nasoi
+ :)
+
+module namespace driver = "http://www.zorba-xquery.com/fots-driver";
+
+import module namespace functx = "http://www.functx.com/";
+
+import module namespace xqxq = "http://www.zorba-xquery.com/modules/xqxq";
+import module namespace datetime = "http://www.zorba-xquery.com/modules/datetime";
+
+import module namespace eval = "http://www.zorba-xquery.com/fots-driver/evaluate" at "evaluate.xq";
+import module namespace env = "http://www.zorba-xquery.com/fots-driver/environment" at "environment.xq";
+import module namespace util = "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
+import module namespace fots-err = "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
+
+declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
+
+declare namespace err = "http://www.w3.org/2005/xqt-errors";
+declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";
+
+(:~
+ : Loops through the FOTS catalog and returns all available test set names.
+ : @param $fotsPath path to the FOTS catalog file.
+ : @param $testSetPrefixes name/criteria for the test sets (empty string means all).
+ : @return available FOTS test sets.
+ :)
+declare %ann:nondeterministic function driver:list-test-sets(
+ $fotsPath as xs:string,
+ $testSetPrefixes as xs:string*
+) as xs:string* {
+ let $doc := doc(resolve-uri($fotsPath))
+ return
+ if(string-join($testSetPrefixes,'') = '') then
+ for $testSet in $doc/fots:catalog/fots:test-set
+ return data($testSet/@name)
+ else
+ for $prefix in $testSetPrefixes
+ for $testSet in $doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)]
+ return data($testSet/@name)
+};
+
+(:~
+ : Loops through the given test sets and returns the corresponding test cases.
+ : @param $fotsPath path to the FOTS catalog file.
+ : @param $testSetPrefixes name/criteria for the test sets (empty string means all).
+ : @return available FOTS test cases.
+ :)
+declare %ann:nondeterministic function driver:list-test-cases(
+ $fotsPath as xs:string,
+ $testSetPrefixes as xs:string*
+) as xs:string* {
+ let $doc := doc(resolve-uri($fotsPath)),
+ $baseUri:= resolve-uri(util:parent-folder($fotsPath))
+ return
+ if(string-join($testSetPrefixes,'') = '') then
+ for $testSet in $doc/fots:catalog/fots:test-set
+ let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
+ return fn:data($testSetDoc//fots:test-case/@name)
+ else
+ for $prefix in $testSetPrefixes
+ for $testSet in $doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)]
+ let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
+ return fn:data($testSetDoc//fots:test-case/@name)
+};
+
+(:~
+ : Loops through all the test cases and returns those that have a 'test' node that matches given pattern using given flags.
+ : @param $fotsPath path to the FOTS catalog file.
+ : @param $pattern pattern.
+ : @param $flags flags.
+ : @return available FOTS test cases matching given pattern and flags.
+ :)
+declare %ann:nondeterministic function driver:list-matching-test-cases(
+ $fotsPath as xs:string,
+ $pattern as xs:string,
+ $flags as xs:string?
+) as xs:string* {
+ let $doc := doc(resolve-uri($fotsPath)),
+ $baseUri:= resolve-uri(util:parent-folder($fotsPath))
+ return
+ for $testSet in $doc/fots:catalog/fots:test-set
+ let $uri := resolve-uri($testSet/@file, $baseUri),
+ $testSetDoc := doc($uri)
+ for $testCase in $testSetDoc//test-case
+ where fn:matches(util:get-value($testCase,
+ util:parent-folder($uri),
+ "test"),
+ $pattern,
+ $flags)
+ return
+ fn:concat(resolve-uri($testSet/@file, $baseUri),
+ ", test name:", fn:data($testCase/@name))
+};
+
+(:~
+ : Loops through the FOTS catalog and evaluates all test cases.
+ : @param $path path to the FOTS catalog file.
+ : @param $FOTSZorbaManifest the file that describes optional features and implementation defined items in Zorba.
+ : @return the failed test cases.
+ :)
+ (:
+declare %ann:sequential function driver:run-fots(
+ $fotsPath as xs:string,
+ $FOTSZorbaManifest as document-node()
+) as element(fots:test-case) {
+ driver:run-fots($fotsPath, $FOTSZorbaManifest, '', '','','','', fn:false(), fn:false())
+};
+:)
+(:~
+ : Loops through the FOTS catalog and evaluates all test cases.
+ : @param $fotsPath path to the FOTS catalog file.
+ : @param $FOTSZorbaManifest the file that describes optional features and implementation defined items in Zorba.
+ : @param $testSetPrefixes name/criteria for the test sets (empty string means all).
+ : @param $testCasePrefixes name/criteria for the test cases (empty string means all).
+ : @return the failed test cases.
+ :)
+ (:
+declare %ann:sequential function driver:run-fots(
+ $fotsPath as xs:string,
+ $FOTSZorbaManifest as document-node(),
+ $exceptedTestCases as xs:string*,
+ $exceptedTestSets as xs:string*
+) as element(fots:FOTS-test-suite-result) {
+ driver:run-fots($fotsPath,
+ $FOTSZorbaManifest,
+ '',
+ '',
+ $exceptedTestCases,
+ $exceptedTestSets,
+ '',
+ fn:false(),
+ fn:false())
+};
+:)
+
+declare %private function driver:list-assertions(
+ $case as element(fots:test-case)
+) as xs:string* {
+ fn:distinct-values(for $assert in $case/result/descendant-or-self::*
+ return fn:local-name-from-QName(fn:node-name($assert)))
+};
+
+(:~
+ : Loops through the FOTS catalog and evaluates all test cases that have a certain assert-type.
+ : This is useful for testing the implementation of a certain assert type.
+ : @param $FOTSCatalogFilePath path to the FOTS catalog file.
+ : @param $FOTSZorbaManifestPath the path to the file that describes optional features and implementation defined items in Zorba.
+ : @param $testSetPrefixes name/criteria for the test sets (empty string means all).
+ : @param $testCasePrefixes name/criteria for the test cases (empty string means all).
+ : @param $exceptedTestCases lists of test cases that should not be run(empty string means all tests will be run).
+ : @param $exceptedTestSets lists of test sets that should not be run(empty string means all tests will be run).
+ : @param $assert lists of tests that contain a certain assert-type(empty string means all tests will be run).
+ : @param $verbose if set to TRUE it will also output the actual failures.
+ : @param $showResult if set to TRUE it will also show the actual result of the Query run.
+ : @return an element containing all failed tests
+ :)
+declare %ann:sequential function driver:run-fots(
+ $FOTSCatalogFilePath as xs:string,
+ $FOTSZorbaManifestPath as xs:string,
+ $testSetPrefixes as xs:string*,
+ $testCasePrefixes as xs:string*,
+ $exceptedTestCases as xs:string*,
+ $exceptedTestSets as xs:string*,
+ $assert as xs:string*,
+ $verbose as xs:boolean,
+ $showResult as xs:boolean
+) as element(fots:test-cases) {
+ try {
+ let $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
+ "The path to FOTS catalog.xml was set to: ")),
+ $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
+ "The path to FOTSZorbaManifest was set to:"))
+ return driver:run($FOTSCatalog,
+ resolve-uri(util:parent-folder($FOTSCatalogFilePath)),
+ $FOTSZorbaManifest,
+ $testSetPrefixes,
+ $testCasePrefixes,
+ $exceptedTestCases,
+ $exceptedTestSets,
+ trace($assert, "The filter for 'assert name' was set to: "),
+ trace($verbose, "'Verbose' parameter was set to: "),
+ $showResult)
+ }
+ catch *
+ {
+ fn:error($err:code,
+ concat("
Please make sure the passed 'fotsPath' points to the exact location of the FOTS catalog.xml:
",
+ resolve-uri($FOTSCatalogFilePath),
+ "
and that the passed 'fotsZorbaManifestPath' points to a file in the same folder as cli.xq:
",
+ resolve-uri($FOTSZorbaManifestPath)))
+ }
+};
+
+(:~
+ : Loops through the FOTS catalog and evaluates all test cases that have a certain assert-type.
+ : This is useful for testing the implementation of a certain assert type.
+ : @param $FOTSCatalog the FOTS catalog.xml file.
+ : @param $FOTSZorbaManifest the file that describes optional features and implementation defined items in Zorba.
+ : @param $testSetPrefixes name/criteria for the test sets (empty string means all).
+ : @param $testCasePrefixes name/criteria for the test cases (empty string means all).
+ : @param $exceptedTestCases lists of test cases that should not be run(empty string means all tests will be run).
+ : @param $exceptedTestSets lists of test sets that should not be run(empty string means all tests will be run).
+ : @param $assert lists of tests that contain a certain assert-type(empty string means all tests will be run).
+ : @param $verbose if set to TRUE it will also output the actual failures.
+ : @param $showResult if set to TRUE it will also show the actual result of the Query run.
+ : @return an element containing all failed tests
+ :)
+declare %ann:sequential function driver:run(
+ $FOTSCatalog as document-node(),
+ $catalogBaseURI as xs:anyURI,
+ $FOTSZorbaManifest as document-node(),
+ $testSetPrefixes as xs:string*,
+ $testCasePrefixes as xs:string*,
+ $exceptedTestCases as xs:string*,
+ $exceptedTestSets as xs:string*,
+ $assert as xs:string*,
+ $verbose as xs:boolean,
+ $showResult as xs:boolean
+) as element(fots:test-cases) {
+ <test-cases>{
+ let $catalogTestSetNames := $FOTSCatalog//fots:test-set/@name,
+ $testSetNames := if ($testSetPrefixes = '') then functx:value-except($catalogTestSetNames, $exceptedTestSets)
+ else functx:value-except(functx:value-intersect($testSetPrefixes, $catalogTestSetNames), $exceptedTestSets)
+ for $testSetName in $testSetNames
+ let $testSet := $FOTSCatalog//fots:test-set[@name=$testSetName],
+ $testSetURI := resolve-uri($testSet/@file, $catalogBaseURI),
+ $testSetDoc := doc($testSetURI),
+ $depMet as xs:string*:= env:check-dependencies($testSetDoc/fots:test-set/fots:dependency, $FOTSZorbaManifest)
+ return
+ if(exists($depMet))
+ then <test-set name="{$testSetName}">
+ {
+ for $testCase in $testSetDoc/fots:test-set/fots:test-case
+ let $envName := fn:data($testCase/fots:environment/@ref),
+ $envTestSet := $testSetDoc/fots:test-set/fots:environment[@name = $envName],
+ $envCatalog := $FOTSCatalog/fots:catalog/fots:environment[@name = $envName],
+ $shouldRun := if ($testCasePrefixes = '') then functx:value-except(xs:string(fn:data($testCase/@name)), $exceptedTestCases)
+ else functx:value-except(functx:value-intersect(fn:data($testCase/@name), $testCasePrefixes), $exceptedTestCases),
+ (:true if the tests-case has an assertion type that is requested :)
+ $hasReqAssert := (($assert = '') or
+ fn:exists(functx:value-intersect(driver:list-assertions($testCase),$assert)))
+ where $shouldRun and $hasReqAssert
+ return
+ driver:not-applicable($testCase, $envTestSet, string-join($depMet,''), $verbose)
+ }</test-set>
+ else <test-set name="{$testSetName}">
+ {
+ for $testCase in $testSetDoc/fots:test-set/fots:test-case
+ let $envName := fn:data($testCase/fots:environment/@ref),
+ $envTestSet := $testSetDoc/fots:test-set/fots:environment[@name = $envName],
+ $envCatalog := $FOTSCatalog/fots:catalog/fots:environment[@name = $envName],
+ $shouldRun := if ($testCasePrefixes = '') then functx:value-except(xs:string(fn:data($testCase/@name)), $exceptedTestCases)
+ else functx:value-except(functx:value-intersect(fn:data($testCase/@name), $testCasePrefixes), $exceptedTestCases),
+ (:true if the tests-case has an assertion type that is requested :)
+ $hasReqAssert := (($assert = '') or
+ fn:exists(functx:value-intersect(driver:list-assertions($testCase),$assert)))
+ where $shouldRun and $hasReqAssert
+ return
+ if(exists(env:check-dependencies($testCase/fots:dependency, $FOTSZorbaManifest)))
+ then driver:not-applicable( $testCase,
+ $envTestSet,
+ string-join(distinct-values(env:check-dependencies($testCase/fots:dependency, $FOTSZorbaManifest)),''),
+ $verbose)
+ else if(fn:empty($envTestSet))
+ then driver:test( $FOTSZorbaManifest,
+ $testCase,
+ $envCatalog,
+ $catalogBaseURI,
+ ($testCase/fots:dependency, $testSetDoc/fots:test-set/fots:dependency),
+ $testSetName,
+ $testSetURI,
+ $verbose,
+ $showResult)
+ else driver:test( $FOTSZorbaManifest,
+ $testCase,
+ $envTestSet,
+ $testSetURI,
+ ($testCase/fots:dependency, $testSetDoc/fots:test-set/fots:dependency),
+ $testSetName,
+ $testSetURI,
+ $verbose,
+ $showResult)
+ }</test-set>
+ }</test-cases>
+};
+
+(:~
+ : Creates the complete query that will be evaluated by adding the necessary XQXQ URL resolvers.
+ : @param $queryText the test-case/test after all the additional prolog statements were added.
+ : @param $case the test case.
+ : @param $env the environment.
+ : @param $envBaseURI URI of the environment.
+ : @param $testSetBaseURI URI of the test set that defines the test case.
+ : @return the query that will be evaluated.
+ :)
+declare %private function driver:create-XQXQ-query(
+ $queryText as xs:string,
+ $case as element(fots:test-case),
+ $env as element(fots:environment)?,
+ $envBaseURI as xs:anyURI?,
+ $testSetBaseURI as xs:anyURI
+) as xs:string {
+ let $resolver as xs:string? := env:resolver($case, $env, $envBaseURI, $testSetBaseURI) return
+ string-join(( "import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';",
+ if (exists($resolver)) then $resolver else (),
+ (concat("variable $queryID := xqxq:prepare-main-module('", "
", fn:replace($queryText,"'","''"), "'", "
",
+ if (exists($resolver))
+ then ", resolver:url-resolver#2, ());"
+ else ");")),
+ env:set-context-item($env, $envBaseURI),
+ env:set-context-item($case/fots:environment, $testSetBaseURI),
+ env:set-variables($env, $envBaseURI),
+ env:set-variables($case/environment, $testSetBaseURI),
+ "xqxq:evaluate($queryID)"
+ ),
+ "
")
+};
+
+(:~
+ : XQXQ invoke.
+ : @param $xqxqQueryText the query that will be run.
+ : @param $case the test case.
+ : @return the result of running the query with XQXQ.
+ :)
+declare %private %ann:sequential function driver:xqxq-invoke(
+ $xqxqQueryText as xs:string,
+ $case as element(fots:test-case),
+ $showResult as xs:boolean?,
+ $testSetBaseURI as xs:anyURI
+) {
+ try {
+ {
+ variable $queryKey := xqxq:prepare-main-module($xqxqQueryText);
+ variable $queryResult := xqxq:evaluate-sequential($queryKey);
+ (:variable $expResult := util:get-value($case, $testSetBaseURI, "result");:)
+ eval:result($queryResult,
+ $case/fots:result/*,
+ $showResult)
+ }
+ } catch * {
+ eval:error((),
+ $case/fots:result/*,
+ $err:code,
+ $err:description,
+ $showResult)
+ }
+};
+
+(:~
+ : Runs a single test case.
+ :
+ : @param $FOTSZorbaManifest the file that describes optional features and implementation defined items in Zorba.
+ : @param $case test case.
+ : @param $env the environment.
+ : @param $envBaseURI the relative URI used to calculate the full URI for the different children of the environment that have a "file" attribute.
+ : @param $deps the dependencies that should be checked for given test case.
+ : @param $testSetName the name of the test set.
+ : @param $testSetBaseURI the URI of the test set.
+ : @param $verbose xs:boolean indicating if a result should be returned in case of success or not.
+ : @return the result of running the test case depending on $verbose.
+ :)
+declare %ann:sequential function driver:test(
+ $FOTSZorbaManifest as document-node(),
+ $case as element(fots:test-case),
+ $env as element(fots:environment)?,
+ $envBaseURI as xs:anyURI?,
+ $deps as element(fots:dependency)*,
+ $testSetName as xs:string?,
+ $testSetBaseURI as xs:anyURI,
+ $verbose as xs:boolean,
+ $showResult as xs:boolean?
+) as element(fots:test-case)? {
+(:TODO If the test expression includes the string "(:%VARDECL%:)"
+ then the variable declaration should be added to replace this string;
+ if it does not include this string, the variable declaration can be added at the start.
+ For the moment the declarations are added at the start because there are no tests that use VARDECL:)
+ try {
+ {
+ variable $queryName := trace(fn:data($case/@name),"processing test case :"),
+ $depMet := env:check-dependencies($deps, $FOTSZorbaManifest);
+
+ if(exists($depMet))
+ then driver:not-applicable($case, $env, string-join($depMet,''), $verbose)
+ else
+ {
+ variable $test := util:get-value($case, $testSetBaseURI, "test");
+ variable $enableHOF := env:enable-HOF-feature(($deps, $case//fots:dependency), $test);
+ variable $query as xs:string := fn:string-join(
+ (env:add-xquery-30(($deps, $case//fots:dependency), $test),
+ env:decl-def-elem-namespace($env, $case/fots:environment),
+ env:decl-base-uri($env, $case/fots:environment),
+ env:decl-namespaces($env, $case, $testSetBaseURI),
+ $enableHOF,
+ env:decl-decimal-formats(($env/fots:decimal-format, $case/fots:environment/fots:decimal-format)),
+ env:add-var-decl($env, $case),
+ $test
+ ),"
"),
+ $xqxqQuery as xs:string := driver:create-XQXQ-query($query,
+ $case,
+ $env,
+ $envBaseURI,
+ $testSetBaseURI),
+ $startDateTime := datetime:current-dateTime (),
+ $result := driver:xqxq-invoke($xqxqQuery,
+ $case,
+ $showResult,
+ $testSetBaseURI),
+ $duration := (datetime:current-dateTime () - $startDateTime);
+
+ if(empty($result)) then
+ driver:pass($case, $result, $xqxqQuery, $env, (), $duration, $verbose)
+ (: if the exact error code was not found, report the test as 'Pass' with an attribute correctError=false :)
+ else if(exists($result) and
+ contains(string-join($result,''), "Expected error:") and
+ contains(string-join($result,''), "Found error:"))
+ then driver:pass($case, $result, $xqxqQuery, $env, $result, $duration, $verbose)
+ else
+ driver:fail($case, $result, $xqxqQuery, $testSetName, $env, $duration, $verbose)
+ }
+ }
+ } catch * {
+ driver:fail($case,
+ <result>{$err:description}</result>,
+ "",
+ $testSetName,
+ $env,
+ xs:dayTimeDuration("PT0S"),
+ $verbose)
+ }
+};
+
+(:~
+ : Gives feedback on a test case that is not run because dependencies are not met.
+ :
+ : @param $case test case.
+ : @param $dependencyError test error returned by the dependency checking.
+ : @return the test case.
+ :)
+declare %private %ann:sequential function driver:not-applicable(
+ $case as element(fots:test-case),
+ $env as element(fots:environment)?,
+ $dependencyError as xs:string,
+ $verbose as xs:boolean
+) as element(fots:test-case)? {
+ trace(fn:data($case/@name), "processing test case :");
+ trace($dependencyError, "Dependency error :");
+ if($verbose) then
+ {
+ let $tmp := $case
+ return {
+ insert node
+ attribute result{'not applicable'}
+ as last into $tmp;
+
+ insert node
+ attribute comment{$dependencyError}
+ as last into $tmp;
+
+ insert node
+ <info>
+ { $env }
+ </info>
+ as last into $tmp;
+
+ delete node $tmp/description;
+ delete node $tmp/created;
+
+ $tmp
+ }
+ }
+ else
+ <test-case name="{data($case/@name)}"
+ result="not applicable"
+ comment="{$dependencyError}" />
+};
+
+(:~
+ : Gives feedback on a test case run with success.
+ :
+ : @param $case test case.
+ : @return the test case after certain information was added.
+ :)
+declare %private %ann:sequential function driver:pass(
+ $case as element(fots:test-case),
+ $result as item()*,
+ $zorbaQuery as xs:string,
+ $env as element(fots:environment)?,
+ $comment as xs:string?,
+ $duration as xs:dayTimeDuration,
+ $verbose as xs:boolean
+) as element(fots:test-case)? {
+ if($verbose) then
+ {
+ let $tmp := $case
+ return {
+ insert node
+ attribute result{'pass'}
+ as last into $tmp;
+
+ if(exists($comment)) then
+ insert node
+ attribute correctError{'false'}
+ as last into $tmp;
+ else ();
+
+ if(exists($comment)) then
+ insert node
+ attribute comment{$comment}
+ as last into $tmp;
+ else ();
+
+ insert node
+ attribute executionTime{$duration}
+ as last into $tmp;
+
+ insert node
+ <info>
+ { $env }
+ <query>{ $zorbaQuery }</query>
+ {$result}
+ </info>
+ as last into $tmp;
+
+ delete node $tmp/description;
+ delete node $tmp/created;
+
+ $tmp
+ }
+ }
+ else if(empty($comment)) then
+ <test-case name="{data($case/@name)}"
+ result="pass"
+ executionTime="{$duration}" />
+ else
+ <test-case name="{data($case/@name)}"
+ result="pass"
+ correctError="{empty($comment)}"
+ executionTime="{$duration}" />
+};
+
+(:~
+ : Gives feedback on a test case run without success.
+ :
+ : @param $case test case.
+ : @return the test case after certain information was added.
+ :)
+declare %private %ann:sequential function driver:fail(
+ $case as element(fots:test-case),
+ $result as item()*,
+ $zorbaQuery as xs:string,
+ $testSetName as xs:string?,
+ $env as element(fots:environment)?,
+ $duration as xs:dayTimeDuration,
+ $verbose as xs:boolean
+) as element(fots:test-case)? {
+ trace($testSetName, "test set name");
+ trace("above test case failed", "result");
+ if($verbose) then
+ {
+ let $tmp := $case
+ return {
+ insert node
+ attribute result{'fail'}
+ as last into $tmp;
+
+ insert node
+ attribute executionTime{$duration}
+ as last into $tmp;
+
+ insert node
+ <info>
+ { $env }
+ <query>{ $zorbaQuery }</query>
+ {$result}
+ </info>
+ as last into $tmp;
+
+ delete node $tmp/description;
+ delete node $tmp/created;
+
+ $tmp
+ }
+ }
+ else
+ <test-case name="{data($case/@name)}"
+ result="fail"
+ executionTime="{$duration}"/>
+};
=== added file 'test/fots_driver/reporting.xq'
--- test/fots_driver/reporting.xq 1970-01-01 00:00:00 +0000
+++ test/fots_driver/reporting.xq 2012-11-12 20:35:24 +0000
@@ -0,0 +1,212 @@
+(:
+ : Copyright 2006-2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : Zorba FOTS driver reporting
+ : @author Sorin Nasoi
+ :)
+
+module namespace reporting = "http://www.zorba-xquery.com/fots-driver/reporting";
+
+import module namespace file = "http://expath.org/ns/file";
+
+import module namespace driver = "http://www.zorba-xquery.com/fots-driver" at "fots-driver.xq";
+import module namespace util = "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
+import module namespace fots-err = "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
+
+declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
+
+declare namespace err ="http://www.w3.org/2005/xqt-errors";
+declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";
+
+(:~
+ : Loops through the test-sets, runs then and creates statistics.
+ : @param $FOTSCatalogFilePath path to the FOTS catalog file.
+ : @param $FOTSZorbaManifestPath path to the FOTS Zorba manifest file.
+ : @param $testSetPrefixes name/criteria for the test sets (empty string means all).
+ : @param $testCasePrefixes name/criteria for the test cases (empty string means all).
+ : @param $exceptedTestCases lists of test cases that are not run(empty string means all tests will be run).
+ : @param $exceptedTestSets lists of test sets that are not run(empty string means all tests will be run).
+ : @param $verbose if set to TRUE it will also output the actual failures.
+ : @param $showResult if set to TRUE it will also show the actual result of the Query run.
+ : @return a report of tests run.
+ :)
+declare %ann:sequential function reporting:run-and-report(
+ $FOTSCatalogFilePath as xs:string,
+ $FOTSZorbaManifestPath as xs:string,
+ $testSetPrefixes as xs:string*,
+ $testCasePrefixes as xs:string*,
+ $exceptedTestCases as xs:string*,
+ $exceptedTestSets as xs:string*,
+ $assert as xs:string*,
+ $verbose as xs:boolean,
+ $showResult as xs:boolean
+) {
+ try {
+ {
+ variable $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
+ "The path to FOTS catalog.xml was set to: "));
+
+ variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
+
+ variable $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
+ "The path to FOTSZorbaManifest was set to:"));
+
+ variable $failures := <fots:FOTS-test-suite-result>{
+ ( $FOTSZorbaManifest//fots:implementation,
+ $FOTSZorbaManifest//fots:dependencies-satisfied,
+ driver:run($FOTSCatalog,
+ $catalogBaseURI,
+ $FOTSZorbaManifest,
+ $testSetPrefixes,
+ $testCasePrefixes,
+ $exceptedTestCases,
+ $exceptedTestSets,
+ $assert,
+ $verbose,
+ $showResult)
+ )
+ }</fots:FOTS-test-suite-result>;
+
+ file:write("failures.xml", $failures, $util:writeXML);
+
+ reporting:do-reporting($FOTSCatalog, $catalogBaseURI, $failures, $exceptedTestCases, $exceptedTestSets, $verbose)
+ }
+ }
+ catch *
+ {
+ fn:error($err:code,$err:description (:
+ concat("
Please make sure the passed 'fotsPath' points to the exact location of the FOTS catalog.xml:
",
+ resolve-uri($FOTSCatalogFilePath),
+ "
and that the passed 'fotsZorbaManifestPath' points to a file in the same folder as cli.xq:
",
+ resolve-uri($FOTSZorbaManifestPath)):))
+ }
+};
+
+(:~
+ : Loops through the test cases report and creates statistics.
+ : @param $pathFOTSCatalog path to the FOTS catalog file.
+ : @param $pathFailures path to the FOTS failures.
+ : @param $exceptedTestCases lists of test cases that are not run(empty string means all tests will be run).
+ : @param $exceptedTestSets lists of test sets that are not run(empty string means all tests will be run).
+ : @param $verbose if set to TRUE it will also output the actual failures.
+ : @param $showResult if set to TRUE it will also show the actual result of the Query run..
+ : @return a report of tests run.
+ :)
+declare %ann:nondeterministic function reporting:report(
+ $FOTSCatalogFilePath as xs:string,
+ $pathFailures as xs:string,
+ $exceptedTestCases as xs:string*,
+ $exceptedTestSets as xs:string*,
+ $verbose as xs:boolean
+) as element(fots:report) {
+ try {
+ {
+ if(not(file:is-file($pathFailures))) then
+ {
+ fn:error($fots-err:errNA, "The file failures file was not found. Suggestion: use driver:run-fots to generate it or use reporting:run-and-report function.");
+ }
+ else ();
+
+ variable $failures := fn:parse-xml(file:read-text($pathFailures));
+
+ variable $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
+ "The path to FOTS catalog.xml was set to: "));
+
+ variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
+
+ reporting:do-reporting($FOTSCatalog, $catalogBaseURI, $failures, $exceptedTestCases, $exceptedTestSets, $verbose)
+ }
+ }
+ catch *
+ {
+ fn:error($err:code, $err:description)
+ }
+};
+
+
+(:~
+ : Loops through the test-sets and creates statistics.
+ : @param $FOTSCatalog FOTS catalog file.
+ : @param $failures the test reported by Zorba as failed.
+ : @param $exceptedTestCases lists of test cases that are not run(empty string means all tests will be run).
+ : @param $exceptedTestSets lists of test sets that are not run(empty string means all tests will be run).
+ : @param $verbose is set to TRUE it will also output the actual failures.
+ : @return a report of tests run.
+ :)
+declare %ann:nondeterministic function reporting:do-reporting(
+ $FOTSCatalog as document-node(),
+ $catalogBaseURI as xs:anyURI,
+ $failures,
+ $exceptedTestCases as xs:string*,
+ $exceptedTestSets as xs:string*,
+ $verbose as xs:boolean
+) as element(fots:report) {
+ let $excepted := fn:count($exceptedTestCases)
+ return
+ <report>
+ {
+ let $totalNoTests := fn:sum(for $testSet in $FOTSCatalog//fots:test-set
+ let $testSetDoc := fn:doc(fn:resolve-uri($testSet/@file, $catalogBaseURI))
+ return fn:count($testSetDoc//fots:test-case)),
+ $totalFailures := fn:sum( for $testSet in $failures//fots:test-set
+ return fn:count($testSet//fots:test-case[@result ='fail'])),
+ $totalNotApplicable := fn:sum(for $testSet in $failures//fots:test-set
+ return fn:count($testSet//fots:test-case[@result ='not applicable'])),
+ $notRun := fn:sum(for $exeptedTS in $exceptedTestSets
+ return
+ for $testSet in $FOTSCatalog//fots:test-set
+ let $testSetDoc := fn:doc(fn:resolve-uri($testSet/@file, $catalogBaseURI))
+ where (fn:data($testSetDoc/fots:test-set/@name) = $exeptedTS)
+ return fn:count($testSetDoc//fots:test-case)),
+ $executionTime := fn:sum(for $testCase in $failures//fots:test-set//fots:test-case return xs:dayTimeDuration($testCase/@executionTime))
+ return
+ <brief totalTests="{$totalNoTests}"
+ totalFailures="{$totalFailures}"
+ totalNotApplicable="{$totalNotApplicable}"
+ totalNotRun="{$notRun + $excepted}"
+ totalExecutionTime="{$executionTime}"/>
+ }
+ {
+ for $testSetFile in $FOTSCatalog//fots:test-set
+ let $testSetURI := fn:resolve-uri($testSetFile/@file, $catalogBaseURI),
+ $testSetDoc := fn:doc($testSetURI),
+ $testSetName := fn:data($testSetDoc/fots:test-set/@name),
+ $totalNoTestCases := fn:count($testSetDoc//fots:test-case),
+ $totalFailures := for $testCase in $failures//fots:test-set[@name = $testSetName]//fots:test-case[@result ="fail"]
+ return $testCase,
+ $percent := fn:round((1 - (fn:count($totalFailures) div $totalNoTestCases))*100,2),
+ $executionTime := fn:sum(for $testCase in $failures//fots:test-set[@name = $testSetName]//fots:test-case return xs:dayTimeDuration($testCase/@executionTime))
+ order by count($totalFailures) descending
+ return
+ <test-set name="{$testSetName}"
+ executionTime="{$executionTime}"
+ noFailures="{fn:count($totalFailures)}"
+ noTestCases="{$totalNoTestCases}"
+ percent="{$percent}"
+ failedTestNames="{fn:string-join( for $failure in $totalFailures
+ order by fn:data($failure/@name)
+ return fn:data($failure/@name)
+ ,",")}">
+ {if (not($verbose)) then $totalFailures else ()}
+ </test-set>
+ }
+ <exceptedTestCases>{$exceptedTestCases}</exceptedTestCases>
+ <exceptedTestSets>{$exceptedTestSets}</exceptedTestSets>
+ </report>
+};
\ No newline at end of file
=== added file 'test/fots_driver/util.xq'
--- test/fots_driver/util.xq 1970-01-01 00:00:00 +0000
+++ test/fots_driver/util.xq 2012-11-12 20:35:24 +0000
@@ -0,0 +1,112 @@
+(:
+ : Copyright 2006-2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : Zorba FOTS driver util
+ : @author Sorin Nasoi
+ :)
+
+module namespace util = "http://www.zorba-xquery.com/fots-driver/util";
+
+import schema namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
+
+import module namespace file = "http://expath.org/ns/file";
+
+import module namespace fots-err = "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
+
+declare namespace err = "http://www.w3.org/2005/xqt-errors";
+declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";
+
+
+(:~
+ : The serialization parameters for XML serialization.
+ :)
+ declare variable $util:serParamXml :=
+ <output:serialization-parameters>
+ <output:method value="xml" />
+ <output:indent value="no" />
+ <output:omit-xml-declaration value="yes" />
+ </output:serialization-parameters>;
+
+(:~
+ : The serialization parameters for XML serialization.
+ :)
+ declare variable $util:writeXML :=
+ <output:serialization-parameters>
+ <output:method value="xml" />
+ <output:indent value="yes" />
+ <output:omit-xml-declaration value="no" />
+ </output:serialization-parameters>;
+
+(:~
+ : Retrieve the value of from the given node that is either given as text node or in a file attribute.
+ :
+ : @param $case test-case element.
+ : @param $path the path of the test-set.
+ : @return the query text.
+ :)
+declare %ann:nondeterministic function util:get-value(
+ $case as element(fots:test-case),
+ $envBaseURI as xs:anyURI,
+ $node-name as xs:string
+) as xs:string {
+ try {
+ for $node in $case/descendant-or-self::*
+ where (fn:local-name-from-QName(fn:node-name($node)) = $node-name)
+ return
+ if(exists($node/@file))
+ then fn:unparsed-text(resolve-uri($node/@file, $envBaseURI))
+ else fn:data($node)
+ } catch * {
+ fn:error($fots-err:errNA, $err:description)
+ }
+};
+
+(:~
+ : returns the parent folder of the given file path.
+ : example: util:parent-folder('/home/user/file.ext') returns '/home/user'.
+ : @param $path Path.
+ : @return the parent folder of the given file.
+ :)
+
+declare function util:parent-folder(
+ $path as xs:string
+) as xs:anyURI {
+ xs:anyURI(fn:substring-before($path, file:base-name($path)))
+};
+
+declare function util:serialize-result(
+ $result as item()*
+) as xs:string* {
+ for $res in $result
+ return
+ if($res instance of node())
+ then fn:serialize($res, $util:serParamXml)
+ else fn:string($res)
+};
+
+declare function util:serialize-result(
+ $result as item()*,
+ $SerParams
+) as xs:string* {
+ for $res in $result
+ return
+ if($res instance of node())
+ then fn:serialize($result, $SerParams)
+ else fn:string($res)
+};
Follow ups
-
[Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: noreply, 2012-11-21
-
[Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Zorba Build Bot, 2012-11-21
-
[Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Zorba Build Bot, 2012-11-21
-
[Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Sorin Marian Nasoi, 2012-11-21
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Markos Zaharioudakis, 2012-11-21
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Nicolae Brinza, 2012-11-21
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Sorin Marian Nasoi, 2012-11-20
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Nicolae Brinza, 2012-11-19
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Markos Zaharioudakis, 2012-11-18
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Nicolae Brinza, 2012-11-16
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Ghislain Fourny, 2012-11-15
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Ghislain Fourny, 2012-11-15
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Ghislain Fourny, 2012-11-15
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Ghislain Fourny, 2012-11-15
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Sorin Marian Nasoi, 2012-11-15
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Markos Zaharioudakis, 2012-11-14
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Chris Hillery, 2012-11-14
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Cezar Andrei, 2012-11-14
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Paul J. Lucas, 2012-11-14
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Markos Zaharioudakis, 2012-11-13
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Paul J. Lucas, 2012-11-13
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Juan Zacarias, 2012-11-12
-
Re: [Merge] lp:~zorba-coders/zorba/fots_driver into lp:zorba
From: Sorin Marian Nasoi, 2012-11-12