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

Proposed by Sorin Marian Nasoi
Status: Merged
Approved by: Sorin Marian Nasoi
Approved revision: 11154
Merged at revision: 11153
Proposed branch: lp:~zorba-coders/zorba/added_fots_driver_back
Merge into: lp:zorba
Diff against target: 2804 lines (+2746/-0)
11 files modified
test/fots_driver/FOTSZorbaManifest.xml (+66/-0)
test/fots_driver/README.TXT (+49/-0)
test/fots_driver/cli.xq (+197/-0)
test/fots_driver/environment.xq (+561/-0)
test/fots_driver/errors.xq (+36/-0)
test/fots_driver/evaluate.xq (+565/-0)
test/fots_driver/fots-driver.xq (+752/-0)
test/fots_driver/reporting.xq (+244/-0)
test/fots_driver/tools/dependencies.xq (+27/-0)
test/fots_driver/tools/process.xq (+130/-0)
test/fots_driver/util.xq (+119/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/added_fots_driver_back
Reviewer Review Type Date Requested Status
Sorin Marian Nasoi Approve
Chris Hillery Approve
Review via email: mp+140401@code.launchpad.net

Commit message

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

Description of the change

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

To post a comment you must log in.
Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) :
review: Approve
Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job added_fots_driver_back-2012-12-18T11-47-44.816Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job added_fots_driver_back-2012-12-18T12-16-45.666Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:57:23 +0000
@@ -0,0 +1,66 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<FOTS-test-suite-result xmlns="http://www.w3.org/2010/09/qt-fots-catalog">
3 <implementation name="Zorba" version="trunk" anonymous-result-column="false">
4 <organization name="http://www.zorba-xquery.com" anonymous="false"/>
5 <submitter name="Sorin Nasoi" email="spungi@gmail.com"/>
6 </implementation>
7 <dependencies-satisfied>
8 <dependency type="feature" value="collection-stability" satisfied="true"/> <!-- Is this correct? -->
9 <dependency type="feature" value="directory-as-collection-uri" satisfied="true"/> <!-- Is this correct? -->
10 <dependency type="feature" value="higherOrderFunctions" satisfied="false"/>
11 <dependency type="feature" value="moduleImport" satisfied="true"/>
12 <dependency type="feature" value="namespace-axis" satisfied="false"/> <!-- Is this correct? -->
13 <dependency type="feature" value="schema-location-hint" satisfied="false"/> <!-- Is this correct? -->
14 <dependency type="feature" value="schemaAware" satisfied="true"/>
15 <dependency type="feature" value="schemaImport" satisfied="true"/>
16 <dependency type="feature" value="schemaValidation" satisfied="true"/>
17 <dependency type="feature" value="staticTyping" satisfied="false"/>
18 <dependency type="feature" value="xpath-1.0-compatibility" satisfied="true"/> <!-- Is this correct? -->
19
20 <dependency type="spec" value="XP10 XQ10" satisfied="true"/>
21 <dependency type="spec" value="XP10+" satisfied="true"/>
22 <dependency type="spec" value="XP20 XQ10" satisfied="true"/>
23 <dependency type="spec" value="XP20+" satisfied="true"/>
24 <dependency type="spec" value="XP30+" satisfied="true"/>
25 <dependency type="spec" value="XP30+ XQ10+" satisfied="true"/>
26 <dependency type="spec" value="XP30+ XQ30+" satisfied="true"/>
27 <dependency type="spec" value="XQ10" satisfied="true"/>
28 <dependency type="spec" value="XQ10 XP20" satisfied="true"/>
29 <dependency type="spec" value="XQ10+" satisfied="true"/>
30 <dependency type="spec" value="XQ10+ XP20+" satisfied="true"/>
31 <dependency type="spec" value="XQ10+ XP30+" satisfied="true"/>
32 <dependency type="spec" value="XQ30" satisfied="true"/>
33 <dependency type="spec" value="XQ30 XP30" satisfied="true"/>
34 <dependency type="spec" value="XQ30+" satisfied="true"/>
35 <dependency type="spec" value="XQ30+ XP30+" satisfied="true"/>
36 <dependency type="spec" value="XT30+" satisfied="false"/>
37
38 <dependency type="xml-version" value="1.0" satisfied="true"/>
39 <dependency type="xml-version" value="1.0:4-" satisfied="true"/>
40 <dependency type="xml-version" value="1.0:5+ 1.1" satisfied="false"/>
41 <dependency type="xml-version" value="1.1" satisfied="false"/>
42
43 <dependency type="language" value="de" satisfied="false"/> <!-- Is this correct? -->
44 <dependency type="language" value="en" satisfied="true"/>
45 <dependency type="language" value="xib" satisfied="false"/> <!-- Is this correct? -->
46
47 <!-- Are these correct? -->
48 <dependency type="limits" value="year_lt_0" satisfied="true"/>
49 <dependency type="calendar" value="CB" satisfied="true"/>
50 <dependency type="format-integer-sequence" value="Α" satisfied="true"/>
51 <dependency type="format-integer-sequence" value="α" satisfied="true"/>
52 <dependency type="format-integer-sequence" value="١" satisfied="true"/>
53 <dependency type="format-integer-sequence" value="①" satisfied="true"/>
54 <dependency type="format-integer-sequence" value="⑴" satisfied="true"/>
55 <dependency type="format-integer-sequence" value="⒈" satisfied="true"/>
56 <dependency type="format-integer-sequence" value="一" satisfied="true"/>
57 <dependency type="format-integer-sequence" value="ﯴ" satisfied="true"/>
58 <dependency type="default-language" value="en" satisfied="true"/>
59 <dependency type="unicode-normalization-form" value="FULLY-NORMALIZED" satisfied="true"/>
60 <dependency type="unicode-normalization-form" value="NFD" satisfied="true"/>
61 <dependency type="unicode-normalization-form" value="NFKC" satisfied="true"/>
62 <dependency type="unicode-normalization-form" value="NFKD" satisfied="true"/>
63 <dependency type="xsd-version" value="1.0" satisfied="true"/>
64 <dependency type="xsd-version" value="1.1" satisfied="false"/>
65 </dependencies-satisfied>
66</FOTS-test-suite-result>
067
=== 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:57:23 +0000
@@ -0,0 +1,49 @@
1Information about the W3C XQuery/XPath/XSLT 3.* Test Suite can be found at:
2 http://dev.w3.org/2011/QT3-test-suite.
3
4In order to use the Zorba FOTS driver (written in XQuery) one has to follow
5these steps:
6
70) Build Zorba with ZORBA_WITH_BIG_INTEGER flag set to ON.
8
9 For example with CMake:
10 cmake -DZORBA_WITH_BIG_INTEGER=ON ..
11 make
12
131) Download the FOTS testsuite from W3C
14 Since currently there is no official release, a simple "cvs get" will do:
15
16 $ export CVSROOT=":pserver:anonymous@dev.w3.org:/sources/public"
17 $ cvs login
18 (Logging in to anonymous@dev.w3.org)
19 CVS password: anonymous
20 $ cvs get 2011/QT3-test-suite
21
223) run
23 ./zorba -f
24 -q ../../test/fots_driver/cli.xq
25
26Zorba FOTS driver usage examples:
27If you run Zorba from a checkout of the trunk and the build/bin folder,
28- /path/to/cli.xq can be set to ../../test/fots_driver/cli.xq
29
30Always try to output the result back to an XML file with nice indentation:
31./zorba -f -q ../../test/fots_driver/cli.xq -e SET_CLI_OPTIONS_HERE -o output.xml --indent
32
33 This way you will see trace information in the CLI window and detailed
34 results of the test cases in the 'output.xml'.
35
36zorba -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
37zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets
38zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets -e testSetPrefixes:=prod,app
39zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-cases -e testSetPrefixes:=prod-Literal
40zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-cases -e dependency:=higherOrderFunctions
41zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-matching-test-cases -e pattern:=catch
42zorba -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
43zorba -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
44zorba -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
45zorba -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
46zorba -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
47zorba -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
48zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=run-and-report -o report.xml --indent
49zorba -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
050
=== 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:57:23 +0000
@@ -0,0 +1,197 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Zorba FOTS driver CLI
19 : @author Ghislain Fourny, Sorin Nasoi
20 :)
21
22import module namespace d =
23 "http://www.zorba-xquery.com/fots-driver" at "fots-driver.xq";
24import module namespace r =
25 "http://www.zorba-xquery.com/fots-driver/reporting" at "reporting.xq";
26
27(:~ path to the place where FOTS can be found :)
28declare variable $fotsPath as xs:string external := "";
29
30(:~ path to the place where the FOTS Zorba manifest can be found :)
31declare variable $fotsZorbaManifestPath as xs:string external :=
32 "FOTSZorbaManifest.xml";
33
34(:~ Path to the results from a previous run :)
35declare variable $failuresFilePath as xs:string external := "";
36
37(:~ choose the CLI option you want to run :)
38declare variable $mode as xs:string external := "";
39
40(:~ name/criteria for the test sets :)
41declare variable $testSetPrefixes as xs:string external := "";
42
43(:~ name/criteria for the test cases :)
44declare variable $testCasePrefixes as xs:string external := "";
45
46(:~ name for the test set :)
47declare variable $testSetName as xs:string external := "";
48
49(:~ name for the test case :)
50declare variable $testCaseName as xs:string external := "";
51
52(:~ Enable or disable verbose output :)
53declare variable $verbose as xs:string external := "true";
54
55(:~
56 Enable or disable showing the actual query result in the output.
57 True by default.
58:)
59declare variable $showResult as xs:string external := "true";
60
61(:~ assertion type :)
62declare variable $assertType as xs:string external := "";
63
64(:~ dependency: used in 'list-test-cases' and 'run-test-sets' modes:)
65declare variable $dependency as xs:string external := "";
66
67(:~ regex for the tests in the 'list-matching-test-cases' option :)
68declare variable $pattern as xs:string external := "";
69
70(:~ flags for the tests in the 'list-matching-test-cases' option :)
71declare variable $flags as xs:string external := "";
72
73(:~ Tokenize comma or empty string :)
74declare %private function local:tokenize(
75 $input as xs:string
76) as xs:string*
77{
78 let $tokens := tokenize($input, ",")
79 return if (exists($tokens)) then $tokens else ""
80};
81
82declare function local:usage() as xs:string
83{
84 string-join((
85 "Zorba FOTS driver usage examples:",
86 "If you run Zorba from a checkout of the trunk and the build/bin folder,",
87 "- /path/to/cli.xq can be set to ../../test/fots_driver/cli.xq",
88 "",
89 "Always try to output the result back to an XML file with nice indentation:",
90 "./zorba -f -q ../../test/fots_driver/cli.xq -e SET_CLI_OPTIONS_HERE -o output.xml --indent",
91 "",
92 " This way you will see trace information in the CLI window and detailed",
93 " results of the test cases in the 'output.xml'.",
94 "",
95 "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",
96 "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets",
97 "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",
98 "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",
99 "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-cases -e dependency:=higherOrderFunctions",
100 "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",
101 "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",
102 "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",
103 "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",
104 "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",
105 "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",
106 "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",
107 "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",
108 "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",
109 ""
110 ), "&#xA;")
111};
112
113(:~ The test cases in this list have bugs assigned and should not be run :)
114variable $exceptedTestCases := (
115"cbcl-subsequence-011", "cbcl-subsequence-012", "cbcl-subsequence-013",
116"cbcl-subsequence-014" (:see bug lp:1069794 :)
117, "re00975", "re00976", "re00976a" (:see bug lp:1070533 :)
118, "fn-unparsed-text-lines-052" (:see bug lp:1073175 :)
119);
120
121(:~ The test in this list have bugs assigned already and should not be run :)
122variable $exceptedTestSets := ();
123
124switch ($mode)
125case "list-test-sets"
126 return
127 string-join(
128 (d:list-test-sets(
129 trace($fotsPath, "Path to FOTS catalog.xml set to: "),
130 local:tokenize(trace($testSetPrefixes, "'testSetPrefixes' set to: ")))),
131 "&#xA;")
132case "list-test-cases"
133 return
134 string-join(
135 (d:list-test-cases( trace($fotsPath,
136 "Path to FOTS catalog.xml set to: "),
137 local:tokenize(trace($testSetPrefixes,
138 "'testSetPrefixes' set to: ")),
139 "",
140 trace($dependency,
141 "'dependency' set to:"))),
142 "&#xA;")
143case "list-matching-test-cases"
144 return string-join((d:list-matching-test-cases(
145 trace($fotsPath,
146 "Path to FOTS catalog.xml set to: "),
147 trace($pattern,
148 "pattern set to: "),
149 trace($flags,
150 "flags were set to: ")), ""),
151 "&#xA;")
152case "run-test-sets"
153 return d:run-fots($fotsPath,
154 $fotsZorbaManifestPath,
155 d:list-test-sets($fotsPath,
156 local:tokenize(trace($testSetPrefixes,
157 "'testSetPrefixes' set to: "))),
158 d:list-test-cases($fotsPath,
159 local:tokenize($testSetPrefixes),
160 local:tokenize(trace($testCasePrefixes,
161 "'$testCasePrefixes' set to: ")),
162 trace($dependency,
163 "'dependency' set to:")),
164 $exceptedTestCases,
165 $exceptedTestSets,
166 $assertType,
167 xs:boolean($verbose),
168 xs:boolean($showResult))
169case "run-test-case"
170 return d:run-fots($fotsPath,
171 $fotsZorbaManifestPath,
172 trace($testSetName,"'testSetName' set to: "),
173 trace($testCaseName,"'testCaseName' set to: "),
174 $exceptedTestCases,
175 $exceptedTestSets,
176 trace($assertType,"'assertType' set to: "),
177 xs:boolean($verbose),
178 xs:boolean($showResult))
179case "run-and-report"
180 return r:run-and-report($fotsPath,
181 $fotsZorbaManifestPath,
182 d:list-test-sets($fotsPath,
183 local:tokenize($testSetPrefixes)),
184 '',
185 $exceptedTestCases,
186 $exceptedTestSets,
187 $assertType,
188 fn:false(), (: the reports to W3C are always generated with verbose set to false:)
189 xs:boolean($showResult))
190case "report"
191 return r:report($fotsPath,
192 $failuresFilePath,
193 $exceptedTestCases,
194 $exceptedTestSets,
195 xs:boolean($verbose))
196default
197 return local:usage()
0198
=== 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:57:23 +0000
@@ -0,0 +1,561 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Zorba FOTS driver environment
19 : @author Sorin Nasoi
20 :)
21
22module namespace env =
23 "http://www.zorba-xquery.com/fots-driver/environment";
24
25import module namespace xqxq =
26 "http://www.zorba-xquery.com/modules/xqxq";
27import module namespace util =
28 "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
29
30declare namespace fots =
31 "http://www.w3.org/2010/09/qt-fots-catalog";
32
33declare namespace ann =
34 "http://www.zorba-xquery.com/annotations";
35
36
37declare variable $env:hof as xs:string :=
38 string-join(
39 ( "declare namespace op = 'http://www.zorba-xquery.com/options/features';",
40 "declare namespace f = 'http://www.zorba-xquery.com/features';",
41 "declare option op:enable 'f:hof';"),
42 "&#xA;");
43
44
45(:~
46 : If there is a dependency on XQuery 3.0 and there is at least one HOF
47 : function in the test, return the strings for enabling the HOF feature.
48 :
49 : @param $deps the dependencies of the test set and test case
50 : @param $test the Query test.
51 : @return the strings for enabling the HOF feature
52 :)
53declare function env:enable-HOF-feature(
54 $deps as element(fots:dependency)*,
55 $test as xs:string
56) as xs:string?
57{
58 let $depSpec := string-join(distinct-values( for $dep in $deps
59 where $dep[@type="spec"]
60 return data($dep/@value)),""),
61 $depFeature := string-join(distinct-values(for $dep in $deps
62 where $dep[@type="feature"]
63 return data($dep/@value)),"")
64 return
65 if ((contains($depSpec,"XQ30") or contains($depSpec,"XP30")) and
66 contains($depFeature,"higherOrderFunctions"))
67 then $env:hof else ()
68};
69
70
71(:~
72 : Check if an XQuery version declaration needs to be added.
73 :
74 : @param $deps the dependencies of the test set and test case.
75 : @param $test the Query test.
76 : @return the XQuery version declaration.
77 :)
78declare function env:add-xquery-version-decl(
79 $deps as element(fots:dependency)*,
80 $test as xs:string
81) as xs:string?
82{
83 let $dependencies := string-join(distinct-values(for $dep in $deps
84 where $dep[@type="spec"]
85 return data($dep/@value)),"")
86 return
87 if ((contains($dependencies,"XQ30") or contains($dependencies,"XP30")) and
88 not(contains($test, "xquery version ")))
89 then 'xquery version "3.0";'
90 else if(contains($dependencies,"XQ10") and
91 not(contains($test, "xquery version ")))
92 then 'xquery version "1.0";'
93 else ()
94};
95
96
97(:~
98 : Sets the declared default element namespace.
99 :
100 : @param $env the environment of the catalog/test-set (given with 'ref').
101 : @param $envCase the environment of the test-case.
102 : @return the declare default element namespace.
103 :)
104declare function env:decl-def-elem-namespace(
105 $env as element(fots:environment)?,
106 $envCase as element(fots:environment)?
107) as xs:string?
108{
109 for $ns in ($env/fots:namespace, $envCase/fots:namespace)
110 where $ns[@prefix=""]
111 return concat('declare default element namespace "',
112 data($ns/@uri),
113 '";')
114};
115
116
117(:~
118 : Adds the declare namespace statements.
119 :
120 : @param $env the environment of the catalog/test-set (given with 'ref').
121 : @param $case the test-case.
122 : @param $testSetBaseURI the URI of the test set file.
123 : @return the declare namespace statements.
124 :)
125declare %ann:nondeterministic function env:decl-namespaces(
126 $env as element(fots:environment)?,
127 $case as element(fots:test-case),
128 $testSetBaseURI as xs:anyURI
129) as xs:string?
130{
131 string-join(
132 for $ns in ($env/fots:namespace, $case/fots:environment/fots:namespace)
133 where not($ns[@prefix=""]) and
134 not(env:is-schema-prefix-bound(data($ns/@prefix),
135 $case,
136 $testSetBaseURI))
137 return concat('declare namespace ',
138 data($ns/@prefix),
139 ' = "',
140 data($ns/@uri),
141 '";')
142 ," ")
143};
144
145
146(:~
147 : Return true if the prefix will be bound to a schema in the Query
148 : It's a bug in the FOTS if this function returns true: TODO report to W3C
149 :)
150declare %private %ann:nondeterministic function env:is-schema-prefix-bound(
151 $prefix as xs:string,
152 $case as element(fots:test-case),
153 $testSetBaseURI as xs:anyURI
154) as xs:boolean
155{
156 contains(util:get-value($case,
157 $testSetBaseURI,
158 "test"),
159 concat("import schema namespace ",
160 $prefix))
161};
162
163
164(:~
165 : Returns the the declare base-uri prolog statement.
166 :
167 : @param $env the environment of the catalog/test-set (given with 'ref').
168 : @param $envCase the environment of the test-case.
169 : @return the declare base-uri prolog statement.
170 :)
171declare function env:decl-base-uri(
172 $env as element(fots:environment)?,
173 $envCase as element(fots:environment)?
174) as xs:string?
175{
176 for $baseURI in ($env/fots:static-base-uri, $envCase/fots:static-base-uri)
177 return concat("declare base-uri '",
178 data($baseURI/@uri),
179 "';")
180};
181
182
183(:~
184 : Add the decimal format declarations.
185 :
186 : @param $decimal-formats decimal formats.
187 : @return the decimal formats declarations.
188 :)
189declare function env:decl-decimal-formats(
190 $decimal-formats as element(fots:decimal-format)*
191) as xs:string*
192{
193 if(empty($decimal-formats))
194 then ()
195 else
196 for $tmp in $decimal-formats
197 let $default := if(exists($tmp/@name))
198 then ()
199 else "default"
200 let $name := if(exists($tmp/@name))
201 then data($tmp/@name)
202 else ()
203 return
204 string-join(("declare",
205 $default,
206 "decimal-format",
207 $name,
208 env:set-properties($tmp),
209 ";"),' ')
210};
211
212
213declare %private function env:set-properties(
214 $decimal-format as element(fots:decimal-format)
215) as xs:string*
216{
217 for $att in $decimal-format/attribute::*
218 let $name := node-name($att)
219 let $value := data($att)
220 return
221 if(exists(index-of(("decimal-separator", "grouping-separator", "infinity",
222 "minus-sign", "NaN", "percent", "per-mille",
223 "zero-digit", "digit", "pattern-separator"),
224 xs:string($name))))
225 then concat($name, '="' , $value, '"')
226 else ()
227};
228
229
230(:~
231 : Adds the variable declarations.
232 : @param $env environment.
233 : @param $case test case.
234 : @param $envBaseURI the relative URI for the environment.
235 : @param $testSetBaseURI the URI of the test set.
236 : @return the variable declarations.
237 :)
238declare %ann:nondeterministic function env:add-var-decl(
239 $env as element(fots:environment)?,
240 $case as element(fots:test-case),
241 $envBaseURI as xs:anyURI,
242 $testSetBaseURI as xs:anyURI
243) as xs:string?
244{
245 concat( env:var-decl-with-value($env,
246 $envBaseURI),
247 env:var-decl-with-value($case/fots:environment,
248 $testSetBaseURI),
249 env:var-decl-without-value($env,
250 $case/fots:environment))
251};
252
253
254declare %private function env:var-decl-with-value(
255 $env as element(fots:environment)?,
256 $baseURI as xs:anyURI
257) as xs:string?
258{
259 string-join(
260 for $param in $env/fots:param
261 let $select := $param/@select
262 let $file := $env/fots:source[@uri = translate($select, "'", "")]/@file
263 let $type := $param/@as
264 let $varValue := if(starts-with($select, "'") and
265 ends-with($select, "'") and
266 exists($file))
267 then concat('"',
268 resolve-uri($file, $baseURI),
269 '"')
270 else $select
271 where (exists($select) and
272(: if there is an attribute 'declared' set to true, this means that the variable
273 is declared within the 'test' itself so no additional variable declaration
274 is needed :)
275 empty($param[@declared="true"]))
276 return concat("declare variable $",
277 $param/@name,
278 ((concat(" as ", $type)))[$type],
279 " := ",
280 $varValue,
281 ";")
282 ," ")
283};
284
285
286declare %private function env:var-decl-without-value(
287 $env as element(fots:environment)?,
288 $envCase as element(fots:environment)?
289) as xs:string?
290{
291 string-join(
292 (for $param in ($env/fots:param, $envCase/fots:param)
293 let $select := $param/@select
294 let $type := $param/@as
295 where (empty($select) and
296 empty($param[@declared="true"]))
297 return concat("declare variable $",
298 $param/@name,
299 ((concat(" as ", $type)))[$type],
300 " external;"),
301 for $source in ($env/fots:source, $envCase/fots:source)
302 let $role := $source/@role
303 where starts-with($role,"$")
304 return concat("declare variable ",
305 $role,
306 " external;"))
307 ," ")
308};
309
310
311(:~
312 : Returns the string for setting the context item if needed.
313 : @param $env environment.
314 : @param $envBaseURI test base URI of the environment.
315 : @return the string for setting the context item if needed.
316 :)
317declare function env:set-context-item(
318 $env as element(fots:environment)?,
319 $envBaseURI as xs:anyURI?
320) as xs:string? {
321 if (exists($env/fots:source[@role = "."]))
322 then string-join((env:declare-context-item($env, $envBaseURI),
323 'xqxq:bind-context-item($queryID, $contextItem);')
324 ,"&#xA;")
325 else ()
326};
327
328
329declare %private function env:declare-context-item(
330 $env as element(fots:environment)?,
331 $envBaseURI as xs:anyURI?
332) as xs:string
333{
334 let $ciURI := resolve-uri($env/fots:source[@role = "."]/@file, $envBaseURI)
335 return
336 if(empty($env/fots:source[@validation = "strict"]))
337 then concat('variable $contextItem := doc("', $ciURI, '");')
338 else string-join(
339 ("&#xA;",
340 "variable $contextItemQuery := xqxq:prepare-main-module('",
341 env:get-schema-import($env),
342 concat('validate { doc("', $ciURI, '")', "}',", " "),
343 "resolver:url-resolver#2, ());",
344 "variable $contextItem := xqxq:evaluate($contextItemQuery);")
345 ,"&#xA;")
346};
347
348
349(:~
350 : Returns the strings for variable binding in XQXQ.
351 :
352 : @param $env the environment of the catalog/test-set (given with 'ref').
353 : @param $envBaseURI the relative URI for the environment.
354 : @return the strings for variable binding in XQXQ.
355 :)
356declare function env:set-variables(
357 $env as element(fots:environment)?,
358 $envBaseURI as xs:anyURI
359) as xs:string?
360{
361 if(empty($env))
362 then ()
363 else
364 let $srcNames := for $source in $env/fots:source
365 where starts-with(data($source/@role),"$")
366 return substring-after(data($source/@role),"$"),
367 $srcValues := for $srcName in $srcNames
368 return concat('doc("',
369 resolve-uri($env/fots:source[@role = concat("$",$srcName)]/@file, $envBaseURI),
370 '")')
371 return
372 string-join(
373 (for $srcName in $srcNames
374 let $index := index-of($srcNames, $srcName)
375 return
376 concat('xqxq:bind-variable( $queryID, xs:QName("', $srcName, '")', ', ',
377 $srcValues[$index], ');'),
378 for $param in $env/fots:param
379 let $select:= $param/@select
380 let $file := $env/fots:source[@uri = translate($select, "'", "")]/@file
381 let $varValue := if(starts-with($select, "'") and
382 ends-with($select, "'") and
383 exists($file))
384 then concat('"',
385 resolve-uri($file, $envBaseURI),
386 '"')
387 else $select
388 let $varName := $param/@name
389 where (exists($select) and
390(: if there is an attribute 'declared' set to true, this means that the variable
391 is declared within the 'test' itself :)
392 exists($param[@declared="true"]))
393 return
394 concat('xqxq:bind-variable( $queryID, xs:QName("',
395 $param/@name,
396 '")', ', ',
397 $varValue, ');'))
398 , "&#xA;")
399};
400
401
402declare %private function env:get-schema-import (
403 $env as element(fots:environment)?
404) as xs:string
405{
406 if (empty($env))
407 then ""
408 else
409 let $namespace := $env/fots:namespace[@uri = data($env/fots:schema/@uri)]
410 let $prefix as xs:string := if(exists($namespace))
411 then xs:string(data($namespace/@prefix))
412 else "p"
413 return
414 if($prefix = "")
415 then concat('import schema default element namespace "',
416 $env/fots:schema/@uri,
417 '";&#xA;')
418 else concat('import schema namespace ',
419 $prefix,
420 ' = "',
421 $env/fots:schema/@uri,
422 '";&#xA;')
423};
424
425
426(:~
427 : Returns the XQXQ URL resolver declaration.
428 : @param $case the test case.
429 : @param $env the environment.
430 : @param $envBaseURI URI of the environment.
431 : @param $testSetBaseURI URI to the test set that defines the test case.
432 : @return the XQXQ URL resolver declaration.
433 :)
434declare function env:resolver(
435 $case as element(fots:test-case),
436 $env as element(fots:environment)?,
437 $envBaseURI as xs:anyURI?,
438 $testSetBaseURI as xs:anyURI
439) as xs:string?
440{
441 let $envSchema := $env/fots:schema,
442 $tcSchema := $case/fots:environment/fots:schema,
443 $schemas := ($envSchema, $tcSchema),
444 $modules := $case/fots:module,
445 $resources := ($env/fots:resource, $case/fots:environment/fots:schema)
446 return
447 if (empty($schemas) and empty($modules) and empty($resources))
448 then ()
449 else string-join(
450 ("declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';",
451 $env:hof,
452 "declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {",
453 "switch($entity)",
454 if (exists($schemas))
455 then string-join(("case 'schema'",
456 " return switch($namespace)",
457 (for $schema in $envSchema
458 return concat(" case '",
459 data($schema/@uri),
460 "' return doc('",
461 resolve-uri($schema/@file, $envBaseURI),
462 "')"),
463 for $schema in $tcSchema
464 return concat(" case '",
465 data($schema/@uri),
466 "' return doc('",
467 resolve-uri($schema/@file, $testSetBaseURI),
468 "')")),
469 " default return ()"),
470 "&#xA;")
471 else (),
472 if (exists($modules))
473 then string-join(("case 'module'",
474 " return switch($namespace)",
475 for $module in $modules
476 return concat(" case '",
477 data($module/@uri),
478 "' return unparsed-text('",
479 resolve-uri($module/@file, $testSetBaseURI),
480 "') "),
481 " default return ()"),
482 "&#xA;")
483 else (),
484 if (exists($resources)) then
485 string-join(("case ''",
486 " return switch($namespace)",
487 for $resource in $resources
488 return concat(" case '",
489 data($resource/@uri),
490 "' return unparsed-text('",
491 resolve-uri($resource/@file, $envBaseURI),
492 "'",
493 if(exists($resource/@encoding))
494 then concat (",'",
495 data($resource/@encoding),
496 "'")
497 else (),
498 ") "),
499 " default return ()")
500 ,"&#xA;")
501 else ()
502 , "default return ()","};"),
503 "&#xA;")
504};
505
506
507(:~
508 : Checks the dependencies according to the Zorba manifest.
509 :
510 : @param $deps the dependencies of the test set and test case
511 : @param $zorbaManifest Zorba manifest document.
512 : @return if true empty string, otherwise returns a string with the
513 : dependencies that were not matched.
514 :)
515declare function env:check-dependencies(
516 $deps as element(fots:dependency)*,
517 $zorbaManifest
518) as xs:string*
519{
520 if(empty($deps))
521 then ()
522 else
523 for $dep in $deps
524 let $satisfied := if(exists($dep/@satisfied))
525 then data($dep/@satisfied)
526 else "true"
527 let $zorbaDep := $zorbaManifest//fots:dependency[ @type = $dep/@type and
528 @value = $dep/@value and
529 @satisfied = $satisfied]
530 return
531 if(empty($zorbaDep))
532 then concat("Dependency (type=",
533 $dep/@type,
534 ", value=",
535 $dep/@value,
536 ", satisfied=",
537 $satisfied,
538 ") was not met. ")
539 else ()
540};
541
542
543(:~
544 : Retrieves the environment from a test-set/catalog given an environment name.
545 : @param $catalog FOTS catalog file.
546 : @param $testSet test set.
547 : @param $envName name of the environment.
548 : @return the environment with the given name.
549 :)
550declare function env:get-environment (
551 $catalog,
552 $testSet as element (fots:test-set),
553 $envName as xs:string
554) as element(fots:environment)?
555{
556 let $envTestSet := $testSet/test-set//environment[@name = $envName]
557 return
558 if (empty($envTestSet))
559 then $catalog/catalog//environment[@name = $envName]
560 else $envTestSet
561};
0562
=== 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:57:23 +0000
@@ -0,0 +1,36 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Zorba FOTS driver errors
19 : @author Sorin Nasoi
20 :)
21
22module namespace err =
23 "http://www.zorba-xquery.com/fots-driver/errors";
24
25(:~
26 : Errors namespace URI.
27:)
28declare variable $err:errNS as xs:string :=
29 "http://www.zorba-xquery.com/fots-driver/errors";
30
31(:~
32 : xs:QName with
33 : namespace URI = "http://www.w3.org/2010/09/qt-fots-catalog/errors"
34 : and local name "err:errNA"
35:)
36declare variable $err:errNA as xs:QName := fn:QName($err:errNS, "check:errNA");
037
=== 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:57:23 +0000
@@ -0,0 +1,565 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Zorba FOTS driver evaluate
19 : @author Sorin Nasoi
20 :)
21
22module namespace eval =
23 "http://www.zorba-xquery.com/fots-driver/evaluate";
24
25import schema namespace output =
26 "http://www.w3.org/2010/xslt-xquery-serialization";
27
28import module namespace xqxq =
29 "http://www.zorba-xquery.com/modules/xqxq";
30import module namespace schema =
31 "http://www.zorba-xquery.com/modules/schema";
32
33import module namespace fots-err =
34 "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
35import module namespace util =
36 "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
37
38declare namespace err =
39 "http://www.w3.org/2005/xqt-errors";
40declare namespace fots =
41 "http://www.w3.org/2010/09/qt-fots-catalog";
42
43declare namespace ann =
44 "http://www.zorba-xquery.com/annotations";
45
46declare namespace features =
47 "http://www.zorba-xquery.com/options/features";
48declare option features:enable "hof";
49
50(:~
51 : Checks if the result matches the assertions.
52 : @param $result actual result.
53 : @param $expResult expected result.
54 : @param $showResult is true the verbose mode is assumed.
55 : @return the results of assertion evaluations.
56 :)
57declare %ann:sequential function eval:result(
58 $result as item()*,
59 $expResult as element(),
60 $showResult as xs:boolean?
61) as element()? {
62 let $err := eval:check-assertion($result,
63 $expResult,
64 (),
65 "",
66 $showResult)
67 return if(empty($err))
68 then ()
69 else
70 <out>
71 <expected-result>{$expResult}</expected-result>
72 {
73 if($showResult)
74 then (<result>{$result}</result>,
75 <errors>{$err}</errors>)
76 else ()
77 }
78 </out>
79};
80
81(:~
82 : Checks if the error found matches the expected error (if any).
83 : @param $result actual result.
84 : @param $expResult expected result.
85 : @param $code err:code.
86 : @param $errorDescription err:description.
87 : @param $showResult is true the verbose mode is assumed.
88 : @return the results of error evaluation.
89 :)
90declare %ann:sequential function eval:error(
91 $result as item()*,
92 $expResult as element(),
93 $code as xs:QName?,
94 $errorDescription as xs:string?,
95 $showResult as xs:boolean?
96) as xs:string* {
97 if(empty($result)) then
98 let $err := eval:error-code($code,
99 $errorDescription,
100 $expResult)
101 return $err
102 else
103 concat("Expected error &#xA;",
104 data($expResult/@code),
105 ",&#xA; found result ",
106 if ($showResult)
107 then string-join(util:serialize-result($result),' ')
108 else ())
109};
110
111declare %private %ann:sequential function eval:error-code(
112 $code as xs:QName?,
113 $errorDescription as xs:string?,
114 $expResult as element()
115) as xs:string* {
116 let $assertName := local-name($expResult)
117 return
118 if( $assertName = "error")
119 then
120 if (exists($expResult[@code = "*"]) or
121 exists($expResult[@code = local-name-from-QName($code)]))
122 then ()
123 else concat("Expected error: ",
124 data($expResult/@code),
125 ". Found error: ",
126 local-name-from-QName($code))
127 else if (($assertName = "any-of") or ($assertName = "all-of"))
128 then eval:check-assertion((),
129 $expResult,
130 $code,
131 $errorDescription,
132 fn:true())
133 else concat("Expected result: &#xA;",
134 data($expResult),
135 ".&#xA; Found error ",
136 local-name-from-QName($code),
137 " - ",
138 $errorDescription)
139};
140
141declare %private %ann:sequential function eval:check-assertion(
142 $result as item()*,
143 $expResult as element(),
144 $code as xs:QName?,
145 $errorDescription as xs:string?,
146 $showResult as xs:boolean?
147) as xs:string* {
148 let $test := local-name($expResult)
149 return switch($test)
150 case 'all-of'
151 return eval:assert-all-of($result,
152 $expResult,
153 $code,
154 $errorDescription,
155 $showResult)
156 case 'any-of'
157 return eval:assert-any-of($result,
158 $expResult,
159 $code,
160 $errorDescription,
161 $showResult)
162 case 'assert'
163 return eval:assert($result,
164 $expResult)
165 case 'assert-count'
166 return eval:assert-count($result,
167 $expResult)
168 case 'assert-deep-eq'
169 return eval:assert-deep-eq($result,
170 $expResult)
171 case 'assert-empty'
172 return eval:assert-empty($result)
173 case 'assert-eq'
174 return eval:assert-eq($result,
175 $expResult)
176 case 'assert-false'
177 return eval:assert-false($result)
178 case 'assert-permutation'
179 return eval:assert-permutation($result,
180 $expResult)
181 case 'assert-xml'
182 return eval:assert-xml($result,
183 $expResult)
184 case 'assert-serialization-error'
185 return eval:assert-serialization-error($result,
186 $expResult)
187 case 'assert-string-value'
188 return eval:assert-string-value($result,
189 $expResult)
190 case 'assert-true'
191 return eval:assert-true($result)
192 case 'assert-type'
193 return eval:assert-type($result,
194 $expResult)
195 case 'serialization-matches'
196 return eval:serialization-matches($result,
197 $expResult)
198 case 'error'
199 return eval:error($result,
200 $expResult,
201 $code,
202 $errorDescription,
203 $showResult)
204 default
205 return error($fots-err:errNA,
206 "&#xA;The requested assertion type is not implemented.")
207};
208
209(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_any-of :)
210declare %private %ann:sequential function eval:assert-any-of(
211 $result as item()*,
212 $expResult as element(),
213 $code as xs:QName?,
214 $errorDescription as xs:string?,
215 $showResult as xs:boolean
216) as xs:string? {
217 let $results :=
218 for $tmp in $expResult/*
219 return <result>{
220 for $r in eval:check-assertion($result,
221 $tmp,
222 $code,
223 $errorDescription,
224 $showResult)
225 return <item>{$r}</item>
226 } </result>
227 where every $result in $results satisfies $result/item
228 return concat("&#xA;Assert-any-of returned: ",
229 string-join(util:serialize-result($results/data(item)), ' '))
230};
231
232(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_all-of :)
233declare %private %ann:sequential function eval:assert-all-of(
234 $result as item()*,
235 $expResult as element(),
236 $code as xs:QName?,
237 $errorDescription as xs:string?,
238 $showResult as xs:boolean
239) as xs:string* {
240 for $tmp in $expResult/*
241 return eval:check-assertion($result,
242 $tmp,
243 $code,
244 $errorDescription,
245 $showResult)
246};
247
248(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert :)
249declare %private %ann:sequential function eval:assert(
250 $result as item()*,
251 $expResult as element()
252) as xs:string? {
253 try {
254 {
255 variable $queryText := concat(
256 "xquery version '3.0';",
257 "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
258 "declare option o:enable 'hof';",
259 "declare variable $result external; ",
260 xs:string($expResult));
261 variable $queryKey := xqxq:prepare-main-module($queryText),
262 $queryKeyResult := xqxq:bind-variable($queryKey,
263 xs:QName('result'),
264 $result),
265 $queryResult := xqxq:evaluate($queryKey);
266
267 if($queryResult)
268 then ()
269 else concat("Assertion ", $expResult, " failed")
270 }
271 } catch * {
272 concat("&#xA;Assertion '",
273 $expResult,
274 "'&#xA; failed with error ",
275 $err:code, " : ", $err:description)
276 }
277};
278
279(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-count :)
280declare %private function eval:assert-count(
281 $result as item()*,
282 $expResult as element()
283) as xs:string? {
284 if(count($result) eq xs:integer($expResult))
285 then ()
286 else "Actual number of items is different than the expected number of items."
287};
288
289(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-deep-eq :)
290declare %private %ann:sequential function eval:assert-deep-eq(
291 $result as item()*,
292 $expResult as element()
293) as xs:string? {
294 try {
295 {
296 variable $queryText := concat(
297 "xquery version '3.0';",
298 "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
299 "declare option o:enable 'hof';",
300 "declare variable $x external;",
301 "let $y := (",string(data($expResult)),") return ",
302 "every $i in 1 to max((count($x),count($y))) satisfies deep-equal($x[$i],$y[$i])");
303 variable $queryKey := xqxq:prepare-main-module($queryText),
304 $queryKeyResult := xqxq:bind-variable($queryKey,
305 xs:QName('x'),
306 $result),
307 $queryResult := xqxq:evaluate($queryKey);
308 if($queryResult)
309 then ()
310 else concat("&#xA;Result is not deep-equal to '", $expResult, "'&#xA;")
311 }
312 } catch * {
313 concat("&#xA;Assert-deep-eq '",
314 $expResult,
315 "'&#xA; failed with error ",
316 $err:code,
317 " : ",
318 $err:description)
319 }
320};
321
322(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-empty :)
323declare %private function eval:assert-empty(
324 $result as item()*
325) as xs:string? {
326 if(empty($result))
327 then ()
328 else "&#xA;Result is not empty as expected"
329};
330
331(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-eq :)
332declare %private %ann:sequential function eval:assert-eq(
333 $result as item()*,
334 $expResult as element()
335) as xs:string? {
336 try {
337 {
338 variable $type := if (empty($result[1]) or (count($result) gt 1))
339 then ()
340 else
341 let $tmp := xs:string(schema:schema-type($result[1]))
342(: add exception for the types defined in schemas available in the environment of the tests :)
343 return
344 if (starts-with($tmp, 'xs:'))
345 then $tmp
346 else ();
347 variable $queryText := concat(
348 "declare variable $x external;",
349 "$x eq ",
350 if (starts-with(data($expResult), $type))
351 then data($expResult)
352 else concat($type,"(", data($expResult), ")"));
353 variable $queryKey := xqxq:prepare-main-module($queryText);
354
355 xqxq:bind-variable($queryKey,
356 xs:QName('x'),
357 $result);
358 variable $queryResult := xqxq:evaluate($queryKey);
359 if($queryResult)
360 then ()
361 else concat("&#xA;Assert-eq: Result '",
362 string-join(util:serialize-result($result),' '),
363 "' &#xA;doesn't match expected item '",
364 xs:string($expResult),
365 "'.")
366 }
367 } catch * {
368 concat("&#xA;Comparison to '",
369 $expResult/text(),
370 "' failed with error: ",
371 $err:code,
372 " : ",
373 $err:description)
374 }
375};
376
377(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-true :)
378declare %private function eval:assert-true(
379 $result as item()*
380) as xs:string? {
381 if($result eq fn:true())
382 then ()
383 else "&#xA;Query doesn't evaluate to true."
384};
385
386(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-false :)
387declare %private function eval:assert-false(
388 $result as item()*
389) as xs:string? {
390 if($result eq fn:false())
391 then ()
392 else "&#xA;Query doesn't evaluate to false."
393};
394
395(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-permutation :)
396declare %private %ann:sequential function eval:assert-permutation(
397 $result as item()*,
398 $expResult as element()
399) as xs:string? {
400 try {
401 {
402 variable $queryText := concat(
403 "xquery version '3.0';",
404 "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
405 "declare option o:enable 'hof';",
406 "declare variable $x external;",
407 "let $y := (",string(data($expResult)),") return ",
408 (: if count(intersection(M1,M2)) = count(union(M1,M2)) = count(M1) then the sequences are identical :)
409 "(count(distinct-values($x[ . = $y])) = count(distinct-values(($x, $y)))) = count(distinct-values($x))");
410 variable $queryKey := xqxq:prepare-main-module($queryText),
411 $queryKeyResult := xqxq:bind-variable($queryKey,
412 xs:QName('x'),
413 $result),
414 $queryResult := xqxq:evaluate($queryKey);
415 if($queryResult)
416 then ()
417 else concat("&#xA;Result isn't a permutation of '",
418 $expResult,
419 "'&#xA;")
420 }
421 } catch * {
422 concat("&#xA;Assert-permutation failed with error: ",
423 $err:code,
424 " : ",
425 $err:description)
426 }
427};
428
429(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-xml :)
430declare %private function eval:assert-xml(
431 $result as item()*,
432 $expResult as element()
433) {
434(:TODO call xml-canonicalization after bug #1076919 is implemented.:)
435 try {
436 let $serRes := util:serialize-result($result),
437 $result1 as xs:string := string-join($serRes,''),
438 $result2 as xs:string := string-join($serRes,' ')
439 return
440 if((normalize-space($result1) eq normalize-space(string($expResult))) or
441 (normalize-space($result2) eq normalize-space(string($expResult))))
442 then ()
443 else concat("&#xA;Result '",
444 $result1,
445 "'&#xA; is different from the expected result &#xA;'",
446 string($expResult),
447 "'.")
448 } catch * {
449 concat("&#xA;Assert-xml failed with error:",
450 $err:code,
451 " : ",
452 $err:description)
453 }
454};
455
456(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-serialization-error :)
457declare %private %ann:sequential function eval:assert-serialization-error(
458 $result as item()*,
459 $expResult as element()
460) as xs:string? {
461 try {
462 let $serializedResult as xs:string := string-join(
463 util:serialize-result($result), '')
464 return
465 concat("&#xA;Expected serialization error but got result: ",
466 $serializedResult)
467 } catch * {
468 eval:error((),
469 $expResult,
470 $err:code,
471 $err:description,
472 fn:true())
473 }
474};
475
476(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_serialization-matches :)
477declare %private function eval:serialization-matches(
478 $result as item()*,
479 $expResult as element()
480) as xs:string? {
481 let $serResult := string-join(util:serialize-result($result,
482 $util:serParamXml),
483 ''),
484 $serExpResult := string-join(util:serialize-result(data($expResult),
485 $util:serParamXml),
486 '')
487 let $matchesFlags := data($expResult/@flags)
488 return
489 if(exists($matchesFlags))
490 then
491 if(matches($serResult, $serExpResult, $matchesFlags))
492 then ()
493 else concat("&#xA;Expected '",
494 $serResult,
495 "'&#xA; does not match &#xA;'",
496 $serExpResult,
497 "' with flags '",
498 $matchesFlags,
499 "'")
500 else
501 if(matches($serResult, $serExpResult))
502 then ()
503 else concat("&#xA;Expected ",
504 $serResult,
505 "'&#xA; does not match &#xA;'",
506 $serExpResult,
507 "'")
508};
509
510(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-string-value :)
511declare %private function eval:assert-string-value(
512 $result as item()*,
513 $expResult as element()
514) as xs:string? {
515 try {
516 let $serRes := string-join(util:serialize-result($result), ' '),
517 $res := if (empty($expResult[@normalize-space="true"]))
518 then $serRes
519 else normalize-space($serRes),
520 $expRes := if (empty($expResult[@normalize-space="true"]))
521 then xs:string($expResult)
522 else normalize-space(xs:string($expResult))
523 return
524 if($res eq $expRes)
525 then ()
526 else concat("&#xA;Expected '",
527 $expRes,
528 "'&#xA; found &#xA;'",
529 $res,
530 "'")
531 } catch * {
532 concat("&#xA;String-value failed with error: ",
533 $err:code,
534 " : ",
535 $err:description)
536 }
537};
538
539(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-type :)
540declare %private %ann:sequential function eval:assert-type(
541 $result as item()*,
542 $expResult as element()
543) as xs:string? {
544 try {
545 {
546 variable $queryText := concat( "declare variable $x external; $x instance of ",
547 data($expResult));
548 variable $queryKey := xqxq:prepare-main-module($queryText),
549 $queryKeyResult := xqxq:bind-variable($queryKey,
550 xs:QName('x'),
551 $result),
552 $queryResult := xqxq:evaluate($queryKey);
553 if($queryResult)
554 then ()
555 else concat("&#xA;Result doesn't have type '",
556 data($expResult),
557 "'")
558 }
559 } catch * {
560 concat("&#xA;Assert-type failed with error: ",
561 $err:code,
562 " : ",
563 $err:description)
564 }
565};
0566
=== 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:57:23 +0000
@@ -0,0 +1,752 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Zorba FOTS driver
19 : @author Sorin Nasoi
20 :)
21
22module namespace driver =
23 "http://www.zorba-xquery.com/fots-driver";
24
25import module namespace functx =
26 "http://www.functx.com/";
27
28import module namespace xqxq =
29 "http://www.zorba-xquery.com/modules/xqxq";
30import module namespace datetime =
31 "http://www.zorba-xquery.com/modules/datetime";
32
33import module namespace eval =
34 "http://www.zorba-xquery.com/fots-driver/evaluate" at "evaluate.xq";
35import module namespace env =
36 "http://www.zorba-xquery.com/fots-driver/environment" at "environment.xq";
37import module namespace util =
38 "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
39import module namespace fots-err =
40 "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
41
42declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
43
44declare namespace err =
45 "http://www.w3.org/2005/xqt-errors";
46declare namespace fots =
47 "http://www.w3.org/2010/09/qt-fots-catalog";
48
49declare namespace ann =
50 "http://www.zorba-xquery.com/annotations";
51
52(:~
53 : Loops through the FOTS catalog and returns all available test set names.
54 : @param $fotsPath path to the FOTS catalog file.
55 : @param $testSetPrefixes name/criteria for the test sets
56 : (empty string means all).
57 : @return available FOTS test sets.
58 :)
59declare %ann:nondeterministic function driver:list-test-sets(
60 $fotsPath as xs:string,
61 $testSetPrefixes as xs:string*
62) as xs:string* {
63 let $doc := doc(resolve-uri($fotsPath))
64 return
65 if(string-join($testSetPrefixes,'') = '')
66 then
67 for $testSet in $doc/fots:catalog/fots:test-set
68 return data($testSet/@name)
69 else
70 for $prefix in $testSetPrefixes
71 for $testSet in $doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)]
72 return data($testSet/@name)
73};
74
75declare %private function driver:matches-dependency(
76 $dependencies as element(fots:dependency)*,
77 $filter as xs:string
78) as xs:boolean {
79 let $filter := tokenize($filter, '_')
80 let $depValue := $filter[1]
81 let $depSatisfied as xs:string := if(exists($filter[2]) and
82 ($filter[2] = 'true' or $filter[2]='false'))
83 then $filter[2]
84 else 'true'
85 return
86 if(xs:boolean($depSatisfied))
87
88 (: $depSatisfied = 'true' :)
89 then (exists($dependencies[@value = $depValue and
90 @satisfied = $depSatisfied]) or
91 exists($dependencies[@value = $depValue and empty(@satisfied)]))
92
93 (: $depSatisfied = 'false' :)
94 else exists($dependencies[@value = $depValue and
95 @satisfied = $depSatisfied])
96};
97
98(:~
99 : Loops through the given test set and returns the test cases that have the
100 : given dependencies defined.
101 : @param $testSet test set document.
102 : @param $dependency defined dependency
103 : (empty string means all test cases).
104 : @return matching test case names.
105 :)
106declare function driver:list-test-cases(
107 $testSetDoc as document-node(),
108 $dependency as xs:string*
109) as xs:string* {
110 if(string-join($dependency,'') = '')
111 then $testSetDoc//fots:test-case/@name
112 else for $testCase in $testSetDoc//fots:test-case
113 let $cond := driver:matches-dependency(($testSetDoc/fots:test-set/fots:dependency,
114 $testCase/fots:dependency),
115 $dependency)
116 where $cond
117 return$testCase/@name
118
119};
120
121(:~
122 : Loops through the given test sets and returns the corresponding test cases.
123 : @param $fotsPath path to the FOTS catalog file.
124 : @param $testSetPrefixes name/criteria for the test sets
125 : (empty string means all test cases).
126 : @param $dependency type of dependency that has to be met
127 : (empty string means all test cases).
128 : @return available FOTS test cases.
129 :)
130declare %ann:nondeterministic function driver:list-test-cases(
131 $fotsPath as xs:string,
132 $testSetPrefixes as xs:string*,
133 $dependency as xs:string*
134) as xs:string* {
135 let $doc := doc(resolve-uri($fotsPath)),
136 $baseUri:= resolve-uri(util:parent-folder($fotsPath))
137 return
138 if(string-join($testSetPrefixes,'') = '')
139 then
140 for $testSet in $doc/fots:catalog/fots:test-set
141 let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
142 return driver:list-test-cases($testSetDoc, $dependency)
143 else
144 for $prefix in $testSetPrefixes
145 for $testSet in $doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)]
146 let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
147 return driver:list-test-cases($testSetDoc, $dependency)
148};
149
150(:~
151 : Loops through the given test sets and returns the corresponding test cases.
152 : @param $fotsPath path to the FOTS catalog file.
153 : @param $testSetPrefixes name/criteria for the test sets
154 : (empty string means all test cases).
155 : @param $testCasePrefixes name/criteria for the test cases
156 : (empty string means all test cases).
157 : @param $dependency type of dependency that has to be met
158 : (empty string means all test cases).
159 : @return available FOTS test cases.
160 :)
161declare %ann:nondeterministic function driver:list-test-cases(
162 $fotsPath as xs:string,
163 $testSetPrefixes as xs:string*,
164 $testCasePrefixes as xs:string*,
165 $dependency as xs:string*
166) as xs:string* {
167 let $doc := doc(resolve-uri($fotsPath)),
168 $baseUri:= resolve-uri(util:parent-folder($fotsPath)),
169 $testCaseNames := driver:list-test-cases($fotsPath,
170 $testSetPrefixes,
171 $dependency)
172 return
173 for $prefix in $testCasePrefixes
174 return
175 for $name in $testCaseNames
176 where starts-with($name,
177 $prefix)
178 return $name
179};
180
181(:~
182 : Loops through all the test cases and returns those that have a 'test' node
183 : that matches given pattern using given flags.
184 : @param $fotsPath path to the FOTS catalog file.
185 : @param $pattern pattern.
186 : @param $flags flags.
187 : @return available FOTS test cases matching given pattern and flags.
188 :)
189declare %ann:nondeterministic function driver:list-matching-test-cases(
190 $fotsPath as xs:string,
191 $pattern as xs:string,
192 $flags as xs:string?
193) as xs:string* {
194 let $doc := doc(resolve-uri($fotsPath)),
195 $baseUri:= resolve-uri(util:parent-folder($fotsPath))
196 return
197 for $testSet in $doc/fots:catalog/fots:test-set
198 let $uri := resolve-uri($testSet/@file, $baseUri),
199 $testSetDoc := doc($uri)
200 for $testCase in $testSetDoc//test-case
201 where matches(util:get-value($testCase,
202 util:parent-folder($uri),
203 "test"),
204 $pattern,
205 $flags)
206 return
207 concat(resolve-uri($testSet/@file, $baseUri),
208 ", test name:",
209 data($testCase/@name))
210};
211
212declare %private function driver:list-assertions(
213 $case as element(fots:test-case)
214) as xs:string* {
215 distinct-values(for $assert in $case/result/descendant-or-self::*
216 return local-name-from-QName(node-name($assert)))
217};
218
219(:~
220 : Loops through the FOTS catalog and evaluates all test cases that have
221 : a certain assert-type.
222 : This is useful for testing the implementation of a certain assert type.
223 : @param $FOTSCatalogFilePath path to the FOTS catalog file.
224 : @param $FOTSZorbaManifestPath the path to the file that describes optional
225 : features and implementation defined items in Zorba.
226 : @param $testSetPrefixes name/criteria for the test sets (empty string
227 : means all).
228 : @param $testCasePrefixes name/criteria for the test cases (empty string
229 : means all).
230 : @param $exceptedTestCases lists of test cases that should not be run(empty
231 : string means all tests will be run).
232 : @param $exceptedTestSets lists of test sets that should not be run(empty
233 : string means all tests will be run).
234 : @param $assert lists of tests that contain a certain assert-type(empty
235 : string means all tests will be run).
236 : @param $verbose if set to TRUE it will also output the actual failures.
237 : @param $showResult if set to TRUE it will also show the actual result of the
238 : Query run.
239 : @return an element containing all failed tests
240 :)
241declare %ann:sequential function driver:run-fots(
242 $FOTSCatalogFilePath as xs:string,
243 $FOTSZorbaManifestPath as xs:string,
244 $testSetPrefixes as xs:string*,
245 $testCasePrefixes as xs:string*,
246 $exceptedTestCases as xs:string*,
247 $exceptedTestSets as xs:string*,
248 $assert as xs:string*,
249 $verbose as xs:boolean,
250 $showResult as xs:boolean
251) as element(fots:test-cases) {
252 try {
253 let $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
254 "Path to FOTS catalog.xml set to: ")),
255 $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
256 "Path to FOTSZorbaManifest set to:"))
257 return driver:run($FOTSCatalog,
258 resolve-uri(util:parent-folder($FOTSCatalogFilePath)),
259 $FOTSZorbaManifest,
260 $testSetPrefixes,
261 $testCasePrefixes,
262 $exceptedTestCases,
263 $exceptedTestSets,
264 trace($assert, "The filter for 'assert name' set to: "),
265 trace($verbose, "'Verbose' parameter set to: "),
266 $showResult)
267 }
268 catch * {
269 error($err:code,
270 concat("&#xA;Please make sure the passed 'fotsPath' points to the",
271 "exact location of the FOTS catalog.xml:&#xA;",
272 resolve-uri($FOTSCatalogFilePath),
273 "&#xA;and that the passed 'fotsZorbaManifestPath' points to",
274 "a file in the same folder as cli.xq:&#xA;",
275 resolve-uri($FOTSZorbaManifestPath)))
276 }
277};
278
279(:~
280 : Loops through the FOTS catalog and evaluates all test cases
281 :
282 : @param $FOTSCatalog the FOTS catalog.xml file.
283 : @param $FOTSZorbaManifest the file that describes optional features and
284 : implementation defined items in Zorba.
285 : @param $testSetPrefixes name/criteria for the test sets (empty string means
286 : all).
287 : @param $testCasePrefixes name/criteria for the test cases (empty string
288 : means all).
289 : @param $exceptedTestCases lists of test cases that should not be run(empty
290 : string means all tests will be run).
291 : @param $exceptedTestSets lists of test sets that should not be run(empty
292 : string means all tests will be run).
293 : @param $assert lists of tests that contain a certain assert-type(empty
294 : string means all tests will be run).
295 : @param $verbose if set to TRUE it will also output the actual failures.
296 : @param $showResult if set to TRUE it will also show the actual result of the
297 : Query run.
298 : @return an element containing all failed tests
299 :)
300declare %ann:sequential function driver:run(
301 $FOTSCatalog as document-node(),
302 $catalogBaseURI as xs:anyURI,
303 $FOTSZorbaManifest as document-node(),
304 $testSetPrefixes as xs:string*,
305 $testCasePrefixes as xs:string*,
306 $exceptedTestCases as xs:string*,
307 $exceptedTestSets as xs:string*,
308 $assert as xs:string*,
309 $verbose as xs:boolean,
310 $showResult as xs:boolean
311) as element(fots:test-cases) {
312 <test-cases>{
313 let $catalogTestSetNames := $FOTSCatalog//fots:test-set/@name,
314 $testSetNames := if ($testSetPrefixes = '')
315 then functx:value-except($catalogTestSetNames,
316 $exceptedTestSets)
317 else functx:value-except(
318 functx:value-intersect($testSetPrefixes,
319 $catalogTestSetNames),
320 $exceptedTestSets)
321 for $testSetName in $testSetNames
322 let $testSet := $FOTSCatalog//fots:test-set[@name=$testSetName],
323 $testSetURI := resolve-uri($testSet/@file,
324 $catalogBaseURI),
325 $testSetDoc := doc($testSetURI),
326 $depMet as xs:string*:= env:check-dependencies($testSetDoc/fots:test-set/fots:dependency,
327 $FOTSZorbaManifest)
328 return
329 if(exists($depMet))
330 then <test-set name="{$testSetName}">
331 {
332 for $testCase in $testSetDoc/fots:test-set/fots:test-case
333 let $envName := data($testCase/fots:environment/@ref),
334 $envTestSet := $testSetDoc/fots:test-set/fots:environment[@name = $envName],
335 $envCatalog := $FOTSCatalog/fots:catalog/fots:environment[@name = $envName],
336 $shouldRun := if ($testCasePrefixes = '')
337 then functx:value-except(xs:string(data($testCase/@name)),
338 $exceptedTestCases)
339 else functx:value-except(
340 functx:value-intersect(data($testCase/@name),
341 $testCasePrefixes),
342 $exceptedTestCases),
343 (:true if the tests-case has an assertion type that is requested :)
344 $hasReqAssert := (($assert = '') or
345 exists(functx:value-intersect(
346 driver:list-assertions($testCase),
347 $assert)))
348 where $shouldRun and $hasReqAssert
349 return
350 driver:not-applicable($testCase,
351 $envTestSet,
352 string-join($depMet,''),
353 $verbose)
354 }</test-set>
355 else <test-set name="{$testSetName}">
356 {
357 for $testCase in $testSetDoc/fots:test-set/fots:test-case
358 let $envName := data($testCase/fots:environment/@ref),
359 $envTestSet := $testSetDoc/fots:test-set/fots:environment[@name = $envName],
360 $envCatalog := $FOTSCatalog/fots:catalog/fots:environment[@name = $envName],
361 $shouldRun := if ($testCasePrefixes = '')
362 then functx:value-except(xs:string(data($testCase/@name)),
363 $exceptedTestCases)
364 else functx:value-except(
365 functx:value-intersect(data($testCase/@name),
366 $testCasePrefixes),
367 $exceptedTestCases),
368 (:true if the tests-case has an assertion type that is requested :)
369 $hasReqAssert := (($assert = '') or
370 exists(functx:value-intersect(driver:list-assertions($testCase),
371 $assert)))
372 where $shouldRun and $hasReqAssert
373 return
374 if(exists(env:check-dependencies($testCase/fots:dependency,
375 $FOTSZorbaManifest)))
376 then driver:not-applicable( $testCase,
377 $envTestSet,
378 string-join(distinct-values(env:check-dependencies($testCase/fots:dependency,
379 $FOTSZorbaManifest)),
380 ''),
381 $verbose)
382 else if(empty($envTestSet))
383 then driver:test( $FOTSZorbaManifest,
384 $testCase,
385 $envCatalog,
386 $catalogBaseURI,
387 ($testCase/fots:dependency,
388 $testSetDoc/fots:test-set/fots:dependency),
389 $testSetName,
390 $testSetURI,
391 $verbose,
392 $showResult)
393 else driver:test( $FOTSZorbaManifest,
394 $testCase,
395 $envTestSet,
396 $testSetURI,
397 ($testCase/fots:dependency,
398 $testSetDoc/fots:test-set/fots:dependency),
399 $testSetName,
400 $testSetURI,
401 $verbose,
402 $showResult)
403 }</test-set>
404 }</test-cases>
405};
406
407(:~
408 : Creates the complete query that will be evaluated by adding the necessary
409 : XQXQ URL resolvers.
410 : @param $queryText the test-case/test after all the additional prolog
411 : statements were added.
412 : @param $case the test case.
413 : @param $env the environment.
414 : @param $envBaseURI URI of the environment.
415 : @param $testSetBaseURI URI of the test set that defines the test case.
416 : @return the query that will be evaluated.
417 :)
418declare %private function driver:create-XQXQ-query(
419 $queryText as xs:string,
420 $case as element(fots:test-case),
421 $env as element(fots:environment)?,
422 $envBaseURI as xs:anyURI?,
423 $testSetBaseURI as xs:anyURI
424) as xs:string {
425 let $resolver as xs:string? := env:resolver($case,
426 $env,
427 $envBaseURI,
428 $testSetBaseURI)
429 return string-join(
430 ("import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';",
431 if (exists($resolver))
432 then $resolver
433 else (),
434 (concat("variable $queryID := xqxq:prepare-main-module('",
435 "&#xA;",
436 replace($queryText,"'","''"),
437 "'",
438 "&#xA;",
439 if (exists($resolver))
440 then ", resolver:url-resolver#2, ());"
441 else ");")),
442 env:set-context-item($env, $envBaseURI),
443 env:set-context-item($case/fots:environment,
444 $testSetBaseURI),
445 env:set-variables($env,
446 $envBaseURI),
447 env:set-variables($case/environment,
448 $testSetBaseURI),
449 "xqxq:evaluate($queryID)"
450 ),
451 "&#xA;")
452};
453
454(:~
455 : XQXQ invoke.
456 : @param $xqxqQueryText the query that will be run.
457 : @param $case the test case.
458 : @return the result of running the query with XQXQ.
459 :)
460declare %private %ann:sequential function driver:xqxq-invoke(
461 $xqxqQueryText as xs:string,
462 $case as element(fots:test-case),
463 $showResult as xs:boolean?,
464 $testSetBaseURI as xs:anyURI
465) {
466 try {
467 {
468 variable $queryKey := xqxq:prepare-main-module($xqxqQueryText);
469 variable $queryResult := xqxq:evaluate-sequential($queryKey);
470 (:TODO check if this works:)
471 (:variable $expResult := util:get-value($case, $testSetBaseURI, "result");:)
472 eval:result($queryResult,
473 $case/fots:result/*,
474 $showResult)
475 }
476 } catch * {
477 eval:error((),
478 $case/fots:result/*,
479 $err:code,
480 $err:description,
481 $showResult)
482 }
483};
484
485(:~
486 : Runs a single test case.
487 :
488 : @param $FOTSZorbaManifest the file that describes optional features and
489 : implementation defined items in Zorba.
490 : @param $case test case.
491 : @param $env the environment.
492 : @param $envBaseURI the relative URI used to calculate the full URI for the
493 : different children of the environment that have a "file" attribute.
494 : @param $deps the dependencies that should be checked for given test case.
495 : @param $testSetName the name of the test set.
496 : @param $testSetBaseURI the URI of the test set.
497 : @param $verbose xs:boolean indicating if a result should be returned in case
498 : of success or not.
499 : @return the result of running the test case depending on $verbose.
500 :)
501declare %ann:sequential function driver:test(
502 $FOTSZorbaManifest as document-node(),
503 $case as element(fots:test-case),
504 $env as element(fots:environment)?,
505 $envBaseURI as xs:anyURI?,
506 $deps as element(fots:dependency)*,
507 $testSetName as xs:string?,
508 $testSetBaseURI as xs:anyURI,
509 $verbose as xs:boolean,
510 $showResult as xs:boolean?
511) as element(fots:test-case)? {
512(:TODO Cover the "(:%VARDECL%:)"when there are tests in FOTS that use it:)
513try {
514{
515 variable $queryName := trace(data($case/@name),
516 "processing test case :");
517
518 variable $test := util:get-value($case,
519 $testSetBaseURI,
520 "test");
521 variable $enableHOF := env:enable-HOF-feature(($deps, $case//fots:dependency),
522 $test);
523 variable $query := string-join((env:add-xquery-version-decl(($deps, $case//fots:dependency),
524 $test),
525 env:decl-def-elem-namespace($env,
526 $case/fots:environment),
527 env:decl-base-uri($env,
528 $case/fots:environment),
529 env:decl-namespaces($env,
530 $case,
531 $testSetBaseURI),
532 $enableHOF,
533 env:decl-decimal-formats(($env/fots:decimal-format,
534 $case/fots:environment/fots:decimal-format)),
535 env:add-var-decl($env,
536 $case,
537 $envBaseURI,
538 $testSetBaseURI),
539 $test
540 ),"&#xA;"),
541 $xqxqQuery := driver:create-XQXQ-query($query,
542 $case,
543 $env,
544 $envBaseURI,
545 $testSetBaseURI),
546 $startDateTime := datetime:current-dateTime (),
547 $result := driver:xqxq-invoke($xqxqQuery,
548 $case,
549 $showResult,
550 $testSetBaseURI),
551 $duration := (datetime:current-dateTime () - $startDateTime);
552
553 if(empty($result))
554 then driver:pass($case,
555 $result,
556 $xqxqQuery,
557 $env,
558 (),
559 $duration,
560 $verbose)
561
562(: if the exact error code was not found, report the test as 'Pass'
563 with an attribute correctError=false :)
564 else if(exists($result) and
565 contains(string-join($result,''), "Expected error:") and
566 contains(string-join($result,''), "Found error:"))
567 then driver:pass($case,
568 $result,
569 $xqxqQuery,
570 $env,
571 $result,
572 $duration,
573 $verbose)
574 else
575 driver:fail($case,
576 $result,
577 $xqxqQuery,
578 $testSetName,
579 $env,
580 $duration,
581 $verbose)
582}
583} catch * {
584 driver:fail($case,
585 <result>{$err:description}</result>,
586 "",
587 $testSetName,
588 $env,
589 xs:dayTimeDuration("PT0S"),
590 $verbose)
591}
592};
593
594(:~
595 : Gives feedback on a test case that is not run when dependencies are not met.
596 :
597 : @param $case test case.
598 : @param $dependencyError test error returned by the dependency checking.
599 : @return the test case.
600 :)
601declare %private %ann:sequential function driver:not-applicable(
602 $case as element(fots:test-case),
603 $env as element(fots:environment)?,
604 $dependencyError as xs:string,
605 $verbose as xs:boolean
606) as element(fots:test-case)? {
607 trace(data($case/@name), "processing test case :");
608 trace($dependencyError, "Dependency error :");
609 if($verbose)
610 then
611 {
612 let $tmp := $case
613 return {
614 insert node
615 attribute result{'not applicable'}
616 as last into $tmp;
617
618 insert node
619 attribute comment{$dependencyError}
620 as last into $tmp;
621
622 insert node
623 <info>
624 {$env}
625 </info>
626 as last into $tmp;
627
628 delete node $tmp/description;
629 delete node $tmp/created;
630
631 $tmp
632 }
633 }
634 else
635 <test-case name="{data($case/@name)}"
636 result="not applicable"
637 comment="{$dependencyError}" />
638};
639
640(:~
641 : Gives feedback on a test case run with success.
642 :
643 : @param $case test case.
644 : @return the test case after certain information was added.
645 :)
646declare %private %ann:sequential function driver:pass(
647 $case as element(fots:test-case),
648 $result as item()*,
649 $zorbaQuery as xs:string,
650 $env as element(fots:environment)?,
651 $comment as xs:string?,
652 $duration as xs:dayTimeDuration,
653 $verbose as xs:boolean
654) as element(fots:test-case)? {
655 if($verbose)
656 then
657 {
658 let $tmp := $case
659 return {
660 insert node
661 attribute result{'pass'}
662 as last into $tmp;
663
664 if(exists($comment)) then
665 insert node
666 attribute correctError{'false'}
667 as last into $tmp;
668 else ();
669
670 if(exists($comment)) then
671 insert node
672 attribute comment{$comment}
673 as last into $tmp;
674 else ();
675
676 insert node
677 attribute executionTime{$duration}
678 as last into $tmp;
679
680 insert node
681 <info>
682 {$env}
683 <query>{$zorbaQuery}</query>
684 <actual-result>{$result}</actual-result>
685 </info>
686 as last into $tmp;
687
688 delete node $tmp/description;
689 delete node $tmp/created;
690
691 $tmp
692 }
693 }
694 else if(empty($comment))
695 then <test-case name="{data($case/@name)}"
696 result="pass"
697 executionTime="{$duration}" />
698 else <test-case name="{data($case/@name)}"
699 result="pass"
700 correctError="{empty($comment)}"
701 executionTime="{$duration}" />
702};
703
704(:~
705 : Gives feedback on a test case run without success.
706 :
707 : @param $case test case.
708 : @return the test case after certain information was added.
709 :)
710declare %private %ann:sequential function driver:fail(
711 $case as element(fots:test-case),
712 $result as item()*,
713 $zorbaQuery as xs:string,
714 $testSetName as xs:string?,
715 $env as element(fots:environment)?,
716 $duration as xs:dayTimeDuration,
717 $verbose as xs:boolean
718) as element(fots:test-case)? {
719 trace($testSetName, "test set name");
720 trace("above test case failed", "result");
721
722 if($verbose)
723 then
724 {
725 let $tmp := $case
726 return {
727 insert node
728 attribute result{'fail'}
729 as last into $tmp;
730
731 insert node
732 attribute executionTime{$duration}
733 as last into $tmp;
734
735 insert node
736 <info>
737 {$env}
738 <query>{$zorbaQuery}</query>
739 <actual-result>{$result}</actual-result>
740 </info>
741 as last into $tmp;
742
743 delete node $tmp/description;
744 delete node $tmp/created;
745
746 $tmp
747 }
748 }
749 else <test-case name="{data($case/@name)}"
750 result="fail"
751 executionTime="{$duration}"/>
752};
0753
=== 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:57:23 +0000
@@ -0,0 +1,244 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Zorba FOTS driver reporting
19 : @author Sorin Nasoi
20 :)
21
22module namespace reporting =
23 "http://www.zorba-xquery.com/fots-driver/reporting";
24
25import module namespace file =
26 "http://expath.org/ns/file";
27
28import module namespace driver =
29 "http://www.zorba-xquery.com/fots-driver" at "fots-driver.xq";
30import module namespace util =
31 "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
32import module namespace fots-err =
33 "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
34
35declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
36
37declare namespace err =
38 "http://www.w3.org/2005/xqt-errors";
39declare namespace fots =
40 "http://www.w3.org/2010/09/qt-fots-catalog";
41
42declare namespace ann =
43 "http://www.zorba-xquery.com/annotations";
44
45(:~
46 : Loops through the test-sets, runs then and creates statistics.
47 : @param $FOTSCatalogFilePath path to the FOTS catalog file.
48 : @param $FOTSZorbaManifestPath path to the FOTS Zorba manifest file.
49 : @param $testSetPrefixes name/criteria for the test sets( empty string means
50 : all).
51 : @param $testCasePrefixes name/criteria for the test cases(empty string means
52 : all).
53 : @param $exceptedTestCases lists of test cases that are not run( empty string
54 : means all tests will be run).
55 : @param $exceptedTestSets lists of test sets that are not run(empty string
56 : means all tests will be run).
57 : @param $verbose if set to TRUE it will also output the actual failures.
58 : @param $showResult if set to TRUE it will also show the actual result of the
59 : Query run.
60 : @return a report of tests run.
61 :)
62declare %ann:sequential function reporting:run-and-report(
63 $FOTSCatalogFilePath as xs:string,
64 $FOTSZorbaManifestPath as xs:string,
65 $testSetPrefixes as xs:string*,
66 $testCasePrefixes as xs:string*,
67 $exceptedTestCases as xs:string*,
68 $exceptedTestSets as xs:string*,
69 $assert as xs:string*,
70 $verbose as xs:boolean,
71 $showResult as xs:boolean
72) {
73try {
74 {
75 variable $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
76 "Path to FOTS catalog.xml set to: "));
77
78 variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
79
80 variable $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
81 "Path to FOTSZorbaManifest set to:"));
82
83 variable $failures := <fots:FOTS-test-suite-result>{
84 ( $FOTSZorbaManifest//fots:implementation,
85 $FOTSZorbaManifest//fots:dependencies-satisfied,
86 driver:run($FOTSCatalog,
87 $catalogBaseURI,
88 $FOTSZorbaManifest,
89 $testSetPrefixes,
90 $testCasePrefixes,
91 $exceptedTestCases,
92 $exceptedTestSets,
93 $assert,
94 $verbose,
95 $showResult)
96 )
97 }</fots:FOTS-test-suite-result>;
98
99 file:write("failures.xml",
100 $failures,
101 $util:writeXML);
102
103 reporting:do-reporting($FOTSCatalog,
104 $catalogBaseURI,
105 $failures,
106 $exceptedTestCases,
107 $exceptedTestSets,
108 $verbose)
109 }
110}
111catch *
112{
113 error($err:code,
114 $err:description,
115 concat("&#xA;Please make sure the passed 'fotsPath' points to the ",
116 "exact location of the FOTS catalog.xml:&#xA;",
117 resolve-uri($FOTSCatalogFilePath),
118 "&#xA;and that the passed 'fotsZorbaManifestPath' points to",
119 " a file in the same folder as cli.xq:&#xA;",
120 resolve-uri($FOTSZorbaManifestPath)))
121}
122};
123
124(:~
125 : Loops through the test cases report and creates statistics.
126 : @param $pathFOTSCatalog path to the FOTS catalog file.
127 : @param $pathFailures path to the FOTS failures.
128 : @param $exceptedTestCases lists of test cases that are not run( empty string
129 : means all tests will be run).
130 : @param $exceptedTestSets lists of test sets that are not run(empty string
131 : means all tests will be run).
132 : @param $verbose if set to TRUE it will also output the actual failures.
133 : @param $showResult if set to TRUE it will also show the actual result of the
134 : Query run.
135 : @return a report of tests run.
136 :)
137declare %ann:nondeterministic function reporting:report(
138 $FOTSCatalogFilePath as xs:string,
139 $pathFailures as xs:string,
140 $exceptedTestCases as xs:string*,
141 $exceptedTestSets as xs:string*,
142 $verbose as xs:boolean
143) as element(fots:report) {
144 try {
145 {
146 if(not(file:is-file($pathFailures)))
147 then
148 {
149 error($fots-err:errNA,
150 "The file failures file was not found. Suggestion: use driver:run-fots to generate it or use reporting:run-and-report function.");
151 }
152 else ();
153
154 variable $failures := parse-xml(file:read-text($pathFailures));
155
156 variable $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
157 "Path to FOTS catalog.xml set to: "));
158
159 variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
160
161 reporting:do-reporting($FOTSCatalog,
162 $catalogBaseURI,
163 $failures,
164 $exceptedTestCases,
165 $exceptedTestSets,
166 $verbose)
167 }
168 }
169 catch *
170 {
171 error($err:code, $err:description)
172 }
173};
174
175
176(:~
177 : Loops through the test-sets and creates statistics.
178 : @param $FOTSCatalog FOTS catalog file.
179 : @param $failures the test reported by Zorba as failed.
180 : @param $exceptedTestCases lists of test cases that are not run(empty string
181 : means all tests will be run).
182 : @param $exceptedTestSets lists of test sets that are not run(empty string
183 : means all tests will be run).
184 : @param $verbose is set to TRUE it will also output the actual failures.
185 : @return a report of tests run.
186 :)
187declare %ann:nondeterministic function reporting:do-reporting(
188 $FOTSCatalog as document-node(),
189 $catalogBaseURI as xs:anyURI,
190 $failures,
191 $exceptedTestCases as xs:string*,
192 $exceptedTestSets as xs:string*,
193 $verbose as xs:boolean
194) as element(fots:report) {
195 let $excepted := count($exceptedTestCases)
196 return
197 <report>
198 {
199 let $totalNoTests := count($failures//fots:test-set//fots:test-case),
200 $totalPass := sum(for $testSet in $failures//fots:test-set
201 return count($testSet//fots:test-case[@result ='pass'])),
202 $totalFail := sum(for $testSet in $failures//fots:test-set
203 return count($testSet//fots:test-case[@result ='fail'])),
204 $totalNotApplicable := sum(for $testSet in $failures//fots:test-set
205 return count($testSet//fots:test-case[@result ='not applicable'])),
206 $totalNotRun := sum(for $testSet in $failures//fots:test-set
207 return count($testSet//fots:test-case[@result ='notRun'])),
208 $executionTime := sum(for $testCase in $failures//fots:test-set//fots:test-case return xs:dayTimeDuration($testCase/@executionTime))
209 return
210 <brief totalTests="{$totalNoTests}"
211 totalPass="{$totalPass}"
212 totalFail="{$totalFail}"
213 totalNotApplicable="{$totalNotApplicable}"
214 totalNotRun="{$totalNotRun}"
215 totalExecutionTime="{$executionTime}"/>
216 }
217 {
218 for $testSetFile in $FOTSCatalog//fots:test-set
219 let $testSetURI := resolve-uri($testSetFile/@file,
220 $catalogBaseURI),
221 $testSetDoc := doc($testSetURI),
222 $testSetName := data($testSetDoc/fots:test-set/@name),
223 $totalNoTestCases := count($testSetDoc//fots:test-case),
224 $totalFailures := for $testCase in $failures//fots:test-set[@name = $testSetName]//fots:test-case[@result ="fail"]
225 return $testCase,
226 $percent := round((1 - (count($totalFailures) div $totalNoTestCases))*100,2),
227 $executionTime := sum(for $testCase in $failures//fots:test-set[@name = $testSetName]//fots:test-case
228 return xs:dayTimeDuration($testCase/@executionTime))
229 order by count($totalFailures) descending
230 return
231 <test-set name="{$testSetName}"
232 executionTime="{$executionTime}"
233 noFailures="{count($totalFailures)}"
234 noTestCases="{$totalNoTestCases}"
235 percent="{$percent}"
236 failedTestNames="{string-join( for $failure in $totalFailures
237 order by data($failure/@name)
238 return data($failure/@name)
239 ,",")}">
240 {if (not($verbose)) then $totalFailures else ()}
241 </test-set>
242 }
243 </report>
244};
0245
=== 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:57:23 +0000
@@ -0,0 +1,27 @@
1(: this query loads a rezults.xml file and reports the number of 'non applicable' tests grouped by feature :)
2(:
3 sample usage
4 ./zorba -f -q ../../test/fots_driver/tools/dependencies.xq
5 -e pathFailures:=results_12_nov.xml
6 -o driver_dependencies.xml
7 --indent
8:)
9
10 import module namespace file = "http://expath.org/ns/file";
11
12 declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
13 declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
14
15 declare variable $pathFailures external;
16
17 variable $failures := fn:parse-xml(file:read-text($pathFailures));
18
19 <report> {
20 for $d in distinct-values(data($failures/fots:test-cases/fots:test-set/fots:test-case[@result="not applicable"]/@comment))
21 order by $d
22 return
23 <dependency type="{$d}"> {
24 <value number-of-tests="{count($failures/fots:test-cases//fots:test-set//fots:test-case[@result="not applicable" and @comment=$d])}" />
25 }</dependency>
26 }</report>
27
0\ No newline at end of file28\ No newline at end of file
129
=== 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:57:23 +0000
@@ -0,0 +1,130 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Run every test case that matches a given criterion in a different process
19 : and report every test case that HANGS or ends in a SEG FAULT.
20 :
21 : @author Sorin Nasoi
22 :)
23
24
25import module namespace proc =
26 "http://www.zorba-xquery.com/modules/process";
27import module namespace util =
28 "http://www.zorba-xquery.com/fots-driver/util" at "../util.xq";
29import module namespace d =
30 "http://www.zorba-xquery.com/fots-driver" at "../fots-driver.xq";
31import module namespace fots-err =
32 "http://www.zorba-xquery.com/fots-driver/errors" at "../errors.xq";
33
34declare namespace ann =
35 "http://www.zorba-xquery.com/annotations";
36declare namespace fots =
37 "http://www.w3.org/2010/09/qt-fots-catalog";
38
39declare variable $fotsPath as xs:string external := "";
40declare variable $dependency as xs:string external := "";
41declare variable $testSetPrefixes as xs:string external := "";
42
43
44(:~
45 : Return the exit-code after invoking the FOTS driver with given $params.
46 :
47 : @param $params additional params.
48 : @return the exit-code returned by the invoked application.
49 :)
50declare %ann:sequential function local:exec(
51 $params as xs:string*
52) as xs:string {
53 variable $pathZorba := normalize-space(xs:string(proc:exec("pwd")/proc:stdout));
54
55 proc:exec(string-join(($pathZorba, "/zorba"),''),
56 ("-f", "-q", concat($pathZorba, "/../../test/fots_driver/cli.xq"),
57 "-e", concat("fotsPath:=", $fotsPath),
58 "-e", "verbose:=false",
59 $params
60 )
61 )/proc:exit-code
62};
63
64declare %private %ann:sequential function local:invoke-exec(
65 $testSets as element(fots:test-set)*,
66 $baseUri as xs:anyURI,
67 $dependency as xs:string*
68) as xs:string* {
69 for $testSet in $testSets
70 let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
71 let $testSetName := xs:string($testSet/@name)
72 let $testCaseNames as xs:string* := d:list-test-cases($testSetDoc,
73 $dependency)
74 return
75 for $testCaseName in $testCaseNames
76 let $exit-code :=
77 trace(local:exec(("-e", "mode:=run-test-case",
78 "-e", concat("testSetName:=", $testSetName),
79 "-e", concat("testCaseName:=", trace($testCaseName, "processing test case :"))
80 )
81 ),"exit-code")
82 where (xs:integer($exit-code) gt xs:integer(134))
83 return $testCaseName
84};
85
86(:~
87 : Return the name of the test cases that return an exit-code > 134.
88 :
89 : @param $fotsPath path to the FOTS catalog file.
90 : @param $testSetPrefixes name/criteria for the test sets.
91 : @param $dependency defined dependency.
92 : @return the exit-codes returned by the invoked applications.
93 :)
94declare %ann:sequential function local:list-test-cases(
95 $fotsPath as xs:string,
96 $testSetPrefixes as xs:string*,
97 $dependency as xs:string*
98) as xs:string* {
99 variable $doc := doc(resolve-uri($fotsPath)),
100 $baseUri:= resolve-uri(util:parent-folder($fotsPath));
101
102 if(string-join($testSetPrefixes,'') = '')
103 then local:invoke-exec($doc/fots:catalog/fots:test-set,
104 $baseUri,
105 $dependency)
106 else
107 for $prefix in $testSetPrefixes
108 return
109 local:invoke-exec($doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)],
110 $baseUri,
111 $dependency)
112};
113
114if( $fotsPath = '')
115then fn:error($fots-err:errNA,
116 "please set the external variable $fotsPath to point to FOTS catalog.xml file.")
117else
118concat("'",
119 string-join(local:list-test-cases($fotsPath, $testSetPrefixes, $dependency),"', '"),
120 "'")
121
122
123(:
124local:exec(
125 ("-e", "mode:=run-test-case",
126 "-e", concat("testSetName:=", "misc-HigherOrderFunctions"),
127 "-e", concat("testCaseName:=", "xqhof2")
128 )
129 )
130:)
0\ No newline at end of file131\ No newline at end of file
1132
=== 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:57:23 +0000
@@ -0,0 +1,119 @@
1(:
2 : Copyright 2006-2011 The FLWOR Foundation.
3 :
4 : Licensed under the Apache License, Version 2.0 (the "License");
5 : you may not use this file except in compliance with the License.
6 : You may obtain a copy of the License at
7 :
8 : http://www.apache.org/licenses/LICENSE-2.0
9 :
10 : Unless required by applicable law or agreed to in writing, software
11 : distributed under the License is distributed on an "AS IS" BASIS,
12 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : See the License for the specific language governing permissions and
14 : limitations under the License.
15 :)
16
17(:~
18 : Zorba FOTS driver util
19 : @author Sorin Nasoi
20 :)
21
22module namespace util =
23 "http://www.zorba-xquery.com/fots-driver/util";
24
25import schema namespace output =
26 "http://www.w3.org/2010/xslt-xquery-serialization";
27
28import module namespace file =
29 "http://expath.org/ns/file";
30
31import module namespace fots-err =
32 "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
33
34declare namespace err =
35 "http://www.w3.org/2005/xqt-errors";
36declare namespace fots =
37 "http://www.w3.org/2010/09/qt-fots-catalog";
38
39declare namespace ann =
40 "http://www.zorba-xquery.com/annotations";
41
42
43(:~
44 : The serialization parameters for XML serialization.
45 :)
46 declare variable $util:serParamXml :=
47 <output:serialization-parameters>
48 <output:method value="xml" />
49 <output:indent value="no" />
50 <output:omit-xml-declaration value="yes" />
51 </output:serialization-parameters>;
52
53(:~
54 : The serialization parameters for XML serialization.
55 :)
56 declare variable $util:writeXML :=
57 <output:serialization-parameters>
58 <output:method value="xml" />
59 <output:indent value="yes" />
60 <output:omit-xml-declaration value="no" />
61 </output:serialization-parameters>;
62
63(:~
64 : Retrieve the value of from the given node that is either given as text node
65 : or in a file attribute.
66 :
67 : @param $case test-case element.
68 : @param $path the path of the test-set.
69 : @return the query text.
70 :)
71declare %ann:nondeterministic function util:get-value(
72 $case as element(fots:test-case),
73 $envBaseURI as xs:anyURI,
74 $node-name as xs:string
75) as xs:string {
76 try {
77 for $node in $case/descendant-or-self::*
78 where (fn:local-name-from-QName(fn:node-name($node)) = $node-name)
79 return
80 if(exists($node/@file))
81 then fn:unparsed-text(resolve-uri($node/@file, $envBaseURI))
82 else fn:data($node)
83 } catch * {
84 fn:error($fots-err:errNA, $err:description)
85 }
86};
87
88(:~
89 : returns the parent folder of the given file path.
90 : example: util:parent-folder('/home/user/file.ext') returns '/home/user'.
91 : @param $path Path.
92 : @return the parent folder of the given file.
93 :)
94
95declare function util:parent-folder(
96 $path as xs:string
97) as xs:anyURI {
98 xs:anyURI(fn:substring-before($path,
99 file:base-name($path)))
100};
101
102declare function util:serialize-result(
103 $result as item()*
104) as xs:string* {
105util:serialize-result($result,
106 $util:serParamXml)
107};
108
109declare function util:serialize-result(
110 $result as item()*,
111 $SerParams
112) as xs:string* {
113 for $res in $result
114 return
115 if($res instance of node())
116 then fn:serialize($res,
117 $SerParams)
118 else fn:string($res)
119};

Subscribers

People subscribed via source and target branches