← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/added_fots_driver_back into lp:zorba

 

Sorin Marian Nasoi has proposed merging lp:~zorba-coders/zorba/added_fots_driver_back into lp:zorba.

Commit message:
Added fots_driver back again after it was removed by accident in r11146.

Requested reviews:
  Chris Hillery (ceejatec)
  Sorin Marian Nasoi (sorin.marian.nasoi)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/added_fots_driver_back/+merge/140401

Added fots_driver back again after it was removed by accident in r11146.
-- 
https://code.launchpad.net/~zorba-coders/zorba/added_fots_driver_back/+merge/140401
Your team Zorba Coders is subscribed to branch 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-12-18 11:45:19 +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-12-18 11:45:19 +0000
@@ -0,0 +1,49 @@
+Information about the W3C XQuery/XPath/XSLT 3.* Test Suite can be found at:
+  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 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 test cases 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
+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-test-cases -e dependency:=higherOrderFunctions
+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 -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 -e dependency:=higherOrderFunctions_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-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-case -e testSetName:=prod-Literal -e testCaseName:=Literals001 -o result.xml --indent
+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-case -e assertType:=assert-count -e testSetName:=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-case -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

=== 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-12-18 11:45:19 +0000
@@ -0,0 +1,197 @@
+(:
+ : 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
+ :)
+
+import module namespace d =
+  "http://www.zorba-xquery.com/fots-driver"; at "fots-driver.xq";
+import module namespace r =
+  "http://www.zorba-xquery.com/fots-driver/reporting"; at "reporting.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";
+
+(:~ 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 := "";
+
+(:~ name for the test set :)
+declare variable $testSetName as xs:string external := "";
+
+(:~ name for the test case :)
+declare variable $testCaseName 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";
+
+(:~ assertion type :)
+declare variable $assertType as xs:string external := "";
+
+(:~ dependency: used in 'list-test-cases' and 'run-test-sets' modes:)
+declare variable $dependency 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 := "";
+
+(:~ Tokenize comma or empty string :)
+declare %private function local:tokenize(
+  $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 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 test cases 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",
+    "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-test-cases -e dependency:=higherOrderFunctions",
+    "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 -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 -e dependency:=higherOrderFunctions_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-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-case -e testSetName:=prod-Literal -e testCaseName:=Literals001 -o result.xml --indent",
+    "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-test-case -e assertType:=assert-count -e testSetName:=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-case -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",
+    ""
+    ), "&#xA;")
+};
+
+(:~ The test cases in this list have bugs assigned 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(
+      (d:list-test-sets(
+        trace($fotsPath, "Path to FOTS catalog.xml set to: "),
+        local:tokenize(trace($testSetPrefixes, "'testSetPrefixes' set to: ")))),
+       "&#xA;")
+case "list-test-cases"
+  return
+    string-join(
+      (d:list-test-cases( trace($fotsPath,
+                                "Path to FOTS catalog.xml set to: "),
+                          local:tokenize(trace($testSetPrefixes,
+                                          "'testSetPrefixes' set to: ")),
+                          "",
+                          trace($dependency,
+                                "'dependency' set to:"))),
+               "&#xA;")
+case "list-matching-test-cases"
+  return string-join((d:list-matching-test-cases(
+                            trace($fotsPath,
+                                  "Path to FOTS catalog.xml set to: "),
+                            trace($pattern,
+                                  "pattern set to: "),
+                            trace($flags,
+                                  "flags were set to: ")), ""),
+                     "&#xA;")
+case "run-test-sets"
+  return d:run-fots($fotsPath,
+                    $fotsZorbaManifestPath,
+                    d:list-test-sets($fotsPath,
+                                     local:tokenize(trace($testSetPrefixes,
+                                       "'testSetPrefixes' set to: "))),
+                    d:list-test-cases($fotsPath,
+                                      local:tokenize($testSetPrefixes),
+                                      local:tokenize(trace($testCasePrefixes,
+                                        "'$testCasePrefixes' set to: ")),
+                                      trace($dependency,
+                                        "'dependency' set to:")),
+                    $exceptedTestCases,
+                    $exceptedTestSets,
+                    $assertType,
+                    xs:boolean($verbose),
+                    xs:boolean($showResult))
+case "run-test-case"
+  return d:run-fots($fotsPath,
+                    $fotsZorbaManifestPath,
+                    trace($testSetName,"'testSetName' set to: "),
+                    trace($testCaseName,"'testCaseName' set to: "),
+                    $exceptedTestCases,
+                    $exceptedTestSets,
+                    trace($assertType,"'assertType' set to: "),
+                    xs:boolean($verbose),
+                    xs:boolean($showResult))
+case "run-and-report"
+  return r:run-and-report($fotsPath,
+                          $fotsZorbaManifestPath,
+                          d:list-test-sets($fotsPath,
+                                          local:tokenize($testSetPrefixes)),
+                          '',
+                          $exceptedTestCases,
+                          $exceptedTestSets,
+                          $assertType,
+                          fn:false(),   (: the reports to W3C are always generated with verbose set to false:)
+                          xs:boolean($showResult))
+case "report"
+  return r: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-12-18 11:45:19 +0000
@@ -0,0 +1,561 @@
+(:
+ : 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';"),
+    "&#xA;");
+
+
+(:~
+ : 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 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 ()
+};
+
+
+(:~
+ : 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 the XQuery version declaration.
+ :)
+declare function env:add-xquery-version-decl(
+  $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(contains($dependencies,"XQ10") and
+            not(contains($test, "xquery version ")))
+    then 'xquery version "1.0";'
+    else ()
+};
+
+
+(:~
+ : Sets the declared default element namespace.
+ :
+ : @param $env the environment of the catalog/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 "',
+                 data($ns/@uri),
+                '";')
+};
+
+
+(:~
+ : Adds the declare namespace statements.
+ :
+ : @param $env the environment of the catalog/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 not($ns[@prefix=""]) and 
+          not(env:is-schema-prefix-bound(data($ns/@prefix),
+                                        $case,
+                                        $testSetBaseURI))
+    return concat('declare namespace ',
+                  data($ns/@prefix),
+                  ' = "',
+                  data($ns/@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: TODO report to W3C
+ :)
+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))
+};
+
+
+(:~
+ : Returns the the declare base-uri prolog statement.
+ :
+ : @param $env the environment of the catalog/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 '",
+                 data($baseURI/@uri),
+                "';")
+};
+
+
+(:~
+ : Add the decimal format declarations.
+ :
+ : @param $decimal-formats decimal formats.
+ : @return the decimal formats declarations.
+ :)
+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),
+                    ";"),' ')
+};
+
+
+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 := 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 ()
+};
+
+
+(:~
+ : Adds the variable declarations.
+ : @param $env environment.
+ : @param $case test case.
+ : @param $envBaseURI the relative URI for the environment.
+ : @param $testSetBaseURI the URI of the test set.
+ : @return the variable declarations.
+ :)
+declare %ann:nondeterministic function env:add-var-decl(
+  $env            as element(fots:environment)?,
+  $case           as element(fots:test-case),
+  $envBaseURI     as xs:anyURI,
+  $testSetBaseURI as xs:anyURI
+) as xs:string? 
+{
+  concat( env:var-decl-with-value($env,
+                                  $envBaseURI),
+          env:var-decl-with-value($case/fots:environment,
+                                  $testSetBaseURI),
+          env:var-decl-without-value($env,
+                                     $case/fots:environment))
+};
+
+
+declare %private function env:var-decl-with-value(
+  $env      as element(fots:environment)?,
+  $baseURI  as xs:anyURI
+) as xs:string? 
+{
+  string-join(
+    for $param in $env/fots:param
+    let $select := $param/@select
+    let $file := $env/fots:source[@uri = translate($select, "'", "")]/@file
+    let $type := $param/@as
+    let $varValue := if(starts-with($select, "'") and
+                        ends-with($select, "'") and
+                        exists($file))
+                     then  concat('"',
+                                 resolve-uri($file, $baseURI),
+                                 '"')
+                     else $select
+    where (exists($select) and
+(: if there is an attribute 'declared' set to true, this means that the variable
+   is declared within the 'test' itself so no additional variable declaration
+   is needed :)
+           empty($param[@declared="true"]))
+    return concat("declare variable $",
+                  $param/@name,
+                  ((concat(" as ", $type)))[$type],
+                  " := ",
+                  $varValue,
+                  ";")
+   ," ")
+};
+
+
+declare %private function env:var-decl-without-value(
+  $env      as element(fots:environment)?,
+  $envCase  as element(fots:environment)?
+) as xs:string? 
+{
+  string-join(
+    (for $param in ($env/fots:param, $envCase/fots:param)
+     let $select := $param/@select
+     let $type := $param/@as
+     where (empty($select) and
+            empty($param[@declared="true"]))
+     return concat("declare variable $",
+                   $param/@name,
+                   ((concat(" as ", $type)))[$type],
+                   " external;"),
+     for $source in ($env/fots:source, $envCase/fots:source)
+     let $role := $source/@role
+     where starts-with($role,"$")
+     return concat("declare variable ",
+                   $role,
+                   " external;"))
+   ," ")
+};
+
+
+(:~
+ : Returns the string for setting the context item if needed.
+ : @param $env environment.
+ : @param $envBaseURI test base URI of the environment.
+ : @return the string for setting the context item if needed.
+ :)
+declare function env:set-context-item(
+  $env        as element(fots:environment)?,
+  $envBaseURI as xs:anyURI?
+) as xs:string? {
+  if (exists($env/fots:source[@role = "."]))
+  then string-join((env:declare-context-item($env, $envBaseURI),
+                   'xqxq:bind-context-item($queryID, $contextItem);')
+                   ,"&#xA;")
+  else ()
+};
+
+
+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(
+    ("&#xA;",
+     "variable $contextItemQuery := xqxq:prepare-main-module('",
+     env:get-schema-import($env),
+     concat('validate { doc("', $ciURI, '")', "}',", " "),
+           "resolver:url-resolver#2, ());",
+           "variable $contextItem := xqxq:evaluate($contextItemQuery);")
+   ,"&#xA;")
+};
+
+
+(:~
+ : Returns the strings for variable binding in XQXQ.
+ :
+ : @param $env the environment of the catalog/test-set (given with 'ref').
+ : @param $envBaseURI the relative URI for the environment.
+ : @return the strings for variable binding in XQXQ.
+ :)
+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 starts-with(data($source/@role),"$")
+                     return substring-after(data($source/@role),"$"),
+        $srcValues := for $srcName in $srcNames
+                      return concat('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:= $param/@select
+      let $file := $env/fots:source[@uri = translate($select, "'", "")]/@file
+      let $varValue := if(starts-with($select, "'") and
+                          ends-with($select, "'") and
+                          exists($file))
+                       then  concat('"',
+                                   resolve-uri($file, $envBaseURI),
+                                   '"')
+                       else $select
+      let $varName := $param/@name
+      where (exists($select) and
+(: if there is an attribute 'declared' set to true, this means that the variable
+   is declared within the 'test' itself :)
+             exists($param[@declared="true"]))
+      return
+        concat('xqxq:bind-variable( $queryID, xs:QName("',
+               $param/@name,
+               '")', ', ',
+               $varValue, ');'))
+    , "&#xA;")
+};
+
+
+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 = data($env/fots:schema/@uri)]
+    let $prefix as xs:string := if(exists($namespace))
+                                then xs:string(data($namespace/@prefix))
+                                else "p"
+    return
+      if($prefix = "")
+      then concat('import schema default element namespace "',
+                  $env/fots:schema/@uri,
+                  '";&#xA;')
+      else concat('import schema namespace ',
+                  $prefix,
+                  ' = "',
+                  $env/fots:schema/@uri,
+                  '";&#xA;')
+};
+
+
+(:~
+ : Returns the 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 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 ()"),
+                      "&#xA;")
+    else (),
+    if (exists($modules))
+    then string-join(("case 'module'",
+                      "  return switch($namespace)",
+                      for $module in $modules
+                      return concat("    case '",
+                                   data($module/@uri),
+                                   "' return unparsed-text('",
+                                   resolve-uri($module/@file, $testSetBaseURI),
+                                   "') "),
+                    "    default return ()"),
+                    "&#xA;")
+    else (),
+    if (exists($resources)) then
+    string-join(("case ''",
+                 "  return switch($namespace)",
+                  for $resource in $resources
+                  return concat("    case '",
+                                 data($resource/@uri),
+                                 "' return unparsed-text('",
+                                 resolve-uri($resource/@file, $envBaseURI),
+                                 "'",
+                                 if(exists($resource/@encoding))
+                                 then concat (",'",
+                                              data($resource/@encoding),
+                                              "'")
+                                 else (),
+                                 ") "),
+                 "         default return ()")
+                ,"&#xA;")
+    else ()
+    , "default return ()","};"),
+    "&#xA;")
+};
+
+
+(:~
+ : Checks the dependencies according to the Zorba manifest.
+ :
+ : @param $deps the dependencies of the test set and test case
+ : @param $zorbaManifest Zorba manifest document.
+ : @return if true empty string, otherwise returns a string with the
+ : dependencies that were not matched.
+ :)
+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 ()
+};
+
+
+(:~
+ : Retrieves the environment from a test-set/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 (empty($envTestSet))
+    then $catalog/catalog//environment[@name = $envName]
+    else $envTestSet
+};

=== 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-12-18 11:45:19 +0000
@@ -0,0 +1,36 @@
+(:
+ : 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");

=== 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-12-18 11:45:19 +0000
@@ -0,0 +1,565 @@
+(:
+ : 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";
+
+(:~
+ : Checks if the result matches the assertions.
+ : @param $result actual result.
+ : @param $expResult expected result.
+ : @param $showResult is true the verbose mode is assumed.
+ : @return the results of assertion evaluations.
+ :)
+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>,
+              <errors>{$err}</errors>)
+        else ()
+      }
+    </out>
+};
+
+(:~
+ : Checks if the error found matches the expected error (if any).
+ : @param $result actual result.
+ : @param $expResult expected result.
+ : @param $code err:code.
+ : @param $errorDescription err:description.
+ : @param $showResult is true the verbose mode is assumed.
+ : @return the results of error evaluation.
+ :)
+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 $err
+  else
+    concat("Expected error &#xA;",
+          data($expResult/@code),
+          ",&#xA; 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 = local-name-from-QName($code)]))
+    then ()
+    else concat("Expected error: ",
+                data($expResult/@code),
+                ". Found error: ",
+                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: &#xA;",
+              data($expResult),
+              ".&#xA; Found error ",
+              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 error($fots-err:errNA,
+                     "&#xA;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 $results :=
+    for $tmp in $expResult/*
+    return <result>{
+      for $r in eval:check-assertion($result,
+                                     $tmp,
+                                     $code,
+                                     $errorDescription,
+                                     $showResult)
+      return <item>{$r}</item>
+    } </result>
+  where every $result in $results satisfies $result/item
+  return concat("&#xA;Assert-any-of returned: ",
+                string-join(util:serialize-result($results/data(item)), ' '))
+};
+
+(: 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));
+    variable $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("&#xA;Assertion '",
+           $expResult,
+           "'&#xA; 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 "Actual number of items 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 := (",string(data($expResult)),") return ",
+      "every $i in 1 to max((count($x),count($y))) satisfies deep-equal($x[$i],$y[$i])");
+    variable $queryKey := xqxq:prepare-main-module($queryText),
+             $queryKeyResult := xqxq:bind-variable($queryKey,
+                                                   xs:QName('x'),
+                                                   $result),
+             $queryResult := xqxq:evaluate($queryKey);
+    if($queryResult)
+    then ()
+    else concat("&#xA;Result is not deep-equal to '", $expResult, "'&#xA;")
+  }
+  } catch * {
+    concat("&#xA;Assert-deep-eq '",
+          $expResult,
+          "'&#xA; 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 "&#xA;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("&#xA;Assert-eq: Result '",
+                string-join(util:serialize-result($result),' '),
+                "' &#xA;doesn't match expected item '",
+                xs:string($expResult),
+                "'.")
+  }
+  } catch * {
+    concat("&#xA;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 "&#xA;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 "&#xA;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 := (",string(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(distinct-values(($x, $y)))) = count(distinct-values($x))");
+    variable $queryKey := xqxq:prepare-main-module($queryText),
+             $queryKeyResult := xqxq:bind-variable($queryKey,
+                                                  xs:QName('x'),
+                                                  $result),
+             $queryResult := xqxq:evaluate($queryKey);
+    if($queryResult)
+    then ()
+    else concat("&#xA;Result isn't a permutation of '",
+                $expResult,
+                "'&#xA;")
+  }
+  } catch * {
+    concat("&#xA;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((normalize-space($result1) eq normalize-space(string($expResult))) or
+         (normalize-space($result2) eq normalize-space(string($expResult))))
+      then ()
+      else concat("&#xA;Result '",
+                  $result1,
+                  "'&#xA; is different from the expected result &#xA;'",
+                  string($expResult),
+                  "'.")
+  } catch * {
+    concat("&#xA;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
+      concat("&#xA;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 concat("&#xA;Expected '",
+                  $serResult,
+                  "'&#xA; does not match  &#xA;'",
+                  $serExpResult,
+                  "' with flags '",
+                  $matchesFlags,
+                  "'")
+    else
+      if(matches($serResult, $serExpResult))
+      then ()
+      else concat("&#xA;Expected ",
+                  $serResult,
+                  "'&#xA; does not match  &#xA;'",
+                  $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 normalize-space($serRes),
+        $expRes :=  if (empty($expResult[@normalize-space="true"]))
+                    then xs:string($expResult)
+                    else normalize-space(xs:string($expResult))
+    return
+      if($res eq $expRes)
+      then ()
+      else concat("&#xA;Expected '",
+                  $expRes,
+                  "'&#xA; found  &#xA;'",
+                  $res,
+                  "'")
+  } catch * {
+    concat("&#xA;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 ",
+                                  data($expResult));
+    variable $queryKey := xqxq:prepare-main-module($queryText),
+             $queryKeyResult := xqxq:bind-variable($queryKey,
+                                                  xs:QName('x'),
+                                                  $result),
+             $queryResult := xqxq:evaluate($queryKey);
+    if($queryResult)
+    then ()
+    else concat("&#xA;Result doesn't have type '",
+                data($expResult),
+                "'")
+  }
+  } catch * {
+    concat("&#xA;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-12-18 11:45:19 +0000
@@ -0,0 +1,752 @@
+(:
+ : 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)
+};
+
+declare %private function driver:matches-dependency(
+  $dependencies as element(fots:dependency)*,
+  $filter       as xs:string
+) as xs:boolean {
+  let $filter := tokenize($filter, '_')
+  let $depValue := $filter[1]
+  let $depSatisfied as xs:string := if(exists($filter[2]) and
+                                    ($filter[2] = 'true' or $filter[2]='false'))
+                                    then $filter[2]
+                                    else 'true'
+  return
+    if(xs:boolean($depSatisfied))
+
+    (: $depSatisfied = 'true' :)
+    then (exists($dependencies[@value = $depValue and
+                               @satisfied = $depSatisfied]) or
+          exists($dependencies[@value = $depValue and empty(@satisfied)]))
+
+    (: $depSatisfied = 'false' :)
+    else  exists($dependencies[@value = $depValue and
+                               @satisfied = $depSatisfied])
+};
+
+(:~
+ : Loops through the given test set and returns the test cases that have the
+ : given dependencies defined.
+ : @param $testSet test set document.
+ : @param $dependency defined dependency
+ : (empty string means all test cases).
+ : @return matching test case names.
+ :)
+declare function driver:list-test-cases(
+  $testSetDoc as document-node(),
+  $dependency as xs:string*
+) as xs:string* {
+  if(string-join($dependency,'') = '')
+  then $testSetDoc//fots:test-case/@name
+  else  for $testCase in $testSetDoc//fots:test-case
+        let $cond := driver:matches-dependency(($testSetDoc/fots:test-set/fots:dependency,
+                                                $testCase/fots:dependency),
+                                               $dependency)
+        where $cond
+        return$testCase/@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 test cases).
+ : @param $dependency type of dependency that has to be met
+ : (empty string means all test cases).
+ : @return available FOTS test cases.
+ :)
+declare %ann:nondeterministic function driver:list-test-cases(
+  $fotsPath         as xs:string,
+  $testSetPrefixes  as xs:string*,
+  $dependency       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 driver:list-test-cases($testSetDoc, $dependency)
+    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 driver:list-test-cases($testSetDoc, $dependency)
+};
+
+(:~
+ : 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 test cases).
+ : @param $testCasePrefixes name/criteria for the test cases
+ : (empty string means all test cases).
+ : @param $dependency type of dependency that has to be met
+ : (empty string means all test cases).
+ : @return available FOTS test cases.
+ :)
+declare %ann:nondeterministic function driver:list-test-cases(
+  $fotsPath         as xs:string,
+  $testSetPrefixes  as xs:string*,
+  $testCasePrefixes as xs:string*,
+  $dependency       as xs:string*
+) as xs:string* {
+  let $doc := doc(resolve-uri($fotsPath)),
+      $baseUri:= resolve-uri(util:parent-folder($fotsPath)),
+      $testCaseNames := driver:list-test-cases($fotsPath,
+                                               $testSetPrefixes,
+                                               $dependency)
+  return
+    for $prefix in $testCasePrefixes
+    return
+      for $name in $testCaseNames
+      where starts-with($name,
+                        $prefix)
+      return $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 matches(util:get-value($testCase, 
+                                  util:parent-folder($uri),
+                                  "test"),
+                   $pattern,
+                   $flags)
+      return
+        concat(resolve-uri($testSet/@file, $baseUri),
+              ", test name:",
+              data($testCase/@name))
+};
+
+declare %private function driver:list-assertions(
+  $case as element(fots:test-case)
+) as xs:string* {
+  distinct-values(for $assert in $case/result/descendant-or-self::*
+                  return local-name-from-QName(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), 
+                              "Path to FOTS catalog.xml set to: ")),
+      $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
+                                    "Path to FOTSZorbaManifest set to:"))
+  return driver:run($FOTSCatalog,
+                    resolve-uri(util:parent-folder($FOTSCatalogFilePath)),
+                    $FOTSZorbaManifest,
+                    $testSetPrefixes,
+                    $testCasePrefixes,
+                    $exceptedTestCases,
+                    $exceptedTestSets,
+                    trace($assert,          "The filter for 'assert name' set to: "),
+                    trace($verbose,         "'Verbose' parameter set to: "),
+                    $showResult)
+  }
+  catch * {
+    error($err:code,
+          concat("&#xA;Please make sure the passed 'fotsPath' points to the",
+                 "exact location of the FOTS catalog.xml:&#xA;",
+                 resolve-uri($FOTSCatalogFilePath),
+                 "&#xA;and that the passed 'fotsZorbaManifestPath' points to",
+                 "a file in the same folder as cli.xq:&#xA;",
+                 resolve-uri($FOTSZorbaManifestPath)))
+  }
+};
+
+(:~
+ : Loops through the FOTS catalog and evaluates all test cases
+ :
+ : @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 := 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(data($testCase/@name)),
+                                                    $exceptedTestCases)
+                           else functx:value-except(
+                                  functx:value-intersect(data($testCase/@name),
+                                                         $testCasePrefixes),
+                                  $exceptedTestCases),
+            (:true if the tests-case has an assertion type that is requested :)
+            $hasReqAssert := (($assert = '') or
+                              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 := 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(data($testCase/@name)),
+                                                      $exceptedTestCases)
+                              else functx:value-except(
+                                     functx:value-intersect(data($testCase/@name),
+                                                            $testCasePrefixes),
+                                     $exceptedTestCases),
+            (:true if the tests-case has an assertion type that is requested :)
+              $hasReqAssert := (($assert = '') or
+                              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(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('",
+          "&#xA;",
+          replace($queryText,"'","''"),
+          "'",
+          "&#xA;",
+          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)"
+   ),
+  "&#xA;")
+};
+
+(:~
+ : 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);
+      (:TODO check if this works:)
+      (: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 Cover the "(:%VARDECL%:)"when there are tests in FOTS that use it:)
+try {
+{
+  variable $queryName := trace(data($case/@name),
+                              "processing test case :");
+ 
+  variable $test := util:get-value($case,
+                                   $testSetBaseURI,
+                                   "test");
+  variable $enableHOF := env:enable-HOF-feature(($deps, $case//fots:dependency),
+                                                $test);
+  variable $query := string-join((env:add-xquery-version-decl(($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,
+                                                   $envBaseURI,
+                                                   $testSetBaseURI),
+                                  $test
+                                  ),"&#xA;"),
+           $xqxqQuery := 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 when 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(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>
+          <actual-result>{$result}</actual-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>
+          <actual-result>{$result}</actual-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-12-18 11:45:19 +0000
@@ -0,0 +1,250 @@
+(:
+ : 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), 
+                                "Path to FOTS catalog.xml set to: "));
+
+    variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
+
+    variable $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
+                                      "Path to FOTSZorbaManifest 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 *
+{
+  error($err:code,
+        $err:description,
+        concat("&#xA;Please make sure the passed 'fotsPath' points to the ",
+               "exact location of the FOTS catalog.xml:&#xA;",
+               resolve-uri($FOTSCatalogFilePath),
+               "&#xA;and that the passed 'fotsZorbaManifestPath' points to",
+               " a file in the same folder as cli.xq:&#xA;",
+               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
+      {
+        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 := parse-xml(file:read-text($pathFailures));
+
+      variable $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
+                                  "Path to FOTS catalog.xml set to: "));
+
+      variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
+
+      reporting:do-reporting($FOTSCatalog,
+                             $catalogBaseURI,
+                             $failures,
+                             $exceptedTestCases,
+                             $exceptedTestSets,
+                             $verbose)
+    }
+  }
+  catch *
+  {
+    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 := count($exceptedTestCases)
+  return
+  <report>
+  {
+    let $totalNoTests := sum(for $testSet in $FOTSCatalog//fots:test-set
+                             let $testSetDoc := doc(resolve-uri($testSet/@file,
+                                                    $catalogBaseURI))
+                             return count($testSetDoc//fots:test-case)),
+        $totalFailures := sum(for $testSet in $failures//fots:test-set
+                              return count($testSet//fots:test-case[@result ='fail'])),
+        $totalNotApplicable := sum(for $testSet in $failures//fots:test-set
+                                   return count($testSet//fots:test-case[@result ='not applicable'])),
+        $notRun := sum(for $exeptedTS in $exceptedTestSets
+                       return
+                        for $testSet in $FOTSCatalog//fots:test-set
+                        let $testSetDoc := doc(resolve-uri($testSet/@file, $catalogBaseURI))
+                        where (data($testSetDoc/fots:test-set/@name) = $exeptedTS)
+                        return count($testSetDoc//fots:test-case)),
+        $executionTime := 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 := resolve-uri($testSetFile/@file,
+                                   $catalogBaseURI),
+        $testSetDoc := doc($testSetURI),
+        $testSetName := data($testSetDoc/fots:test-set/@name),
+        $totalNoTestCases := count($testSetDoc//fots:test-case),
+        $totalFailures := for $testCase in $failures//fots:test-set[@name = $testSetName]//fots:test-case[@result ="fail"]
+                          return $testCase,
+        $percent := round((1 - (count($totalFailures) div $totalNoTestCases))*100,2),
+        $executionTime := 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="{count($totalFailures)}"
+              noTestCases="{$totalNoTestCases}"
+              percent="{$percent}"
+              failedTestNames="{string-join( for $failure in $totalFailures
+                                              order by data($failure/@name)
+                                              return data($failure/@name)
+                                              ,",")}">
+   {if (not($verbose)) then $totalFailures else ()}
+    </test-set>
+   }
+   <exceptedTestCases>{$exceptedTestCases}</exceptedTestCases>
+   <exceptedTestSets>{$exceptedTestSets}</exceptedTestSets>
+   </report>
+};

=== added directory 'test/fots_driver/tools'
=== added file 'test/fots_driver/tools/dependencies.xq'
--- test/fots_driver/tools/dependencies.xq	1970-01-01 00:00:00 +0000
+++ test/fots_driver/tools/dependencies.xq	2012-12-18 11:45:19 +0000
@@ -0,0 +1,27 @@
+(: this query loads a rezults.xml file and reports the number of 'non applicable' tests grouped by feature :)
+(: 
+  sample usage
+  ./zorba -f -q ../../test/fots_driver/tools/dependencies.xq
+          -e pathFailures:=results_12_nov.xml
+          -o driver_dependencies.xml
+          --indent
+:)
+
+  import module namespace file = "http://expath.org/ns/file";;
+  
+  declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";;
+  declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";;
+  
+  declare variable $pathFailures external;
+
+  variable $failures := fn:parse-xml(file:read-text($pathFailures));
+  
+  <report> {
+    for $d in distinct-values(data($failures/fots:test-cases/fots:test-set/fots:test-case[@result="not applicable"]/@comment))
+    order by $d
+    return
+      <dependency type="{$d}"> {
+        <value number-of-tests="{count($failures/fots:test-cases//fots:test-set//fots:test-case[@result="not applicable" and @comment=$d])}" />
+      }</dependency>
+ }</report>
+ 
\ No newline at end of file

=== added file 'test/fots_driver/tools/process.xq'
--- test/fots_driver/tools/process.xq	1970-01-01 00:00:00 +0000
+++ test/fots_driver/tools/process.xq	2012-12-18 11:45:19 +0000
@@ -0,0 +1,127 @@
+(:
+ : 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.
+ :)
+ 
+(:~
+ : Run every test case that matches a given criterion in a different process
+ : and report every test case that HANGS or ends in a SEG FAULT.
+ :
+ : @author Sorin Nasoi
+ :)
+
+
+import module namespace proc =
+  "http://www.zorba-xquery.com/modules/process";;
+import module namespace util =
+  "http://www.zorba-xquery.com/fots-driver/util"; at "../util.xq";
+import module namespace d =
+  "http://www.zorba-xquery.com/fots-driver"; at "../fots-driver.xq";
+import module namespace fots-err =
+  "http://www.zorba-xquery.com/fots-driver/errors"; at "../errors.xq";
+  
+declare namespace ann =
+  "http://www.zorba-xquery.com/annotations";;
+declare namespace fots =
+  "http://www.w3.org/2010/09/qt-fots-catalog";;
+
+declare variable $pathFOTS as xs:string external :="";
+
+(:~
+ : Return the exit-code after invoking the FOTS driver with given $params.
+ :
+ : @param $params additional params.
+ : @return the exit-code returned by the invoked application.
+ :)
+declare %ann:sequential function local:exec(
+  $params as xs:string*
+) as xs:string {
+  variable $pathZorba := normalize-space(xs:string(proc:exec("pwd")/proc:stdout));
+
+  proc:exec(string-join(($pathZorba, "/zorba"),''),
+            ("-f", "-q", concat($pathZorba, "/../../test/fots_driver/cli.xq"),
+             "-e", concat("fotsPath:=", $pathFOTS),
+             "-e", "verbose:=false",
+             $params
+            )
+           )/proc:exit-code
+};
+
+declare %private %ann:sequential function local:invoke-exec(
+  $testSets   as element(fots:test-set)*,
+  $baseUri    as xs:anyURI,
+  $dependency as xs:string*
+) as xs:string* {
+  for $testSet in $testSets
+    let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
+    let $testSetName := xs:string($testSet/@name)
+    let $testCaseNames as xs:string* := d:list-test-cases($testSetDoc,
+                                                          $dependency)
+    return
+      for $testCaseName in $testCaseNames
+      let $exit-code := 
+          trace(local:exec(("-e", "mode:=run-test-case",
+                      "-e", concat("testSetName:=",  $testSetName),
+                      "-e", concat("testCaseName:=", trace($testCaseName, "processing test case :"))
+                     )
+                    ),"exit-code")
+      where (xs:integer($exit-code) gt xs:integer(134))
+      return $testCaseName
+};
+  
+(:~
+ : Return the name of the test cases that return an exit-code > 128.
+ :
+ : @param $fotsPath path to the FOTS catalog file.
+ : @param $testSetPrefixes name/criteria for the test sets.
+ : @param $dependency defined dependency.
+ : @return the exit-codes returned by the invoked applications.
+ :)
+declare %ann:sequential function local:list-test-cases(
+  $fotsPath         as xs:string,
+  $testSetPrefixes  as xs:string*,
+  $dependency       as xs:string*
+) as xs:string* {
+  variable  $doc := doc(resolve-uri($fotsPath)),
+            $baseUri:= resolve-uri(util:parent-folder($fotsPath));
+ 
+  if(string-join($testSetPrefixes,'') = '')
+  then local:invoke-exec($doc/fots:catalog/fots:test-set,
+                         $baseUri,
+                         $dependency)
+  else
+    for $prefix in $testSetPrefixes
+    return
+      local:invoke-exec($doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)],
+                        $baseUri,
+                        $dependency)
+};
+
+if( $pathFOTS = '')
+then fn:error($fots-err:errNA, 
+              "please set the external variable $pathFOTS to point to FOTS catalog.xml file.")
+else
+concat("'",
+       string-join(local:list-test-cases($pathFOTS, '', 'higherOrderFunctions'),"', '"),
+       "'")
+
+
+(:
+local:exec(
+            ("-e", "mode:=run-test-case",
+             "-e", concat("testSetName:=",  "misc-HigherOrderFunctions"),
+             "-e", concat("testCaseName:=", "xqhof2")
+            )
+          )
+:)
\ 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-12-18 11:45:19 +0000
@@ -0,0 +1,119 @@
+(:
+ : 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* {
+util:serialize-result($result,
+                      $util:serParamXml)
+};
+
+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($res,
+                     $SerParams)
+   else fn:string($res)
+};


Follow ups