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

Proposed by Sorin Marian Nasoi on 2012-12-18
Status: Merged
Approved by: Sorin Marian Nasoi on 2012-12-18
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 on 2012-12-18
Chris Hillery 2012-12-18 Approve on 2012-12-18
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.
review: Approve
Chris Hillery (ceejatec) :
review: Approve
review: Approve
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!

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.

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
1=== added directory 'test/fots_driver'
2=== added file 'test/fots_driver/FOTSZorbaManifest.xml'
3--- test/fots_driver/FOTSZorbaManifest.xml 1970-01-01 00:00:00 +0000
4+++ test/fots_driver/FOTSZorbaManifest.xml 2012-12-18 11:57:23 +0000
5@@ -0,0 +1,66 @@
6+<?xml version="1.0" encoding="UTF-8"?>
7+<FOTS-test-suite-result xmlns="http://www.w3.org/2010/09/qt-fots-catalog">
8+ <implementation name="Zorba" version="trunk" anonymous-result-column="false">
9+ <organization name="http://www.zorba-xquery.com" anonymous="false"/>
10+ <submitter name="Sorin Nasoi" email="spungi@gmail.com"/>
11+ </implementation>
12+ <dependencies-satisfied>
13+ <dependency type="feature" value="collection-stability" satisfied="true"/> <!-- Is this correct? -->
14+ <dependency type="feature" value="directory-as-collection-uri" satisfied="true"/> <!-- Is this correct? -->
15+ <dependency type="feature" value="higherOrderFunctions" satisfied="false"/>
16+ <dependency type="feature" value="moduleImport" satisfied="true"/>
17+ <dependency type="feature" value="namespace-axis" satisfied="false"/> <!-- Is this correct? -->
18+ <dependency type="feature" value="schema-location-hint" satisfied="false"/> <!-- Is this correct? -->
19+ <dependency type="feature" value="schemaAware" satisfied="true"/>
20+ <dependency type="feature" value="schemaImport" satisfied="true"/>
21+ <dependency type="feature" value="schemaValidation" satisfied="true"/>
22+ <dependency type="feature" value="staticTyping" satisfied="false"/>
23+ <dependency type="feature" value="xpath-1.0-compatibility" satisfied="true"/> <!-- Is this correct? -->
24+
25+ <dependency type="spec" value="XP10 XQ10" satisfied="true"/>
26+ <dependency type="spec" value="XP10+" satisfied="true"/>
27+ <dependency type="spec" value="XP20 XQ10" satisfied="true"/>
28+ <dependency type="spec" value="XP20+" satisfied="true"/>
29+ <dependency type="spec" value="XP30+" satisfied="true"/>
30+ <dependency type="spec" value="XP30+ XQ10+" satisfied="true"/>
31+ <dependency type="spec" value="XP30+ XQ30+" satisfied="true"/>
32+ <dependency type="spec" value="XQ10" satisfied="true"/>
33+ <dependency type="spec" value="XQ10 XP20" satisfied="true"/>
34+ <dependency type="spec" value="XQ10+" satisfied="true"/>
35+ <dependency type="spec" value="XQ10+ XP20+" satisfied="true"/>
36+ <dependency type="spec" value="XQ10+ XP30+" satisfied="true"/>
37+ <dependency type="spec" value="XQ30" satisfied="true"/>
38+ <dependency type="spec" value="XQ30 XP30" satisfied="true"/>
39+ <dependency type="spec" value="XQ30+" satisfied="true"/>
40+ <dependency type="spec" value="XQ30+ XP30+" satisfied="true"/>
41+ <dependency type="spec" value="XT30+" satisfied="false"/>
42+
43+ <dependency type="xml-version" value="1.0" satisfied="true"/>
44+ <dependency type="xml-version" value="1.0:4-" satisfied="true"/>
45+ <dependency type="xml-version" value="1.0:5+ 1.1" satisfied="false"/>
46+ <dependency type="xml-version" value="1.1" satisfied="false"/>
47+
48+ <dependency type="language" value="de" satisfied="false"/> <!-- Is this correct? -->
49+ <dependency type="language" value="en" satisfied="true"/>
50+ <dependency type="language" value="xib" satisfied="false"/> <!-- Is this correct? -->
51+
52+ <!-- Are these correct? -->
53+ <dependency type="limits" value="year_lt_0" satisfied="true"/>
54+ <dependency type="calendar" value="CB" 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="format-integer-sequence" value="①" satisfied="true"/>
59+ <dependency type="format-integer-sequence" value="⑴" satisfied="true"/>
60+ <dependency type="format-integer-sequence" value="⒈" satisfied="true"/>
61+ <dependency type="format-integer-sequence" value="一" satisfied="true"/>
62+ <dependency type="format-integer-sequence" value="ﯴ" satisfied="true"/>
63+ <dependency type="default-language" value="en" satisfied="true"/>
64+ <dependency type="unicode-normalization-form" value="FULLY-NORMALIZED" satisfied="true"/>
65+ <dependency type="unicode-normalization-form" value="NFD" satisfied="true"/>
66+ <dependency type="unicode-normalization-form" value="NFKC" satisfied="true"/>
67+ <dependency type="unicode-normalization-form" value="NFKD" satisfied="true"/>
68+ <dependency type="xsd-version" value="1.0" satisfied="true"/>
69+ <dependency type="xsd-version" value="1.1" satisfied="false"/>
70+ </dependencies-satisfied>
71+</FOTS-test-suite-result>
72
73=== added file 'test/fots_driver/README.TXT'
74--- test/fots_driver/README.TXT 1970-01-01 00:00:00 +0000
75+++ test/fots_driver/README.TXT 2012-12-18 11:57:23 +0000
76@@ -0,0 +1,49 @@
77+Information about the W3C XQuery/XPath/XSLT 3.* Test Suite can be found at:
78+ http://dev.w3.org/2011/QT3-test-suite.
79+
80+In order to use the Zorba FOTS driver (written in XQuery) one has to follow
81+these steps:
82+
83+0) Build Zorba with ZORBA_WITH_BIG_INTEGER flag set to ON.
84+
85+ For example with CMake:
86+ cmake -DZORBA_WITH_BIG_INTEGER=ON ..
87+ make
88+
89+1) Download the FOTS testsuite from W3C
90+ Since currently there is no official release, a simple "cvs get" will do:
91+
92+ $ export CVSROOT=":pserver:anonymous@dev.w3.org:/sources/public"
93+ $ cvs login
94+ (Logging in to anonymous@dev.w3.org)
95+ CVS password: anonymous
96+ $ cvs get 2011/QT3-test-suite
97+
98+3) run
99+ ./zorba -f
100+ -q ../../test/fots_driver/cli.xq
101+
102+Zorba FOTS driver usage examples:
103+If you run Zorba from a checkout of the trunk and the build/bin folder,
104+- /path/to/cli.xq can be set to ../../test/fots_driver/cli.xq
105+
106+Always try to output the result back to an XML file with nice indentation:
107+./zorba -f -q ../../test/fots_driver/cli.xq -e SET_CLI_OPTIONS_HERE -o output.xml --indent
108+
109+ This way you will see trace information in the CLI window and detailed
110+ results of the test cases in the 'output.xml'.
111+
112+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
113+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets
114+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
115+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
116+zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-cases -e dependency:=higherOrderFunctions
117+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
118+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
119+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
120+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
121+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
122+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
123+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
124+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
125+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
126
127=== added file 'test/fots_driver/cli.xq'
128--- test/fots_driver/cli.xq 1970-01-01 00:00:00 +0000
129+++ test/fots_driver/cli.xq 2012-12-18 11:57:23 +0000
130@@ -0,0 +1,197 @@
131+(:
132+ : Copyright 2006-2011 The FLWOR Foundation.
133+ :
134+ : Licensed under the Apache License, Version 2.0 (the "License");
135+ : you may not use this file except in compliance with the License.
136+ : You may obtain a copy of the License at
137+ :
138+ : http://www.apache.org/licenses/LICENSE-2.0
139+ :
140+ : Unless required by applicable law or agreed to in writing, software
141+ : distributed under the License is distributed on an "AS IS" BASIS,
142+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
143+ : See the License for the specific language governing permissions and
144+ : limitations under the License.
145+ :)
146+
147+(:~
148+ : Zorba FOTS driver CLI
149+ : @author Ghislain Fourny, Sorin Nasoi
150+ :)
151+
152+import module namespace d =
153+ "http://www.zorba-xquery.com/fots-driver" at "fots-driver.xq";
154+import module namespace r =
155+ "http://www.zorba-xquery.com/fots-driver/reporting" at "reporting.xq";
156+
157+(:~ path to the place where FOTS can be found :)
158+declare variable $fotsPath as xs:string external := "";
159+
160+(:~ path to the place where the FOTS Zorba manifest can be found :)
161+declare variable $fotsZorbaManifestPath as xs:string external :=
162+ "FOTSZorbaManifest.xml";
163+
164+(:~ Path to the results from a previous run :)
165+declare variable $failuresFilePath as xs:string external := "";
166+
167+(:~ choose the CLI option you want to run :)
168+declare variable $mode as xs:string external := "";
169+
170+(:~ name/criteria for the test sets :)
171+declare variable $testSetPrefixes as xs:string external := "";
172+
173+(:~ name/criteria for the test cases :)
174+declare variable $testCasePrefixes as xs:string external := "";
175+
176+(:~ name for the test set :)
177+declare variable $testSetName as xs:string external := "";
178+
179+(:~ name for the test case :)
180+declare variable $testCaseName as xs:string external := "";
181+
182+(:~ Enable or disable verbose output :)
183+declare variable $verbose as xs:string external := "true";
184+
185+(:~
186+ Enable or disable showing the actual query result in the output.
187+ True by default.
188+:)
189+declare variable $showResult as xs:string external := "true";
190+
191+(:~ assertion type :)
192+declare variable $assertType as xs:string external := "";
193+
194+(:~ dependency: used in 'list-test-cases' and 'run-test-sets' modes:)
195+declare variable $dependency as xs:string external := "";
196+
197+(:~ regex for the tests in the 'list-matching-test-cases' option :)
198+declare variable $pattern as xs:string external := "";
199+
200+(:~ flags for the tests in the 'list-matching-test-cases' option :)
201+declare variable $flags as xs:string external := "";
202+
203+(:~ Tokenize comma or empty string :)
204+declare %private function local:tokenize(
205+ $input as xs:string
206+) as xs:string*
207+{
208+ let $tokens := tokenize($input, ",")
209+ return if (exists($tokens)) then $tokens else ""
210+};
211+
212+declare function local:usage() as xs:string
213+{
214+ string-join((
215+ "Zorba FOTS driver usage examples:",
216+ "If you run Zorba from a checkout of the trunk and the build/bin folder,",
217+ "- /path/to/cli.xq can be set to ../../test/fots_driver/cli.xq",
218+ "",
219+ "Always try to output the result back to an XML file with nice indentation:",
220+ "./zorba -f -q ../../test/fots_driver/cli.xq -e SET_CLI_OPTIONS_HERE -o output.xml --indent",
221+ "",
222+ " This way you will see trace information in the CLI window and detailed",
223+ " results of the test cases in the 'output.xml'.",
224+ "",
225+ "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",
226+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-sets",
227+ "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",
228+ "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",
229+ "zorba -f -q /path/to/cli.xq -e fotsPath:=/path/to/QT3-test-suite/catalog.xml -e mode:=list-test-cases -e dependency:=higherOrderFunctions",
230+ "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",
231+ "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",
232+ "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",
233+ "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",
234+ "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",
235+ "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",
236+ "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",
237+ "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",
238+ "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",
239+ ""
240+ ), "&#xA;")
241+};
242+
243+(:~ The test cases in this list have bugs assigned and should not be run :)
244+variable $exceptedTestCases := (
245+"cbcl-subsequence-011", "cbcl-subsequence-012", "cbcl-subsequence-013",
246+"cbcl-subsequence-014" (:see bug lp:1069794 :)
247+, "re00975", "re00976", "re00976a" (:see bug lp:1070533 :)
248+, "fn-unparsed-text-lines-052" (:see bug lp:1073175 :)
249+);
250+
251+(:~ The test in this list have bugs assigned already and should not be run :)
252+variable $exceptedTestSets := ();
253+
254+switch ($mode)
255+case "list-test-sets"
256+ return
257+ string-join(
258+ (d:list-test-sets(
259+ trace($fotsPath, "Path to FOTS catalog.xml set to: "),
260+ local:tokenize(trace($testSetPrefixes, "'testSetPrefixes' set to: ")))),
261+ "&#xA;")
262+case "list-test-cases"
263+ return
264+ string-join(
265+ (d:list-test-cases( trace($fotsPath,
266+ "Path to FOTS catalog.xml set to: "),
267+ local:tokenize(trace($testSetPrefixes,
268+ "'testSetPrefixes' set to: ")),
269+ "",
270+ trace($dependency,
271+ "'dependency' set to:"))),
272+ "&#xA;")
273+case "list-matching-test-cases"
274+ return string-join((d:list-matching-test-cases(
275+ trace($fotsPath,
276+ "Path to FOTS catalog.xml set to: "),
277+ trace($pattern,
278+ "pattern set to: "),
279+ trace($flags,
280+ "flags were set to: ")), ""),
281+ "&#xA;")
282+case "run-test-sets"
283+ return d:run-fots($fotsPath,
284+ $fotsZorbaManifestPath,
285+ d:list-test-sets($fotsPath,
286+ local:tokenize(trace($testSetPrefixes,
287+ "'testSetPrefixes' set to: "))),
288+ d:list-test-cases($fotsPath,
289+ local:tokenize($testSetPrefixes),
290+ local:tokenize(trace($testCasePrefixes,
291+ "'$testCasePrefixes' set to: ")),
292+ trace($dependency,
293+ "'dependency' set to:")),
294+ $exceptedTestCases,
295+ $exceptedTestSets,
296+ $assertType,
297+ xs:boolean($verbose),
298+ xs:boolean($showResult))
299+case "run-test-case"
300+ return d:run-fots($fotsPath,
301+ $fotsZorbaManifestPath,
302+ trace($testSetName,"'testSetName' set to: "),
303+ trace($testCaseName,"'testCaseName' set to: "),
304+ $exceptedTestCases,
305+ $exceptedTestSets,
306+ trace($assertType,"'assertType' set to: "),
307+ xs:boolean($verbose),
308+ xs:boolean($showResult))
309+case "run-and-report"
310+ return r:run-and-report($fotsPath,
311+ $fotsZorbaManifestPath,
312+ d:list-test-sets($fotsPath,
313+ local:tokenize($testSetPrefixes)),
314+ '',
315+ $exceptedTestCases,
316+ $exceptedTestSets,
317+ $assertType,
318+ fn:false(), (: the reports to W3C are always generated with verbose set to false:)
319+ xs:boolean($showResult))
320+case "report"
321+ return r:report($fotsPath,
322+ $failuresFilePath,
323+ $exceptedTestCases,
324+ $exceptedTestSets,
325+ xs:boolean($verbose))
326+default
327+ return local:usage()
328
329=== added file 'test/fots_driver/environment.xq'
330--- test/fots_driver/environment.xq 1970-01-01 00:00:00 +0000
331+++ test/fots_driver/environment.xq 2012-12-18 11:57:23 +0000
332@@ -0,0 +1,561 @@
333+(:
334+ : Copyright 2006-2011 The FLWOR Foundation.
335+ :
336+ : Licensed under the Apache License, Version 2.0 (the "License");
337+ : you may not use this file except in compliance with the License.
338+ : You may obtain a copy of the License at
339+ :
340+ : http://www.apache.org/licenses/LICENSE-2.0
341+ :
342+ : Unless required by applicable law or agreed to in writing, software
343+ : distributed under the License is distributed on an "AS IS" BASIS,
344+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
345+ : See the License for the specific language governing permissions and
346+ : limitations under the License.
347+ :)
348+
349+(:~
350+ : Zorba FOTS driver environment
351+ : @author Sorin Nasoi
352+ :)
353+
354+module namespace env =
355+ "http://www.zorba-xquery.com/fots-driver/environment";
356+
357+import module namespace xqxq =
358+ "http://www.zorba-xquery.com/modules/xqxq";
359+import module namespace util =
360+ "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
361+
362+declare namespace fots =
363+ "http://www.w3.org/2010/09/qt-fots-catalog";
364+
365+declare namespace ann =
366+ "http://www.zorba-xquery.com/annotations";
367+
368+
369+declare variable $env:hof as xs:string :=
370+ string-join(
371+ ( "declare namespace op = 'http://www.zorba-xquery.com/options/features';",
372+ "declare namespace f = 'http://www.zorba-xquery.com/features';",
373+ "declare option op:enable 'f:hof';"),
374+ "&#xA;");
375+
376+
377+(:~
378+ : If there is a dependency on XQuery 3.0 and there is at least one HOF
379+ : function in the test, return the strings for enabling the HOF feature.
380+ :
381+ : @param $deps the dependencies of the test set and test case
382+ : @param $test the Query test.
383+ : @return the strings for enabling the HOF feature
384+ :)
385+declare function env:enable-HOF-feature(
386+ $deps as element(fots:dependency)*,
387+ $test as xs:string
388+) as xs:string?
389+{
390+ let $depSpec := string-join(distinct-values( for $dep in $deps
391+ where $dep[@type="spec"]
392+ return data($dep/@value)),""),
393+ $depFeature := string-join(distinct-values(for $dep in $deps
394+ where $dep[@type="feature"]
395+ return data($dep/@value)),"")
396+ return
397+ if ((contains($depSpec,"XQ30") or contains($depSpec,"XP30")) and
398+ contains($depFeature,"higherOrderFunctions"))
399+ then $env:hof else ()
400+};
401+
402+
403+(:~
404+ : Check if an XQuery version declaration needs to be added.
405+ :
406+ : @param $deps the dependencies of the test set and test case.
407+ : @param $test the Query test.
408+ : @return the XQuery version declaration.
409+ :)
410+declare function env:add-xquery-version-decl(
411+ $deps as element(fots:dependency)*,
412+ $test as xs:string
413+) as xs:string?
414+{
415+ let $dependencies := string-join(distinct-values(for $dep in $deps
416+ where $dep[@type="spec"]
417+ return data($dep/@value)),"")
418+ return
419+ if ((contains($dependencies,"XQ30") or contains($dependencies,"XP30")) and
420+ not(contains($test, "xquery version ")))
421+ then 'xquery version "3.0";'
422+ else if(contains($dependencies,"XQ10") and
423+ not(contains($test, "xquery version ")))
424+ then 'xquery version "1.0";'
425+ else ()
426+};
427+
428+
429+(:~
430+ : Sets the declared default element namespace.
431+ :
432+ : @param $env the environment of the catalog/test-set (given with 'ref').
433+ : @param $envCase the environment of the test-case.
434+ : @return the declare default element namespace.
435+ :)
436+declare function env:decl-def-elem-namespace(
437+ $env as element(fots:environment)?,
438+ $envCase as element(fots:environment)?
439+) as xs:string?
440+{
441+ for $ns in ($env/fots:namespace, $envCase/fots:namespace)
442+ where $ns[@prefix=""]
443+ return concat('declare default element namespace "',
444+ data($ns/@uri),
445+ '";')
446+};
447+
448+
449+(:~
450+ : Adds the declare namespace statements.
451+ :
452+ : @param $env the environment of the catalog/test-set (given with 'ref').
453+ : @param $case the test-case.
454+ : @param $testSetBaseURI the URI of the test set file.
455+ : @return the declare namespace statements.
456+ :)
457+declare %ann:nondeterministic function env:decl-namespaces(
458+ $env as element(fots:environment)?,
459+ $case as element(fots:test-case),
460+ $testSetBaseURI as xs:anyURI
461+) as xs:string?
462+{
463+ string-join(
464+ for $ns in ($env/fots:namespace, $case/fots:environment/fots:namespace)
465+ where not($ns[@prefix=""]) and
466+ not(env:is-schema-prefix-bound(data($ns/@prefix),
467+ $case,
468+ $testSetBaseURI))
469+ return concat('declare namespace ',
470+ data($ns/@prefix),
471+ ' = "',
472+ data($ns/@uri),
473+ '";')
474+ ," ")
475+};
476+
477+
478+(:~
479+ : Return true if the prefix will be bound to a schema in the Query
480+ : It's a bug in the FOTS if this function returns true: TODO report to W3C
481+ :)
482+declare %private %ann:nondeterministic function env:is-schema-prefix-bound(
483+ $prefix as xs:string,
484+ $case as element(fots:test-case),
485+ $testSetBaseURI as xs:anyURI
486+) as xs:boolean
487+{
488+ contains(util:get-value($case,
489+ $testSetBaseURI,
490+ "test"),
491+ concat("import schema namespace ",
492+ $prefix))
493+};
494+
495+
496+(:~
497+ : Returns the the declare base-uri prolog statement.
498+ :
499+ : @param $env the environment of the catalog/test-set (given with 'ref').
500+ : @param $envCase the environment of the test-case.
501+ : @return the declare base-uri prolog statement.
502+ :)
503+declare function env:decl-base-uri(
504+ $env as element(fots:environment)?,
505+ $envCase as element(fots:environment)?
506+) as xs:string?
507+{
508+ for $baseURI in ($env/fots:static-base-uri, $envCase/fots:static-base-uri)
509+ return concat("declare base-uri '",
510+ data($baseURI/@uri),
511+ "';")
512+};
513+
514+
515+(:~
516+ : Add the decimal format declarations.
517+ :
518+ : @param $decimal-formats decimal formats.
519+ : @return the decimal formats declarations.
520+ :)
521+declare function env:decl-decimal-formats(
522+ $decimal-formats as element(fots:decimal-format)*
523+) as xs:string*
524+{
525+ if(empty($decimal-formats))
526+ then ()
527+ else
528+ for $tmp in $decimal-formats
529+ let $default := if(exists($tmp/@name))
530+ then ()
531+ else "default"
532+ let $name := if(exists($tmp/@name))
533+ then data($tmp/@name)
534+ else ()
535+ return
536+ string-join(("declare",
537+ $default,
538+ "decimal-format",
539+ $name,
540+ env:set-properties($tmp),
541+ ";"),' ')
542+};
543+
544+
545+declare %private function env:set-properties(
546+ $decimal-format as element(fots:decimal-format)
547+) as xs:string*
548+{
549+ for $att in $decimal-format/attribute::*
550+ let $name := node-name($att)
551+ let $value := data($att)
552+ return
553+ if(exists(index-of(("decimal-separator", "grouping-separator", "infinity",
554+ "minus-sign", "NaN", "percent", "per-mille",
555+ "zero-digit", "digit", "pattern-separator"),
556+ xs:string($name))))
557+ then concat($name, '="' , $value, '"')
558+ else ()
559+};
560+
561+
562+(:~
563+ : Adds the variable declarations.
564+ : @param $env environment.
565+ : @param $case test case.
566+ : @param $envBaseURI the relative URI for the environment.
567+ : @param $testSetBaseURI the URI of the test set.
568+ : @return the variable declarations.
569+ :)
570+declare %ann:nondeterministic function env:add-var-decl(
571+ $env as element(fots:environment)?,
572+ $case as element(fots:test-case),
573+ $envBaseURI as xs:anyURI,
574+ $testSetBaseURI as xs:anyURI
575+) as xs:string?
576+{
577+ concat( env:var-decl-with-value($env,
578+ $envBaseURI),
579+ env:var-decl-with-value($case/fots:environment,
580+ $testSetBaseURI),
581+ env:var-decl-without-value($env,
582+ $case/fots:environment))
583+};
584+
585+
586+declare %private function env:var-decl-with-value(
587+ $env as element(fots:environment)?,
588+ $baseURI as xs:anyURI
589+) as xs:string?
590+{
591+ string-join(
592+ for $param in $env/fots:param
593+ let $select := $param/@select
594+ let $file := $env/fots:source[@uri = translate($select, "'", "")]/@file
595+ let $type := $param/@as
596+ let $varValue := if(starts-with($select, "'") and
597+ ends-with($select, "'") and
598+ exists($file))
599+ then concat('"',
600+ resolve-uri($file, $baseURI),
601+ '"')
602+ else $select
603+ where (exists($select) and
604+(: if there is an attribute 'declared' set to true, this means that the variable
605+ is declared within the 'test' itself so no additional variable declaration
606+ is needed :)
607+ empty($param[@declared="true"]))
608+ return concat("declare variable $",
609+ $param/@name,
610+ ((concat(" as ", $type)))[$type],
611+ " := ",
612+ $varValue,
613+ ";")
614+ ," ")
615+};
616+
617+
618+declare %private function env:var-decl-without-value(
619+ $env as element(fots:environment)?,
620+ $envCase as element(fots:environment)?
621+) as xs:string?
622+{
623+ string-join(
624+ (for $param in ($env/fots:param, $envCase/fots:param)
625+ let $select := $param/@select
626+ let $type := $param/@as
627+ where (empty($select) and
628+ empty($param[@declared="true"]))
629+ return concat("declare variable $",
630+ $param/@name,
631+ ((concat(" as ", $type)))[$type],
632+ " external;"),
633+ for $source in ($env/fots:source, $envCase/fots:source)
634+ let $role := $source/@role
635+ where starts-with($role,"$")
636+ return concat("declare variable ",
637+ $role,
638+ " external;"))
639+ ," ")
640+};
641+
642+
643+(:~
644+ : Returns the string for setting the context item if needed.
645+ : @param $env environment.
646+ : @param $envBaseURI test base URI of the environment.
647+ : @return the string for setting the context item if needed.
648+ :)
649+declare function env:set-context-item(
650+ $env as element(fots:environment)?,
651+ $envBaseURI as xs:anyURI?
652+) as xs:string? {
653+ if (exists($env/fots:source[@role = "."]))
654+ then string-join((env:declare-context-item($env, $envBaseURI),
655+ 'xqxq:bind-context-item($queryID, $contextItem);')
656+ ,"&#xA;")
657+ else ()
658+};
659+
660+
661+declare %private function env:declare-context-item(
662+ $env as element(fots:environment)?,
663+ $envBaseURI as xs:anyURI?
664+) as xs:string
665+{
666+ let $ciURI := resolve-uri($env/fots:source[@role = "."]/@file, $envBaseURI)
667+ return
668+ if(empty($env/fots:source[@validation = "strict"]))
669+ then concat('variable $contextItem := doc("', $ciURI, '");')
670+ else string-join(
671+ ("&#xA;",
672+ "variable $contextItemQuery := xqxq:prepare-main-module('",
673+ env:get-schema-import($env),
674+ concat('validate { doc("', $ciURI, '")', "}',", " "),
675+ "resolver:url-resolver#2, ());",
676+ "variable $contextItem := xqxq:evaluate($contextItemQuery);")
677+ ,"&#xA;")
678+};
679+
680+
681+(:~
682+ : Returns the strings for variable binding in XQXQ.
683+ :
684+ : @param $env the environment of the catalog/test-set (given with 'ref').
685+ : @param $envBaseURI the relative URI for the environment.
686+ : @return the strings for variable binding in XQXQ.
687+ :)
688+declare function env:set-variables(
689+ $env as element(fots:environment)?,
690+ $envBaseURI as xs:anyURI
691+) as xs:string?
692+{
693+ if(empty($env))
694+ then ()
695+ else
696+ let $srcNames := for $source in $env/fots:source
697+ where starts-with(data($source/@role),"$")
698+ return substring-after(data($source/@role),"$"),
699+ $srcValues := for $srcName in $srcNames
700+ return concat('doc("',
701+ resolve-uri($env/fots:source[@role = concat("$",$srcName)]/@file, $envBaseURI),
702+ '")')
703+ return
704+ string-join(
705+ (for $srcName in $srcNames
706+ let $index := index-of($srcNames, $srcName)
707+ return
708+ concat('xqxq:bind-variable( $queryID, xs:QName("', $srcName, '")', ', ',
709+ $srcValues[$index], ');'),
710+ for $param in $env/fots:param
711+ let $select:= $param/@select
712+ let $file := $env/fots:source[@uri = translate($select, "'", "")]/@file
713+ let $varValue := if(starts-with($select, "'") and
714+ ends-with($select, "'") and
715+ exists($file))
716+ then concat('"',
717+ resolve-uri($file, $envBaseURI),
718+ '"')
719+ else $select
720+ let $varName := $param/@name
721+ where (exists($select) and
722+(: if there is an attribute 'declared' set to true, this means that the variable
723+ is declared within the 'test' itself :)
724+ exists($param[@declared="true"]))
725+ return
726+ concat('xqxq:bind-variable( $queryID, xs:QName("',
727+ $param/@name,
728+ '")', ', ',
729+ $varValue, ');'))
730+ , "&#xA;")
731+};
732+
733+
734+declare %private function env:get-schema-import (
735+ $env as element(fots:environment)?
736+) as xs:string
737+{
738+ if (empty($env))
739+ then ""
740+ else
741+ let $namespace := $env/fots:namespace[@uri = data($env/fots:schema/@uri)]
742+ let $prefix as xs:string := if(exists($namespace))
743+ then xs:string(data($namespace/@prefix))
744+ else "p"
745+ return
746+ if($prefix = "")
747+ then concat('import schema default element namespace "',
748+ $env/fots:schema/@uri,
749+ '";&#xA;')
750+ else concat('import schema namespace ',
751+ $prefix,
752+ ' = "',
753+ $env/fots:schema/@uri,
754+ '";&#xA;')
755+};
756+
757+
758+(:~
759+ : Returns the XQXQ URL resolver declaration.
760+ : @param $case the test case.
761+ : @param $env the environment.
762+ : @param $envBaseURI URI of the environment.
763+ : @param $testSetBaseURI URI to the test set that defines the test case.
764+ : @return the XQXQ URL resolver declaration.
765+ :)
766+declare function env:resolver(
767+ $case as element(fots:test-case),
768+ $env as element(fots:environment)?,
769+ $envBaseURI as xs:anyURI?,
770+ $testSetBaseURI as xs:anyURI
771+) as xs:string?
772+{
773+ let $envSchema := $env/fots:schema,
774+ $tcSchema := $case/fots:environment/fots:schema,
775+ $schemas := ($envSchema, $tcSchema),
776+ $modules := $case/fots:module,
777+ $resources := ($env/fots:resource, $case/fots:environment/fots:schema)
778+ return
779+ if (empty($schemas) and empty($modules) and empty($resources))
780+ then ()
781+ else string-join(
782+ ("declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';",
783+ $env:hof,
784+ "declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {",
785+ "switch($entity)",
786+ if (exists($schemas))
787+ then string-join(("case 'schema'",
788+ " return switch($namespace)",
789+ (for $schema in $envSchema
790+ return concat(" case '",
791+ data($schema/@uri),
792+ "' return doc('",
793+ resolve-uri($schema/@file, $envBaseURI),
794+ "')"),
795+ for $schema in $tcSchema
796+ return concat(" case '",
797+ data($schema/@uri),
798+ "' return doc('",
799+ resolve-uri($schema/@file, $testSetBaseURI),
800+ "')")),
801+ " default return ()"),
802+ "&#xA;")
803+ else (),
804+ if (exists($modules))
805+ then string-join(("case 'module'",
806+ " return switch($namespace)",
807+ for $module in $modules
808+ return concat(" case '",
809+ data($module/@uri),
810+ "' return unparsed-text('",
811+ resolve-uri($module/@file, $testSetBaseURI),
812+ "') "),
813+ " default return ()"),
814+ "&#xA;")
815+ else (),
816+ if (exists($resources)) then
817+ string-join(("case ''",
818+ " return switch($namespace)",
819+ for $resource in $resources
820+ return concat(" case '",
821+ data($resource/@uri),
822+ "' return unparsed-text('",
823+ resolve-uri($resource/@file, $envBaseURI),
824+ "'",
825+ if(exists($resource/@encoding))
826+ then concat (",'",
827+ data($resource/@encoding),
828+ "'")
829+ else (),
830+ ") "),
831+ " default return ()")
832+ ,"&#xA;")
833+ else ()
834+ , "default return ()","};"),
835+ "&#xA;")
836+};
837+
838+
839+(:~
840+ : Checks the dependencies according to the Zorba manifest.
841+ :
842+ : @param $deps the dependencies of the test set and test case
843+ : @param $zorbaManifest Zorba manifest document.
844+ : @return if true empty string, otherwise returns a string with the
845+ : dependencies that were not matched.
846+ :)
847+declare function env:check-dependencies(
848+ $deps as element(fots:dependency)*,
849+ $zorbaManifest
850+) as xs:string*
851+{
852+ if(empty($deps))
853+ then ()
854+ else
855+ for $dep in $deps
856+ let $satisfied := if(exists($dep/@satisfied))
857+ then data($dep/@satisfied)
858+ else "true"
859+ let $zorbaDep := $zorbaManifest//fots:dependency[ @type = $dep/@type and
860+ @value = $dep/@value and
861+ @satisfied = $satisfied]
862+ return
863+ if(empty($zorbaDep))
864+ then concat("Dependency (type=",
865+ $dep/@type,
866+ ", value=",
867+ $dep/@value,
868+ ", satisfied=",
869+ $satisfied,
870+ ") was not met. ")
871+ else ()
872+};
873+
874+
875+(:~
876+ : Retrieves the environment from a test-set/catalog given an environment name.
877+ : @param $catalog FOTS catalog file.
878+ : @param $testSet test set.
879+ : @param $envName name of the environment.
880+ : @return the environment with the given name.
881+ :)
882+declare function env:get-environment (
883+ $catalog,
884+ $testSet as element (fots:test-set),
885+ $envName as xs:string
886+) as element(fots:environment)?
887+{
888+ let $envTestSet := $testSet/test-set//environment[@name = $envName]
889+ return
890+ if (empty($envTestSet))
891+ then $catalog/catalog//environment[@name = $envName]
892+ else $envTestSet
893+};
894
895=== added file 'test/fots_driver/errors.xq'
896--- test/fots_driver/errors.xq 1970-01-01 00:00:00 +0000
897+++ test/fots_driver/errors.xq 2012-12-18 11:57:23 +0000
898@@ -0,0 +1,36 @@
899+(:
900+ : Copyright 2006-2011 The FLWOR Foundation.
901+ :
902+ : Licensed under the Apache License, Version 2.0 (the "License");
903+ : you may not use this file except in compliance with the License.
904+ : You may obtain a copy of the License at
905+ :
906+ : http://www.apache.org/licenses/LICENSE-2.0
907+ :
908+ : Unless required by applicable law or agreed to in writing, software
909+ : distributed under the License is distributed on an "AS IS" BASIS,
910+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
911+ : See the License for the specific language governing permissions and
912+ : limitations under the License.
913+ :)
914+
915+(:~
916+ : Zorba FOTS driver errors
917+ : @author Sorin Nasoi
918+ :)
919+
920+module namespace err =
921+ "http://www.zorba-xquery.com/fots-driver/errors";
922+
923+(:~
924+ : Errors namespace URI.
925+:)
926+declare variable $err:errNS as xs:string :=
927+ "http://www.zorba-xquery.com/fots-driver/errors";
928+
929+(:~
930+ : xs:QName with
931+ : namespace URI = "http://www.w3.org/2010/09/qt-fots-catalog/errors"
932+ : and local name "err:errNA"
933+:)
934+declare variable $err:errNA as xs:QName := fn:QName($err:errNS, "check:errNA");
935
936=== added file 'test/fots_driver/evaluate.xq'
937--- test/fots_driver/evaluate.xq 1970-01-01 00:00:00 +0000
938+++ test/fots_driver/evaluate.xq 2012-12-18 11:57:23 +0000
939@@ -0,0 +1,565 @@
940+(:
941+ : Copyright 2006-2011 The FLWOR Foundation.
942+ :
943+ : Licensed under the Apache License, Version 2.0 (the "License");
944+ : you may not use this file except in compliance with the License.
945+ : You may obtain a copy of the License at
946+ :
947+ : http://www.apache.org/licenses/LICENSE-2.0
948+ :
949+ : Unless required by applicable law or agreed to in writing, software
950+ : distributed under the License is distributed on an "AS IS" BASIS,
951+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
952+ : See the License for the specific language governing permissions and
953+ : limitations under the License.
954+ :)
955+
956+(:~
957+ : Zorba FOTS driver evaluate
958+ : @author Sorin Nasoi
959+ :)
960+
961+module namespace eval =
962+ "http://www.zorba-xquery.com/fots-driver/evaluate";
963+
964+import schema namespace output =
965+ "http://www.w3.org/2010/xslt-xquery-serialization";
966+
967+import module namespace xqxq =
968+ "http://www.zorba-xquery.com/modules/xqxq";
969+import module namespace schema =
970+ "http://www.zorba-xquery.com/modules/schema";
971+
972+import module namespace fots-err =
973+ "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
974+import module namespace util =
975+ "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
976+
977+declare namespace err =
978+ "http://www.w3.org/2005/xqt-errors";
979+declare namespace fots =
980+ "http://www.w3.org/2010/09/qt-fots-catalog";
981+
982+declare namespace ann =
983+ "http://www.zorba-xquery.com/annotations";
984+
985+declare namespace features =
986+ "http://www.zorba-xquery.com/options/features";
987+declare option features:enable "hof";
988+
989+(:~
990+ : Checks if the result matches the assertions.
991+ : @param $result actual result.
992+ : @param $expResult expected result.
993+ : @param $showResult is true the verbose mode is assumed.
994+ : @return the results of assertion evaluations.
995+ :)
996+declare %ann:sequential function eval:result(
997+ $result as item()*,
998+ $expResult as element(),
999+ $showResult as xs:boolean?
1000+) as element()? {
1001+ let $err := eval:check-assertion($result,
1002+ $expResult,
1003+ (),
1004+ "",
1005+ $showResult)
1006+ return if(empty($err))
1007+ then ()
1008+ else
1009+ <out>
1010+ <expected-result>{$expResult}</expected-result>
1011+ {
1012+ if($showResult)
1013+ then (<result>{$result}</result>,
1014+ <errors>{$err}</errors>)
1015+ else ()
1016+ }
1017+ </out>
1018+};
1019+
1020+(:~
1021+ : Checks if the error found matches the expected error (if any).
1022+ : @param $result actual result.
1023+ : @param $expResult expected result.
1024+ : @param $code err:code.
1025+ : @param $errorDescription err:description.
1026+ : @param $showResult is true the verbose mode is assumed.
1027+ : @return the results of error evaluation.
1028+ :)
1029+declare %ann:sequential function eval:error(
1030+ $result as item()*,
1031+ $expResult as element(),
1032+ $code as xs:QName?,
1033+ $errorDescription as xs:string?,
1034+ $showResult as xs:boolean?
1035+) as xs:string* {
1036+ if(empty($result)) then
1037+ let $err := eval:error-code($code,
1038+ $errorDescription,
1039+ $expResult)
1040+ return $err
1041+ else
1042+ concat("Expected error &#xA;",
1043+ data($expResult/@code),
1044+ ",&#xA; found result ",
1045+ if ($showResult)
1046+ then string-join(util:serialize-result($result),' ')
1047+ else ())
1048+};
1049+
1050+declare %private %ann:sequential function eval:error-code(
1051+ $code as xs:QName?,
1052+ $errorDescription as xs:string?,
1053+ $expResult as element()
1054+) as xs:string* {
1055+ let $assertName := local-name($expResult)
1056+ return
1057+ if( $assertName = "error")
1058+ then
1059+ if (exists($expResult[@code = "*"]) or
1060+ exists($expResult[@code = local-name-from-QName($code)]))
1061+ then ()
1062+ else concat("Expected error: ",
1063+ data($expResult/@code),
1064+ ". Found error: ",
1065+ local-name-from-QName($code))
1066+ else if (($assertName = "any-of") or ($assertName = "all-of"))
1067+ then eval:check-assertion((),
1068+ $expResult,
1069+ $code,
1070+ $errorDescription,
1071+ fn:true())
1072+ else concat("Expected result: &#xA;",
1073+ data($expResult),
1074+ ".&#xA; Found error ",
1075+ local-name-from-QName($code),
1076+ " - ",
1077+ $errorDescription)
1078+};
1079+
1080+declare %private %ann:sequential function eval:check-assertion(
1081+ $result as item()*,
1082+ $expResult as element(),
1083+ $code as xs:QName?,
1084+ $errorDescription as xs:string?,
1085+ $showResult as xs:boolean?
1086+) as xs:string* {
1087+ let $test := local-name($expResult)
1088+ return switch($test)
1089+ case 'all-of'
1090+ return eval:assert-all-of($result,
1091+ $expResult,
1092+ $code,
1093+ $errorDescription,
1094+ $showResult)
1095+ case 'any-of'
1096+ return eval:assert-any-of($result,
1097+ $expResult,
1098+ $code,
1099+ $errorDescription,
1100+ $showResult)
1101+ case 'assert'
1102+ return eval:assert($result,
1103+ $expResult)
1104+ case 'assert-count'
1105+ return eval:assert-count($result,
1106+ $expResult)
1107+ case 'assert-deep-eq'
1108+ return eval:assert-deep-eq($result,
1109+ $expResult)
1110+ case 'assert-empty'
1111+ return eval:assert-empty($result)
1112+ case 'assert-eq'
1113+ return eval:assert-eq($result,
1114+ $expResult)
1115+ case 'assert-false'
1116+ return eval:assert-false($result)
1117+ case 'assert-permutation'
1118+ return eval:assert-permutation($result,
1119+ $expResult)
1120+ case 'assert-xml'
1121+ return eval:assert-xml($result,
1122+ $expResult)
1123+ case 'assert-serialization-error'
1124+ return eval:assert-serialization-error($result,
1125+ $expResult)
1126+ case 'assert-string-value'
1127+ return eval:assert-string-value($result,
1128+ $expResult)
1129+ case 'assert-true'
1130+ return eval:assert-true($result)
1131+ case 'assert-type'
1132+ return eval:assert-type($result,
1133+ $expResult)
1134+ case 'serialization-matches'
1135+ return eval:serialization-matches($result,
1136+ $expResult)
1137+ case 'error'
1138+ return eval:error($result,
1139+ $expResult,
1140+ $code,
1141+ $errorDescription,
1142+ $showResult)
1143+ default
1144+ return error($fots-err:errNA,
1145+ "&#xA;The requested assertion type is not implemented.")
1146+};
1147+
1148+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_any-of :)
1149+declare %private %ann:sequential function eval:assert-any-of(
1150+ $result as item()*,
1151+ $expResult as element(),
1152+ $code as xs:QName?,
1153+ $errorDescription as xs:string?,
1154+ $showResult as xs:boolean
1155+) as xs:string? {
1156+ let $results :=
1157+ for $tmp in $expResult/*
1158+ return <result>{
1159+ for $r in eval:check-assertion($result,
1160+ $tmp,
1161+ $code,
1162+ $errorDescription,
1163+ $showResult)
1164+ return <item>{$r}</item>
1165+ } </result>
1166+ where every $result in $results satisfies $result/item
1167+ return concat("&#xA;Assert-any-of returned: ",
1168+ string-join(util:serialize-result($results/data(item)), ' '))
1169+};
1170+
1171+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_all-of :)
1172+declare %private %ann:sequential function eval:assert-all-of(
1173+ $result as item()*,
1174+ $expResult as element(),
1175+ $code as xs:QName?,
1176+ $errorDescription as xs:string?,
1177+ $showResult as xs:boolean
1178+) as xs:string* {
1179+ for $tmp in $expResult/*
1180+ return eval:check-assertion($result,
1181+ $tmp,
1182+ $code,
1183+ $errorDescription,
1184+ $showResult)
1185+};
1186+
1187+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert :)
1188+declare %private %ann:sequential function eval:assert(
1189+ $result as item()*,
1190+ $expResult as element()
1191+) as xs:string? {
1192+ try {
1193+ {
1194+ variable $queryText := concat(
1195+ "xquery version '3.0';",
1196+ "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
1197+ "declare option o:enable 'hof';",
1198+ "declare variable $result external; ",
1199+ xs:string($expResult));
1200+ variable $queryKey := xqxq:prepare-main-module($queryText),
1201+ $queryKeyResult := xqxq:bind-variable($queryKey,
1202+ xs:QName('result'),
1203+ $result),
1204+ $queryResult := xqxq:evaluate($queryKey);
1205+
1206+ if($queryResult)
1207+ then ()
1208+ else concat("Assertion ", $expResult, " failed")
1209+ }
1210+ } catch * {
1211+ concat("&#xA;Assertion '",
1212+ $expResult,
1213+ "'&#xA; failed with error ",
1214+ $err:code, " : ", $err:description)
1215+ }
1216+};
1217+
1218+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-count :)
1219+declare %private function eval:assert-count(
1220+ $result as item()*,
1221+ $expResult as element()
1222+) as xs:string? {
1223+ if(count($result) eq xs:integer($expResult))
1224+ then ()
1225+ else "Actual number of items is different than the expected number of items."
1226+};
1227+
1228+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-deep-eq :)
1229+declare %private %ann:sequential function eval:assert-deep-eq(
1230+ $result as item()*,
1231+ $expResult as element()
1232+) as xs:string? {
1233+ try {
1234+ {
1235+ variable $queryText := concat(
1236+ "xquery version '3.0';",
1237+ "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
1238+ "declare option o:enable 'hof';",
1239+ "declare variable $x external;",
1240+ "let $y := (",string(data($expResult)),") return ",
1241+ "every $i in 1 to max((count($x),count($y))) satisfies deep-equal($x[$i],$y[$i])");
1242+ variable $queryKey := xqxq:prepare-main-module($queryText),
1243+ $queryKeyResult := xqxq:bind-variable($queryKey,
1244+ xs:QName('x'),
1245+ $result),
1246+ $queryResult := xqxq:evaluate($queryKey);
1247+ if($queryResult)
1248+ then ()
1249+ else concat("&#xA;Result is not deep-equal to '", $expResult, "'&#xA;")
1250+ }
1251+ } catch * {
1252+ concat("&#xA;Assert-deep-eq '",
1253+ $expResult,
1254+ "'&#xA; failed with error ",
1255+ $err:code,
1256+ " : ",
1257+ $err:description)
1258+ }
1259+};
1260+
1261+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-empty :)
1262+declare %private function eval:assert-empty(
1263+ $result as item()*
1264+) as xs:string? {
1265+ if(empty($result))
1266+ then ()
1267+ else "&#xA;Result is not empty as expected"
1268+};
1269+
1270+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-eq :)
1271+declare %private %ann:sequential function eval:assert-eq(
1272+ $result as item()*,
1273+ $expResult as element()
1274+) as xs:string? {
1275+ try {
1276+ {
1277+ variable $type := if (empty($result[1]) or (count($result) gt 1))
1278+ then ()
1279+ else
1280+ let $tmp := xs:string(schema:schema-type($result[1]))
1281+(: add exception for the types defined in schemas available in the environment of the tests :)
1282+ return
1283+ if (starts-with($tmp, 'xs:'))
1284+ then $tmp
1285+ else ();
1286+ variable $queryText := concat(
1287+ "declare variable $x external;",
1288+ "$x eq ",
1289+ if (starts-with(data($expResult), $type))
1290+ then data($expResult)
1291+ else concat($type,"(", data($expResult), ")"));
1292+ variable $queryKey := xqxq:prepare-main-module($queryText);
1293+
1294+ xqxq:bind-variable($queryKey,
1295+ xs:QName('x'),
1296+ $result);
1297+ variable $queryResult := xqxq:evaluate($queryKey);
1298+ if($queryResult)
1299+ then ()
1300+ else concat("&#xA;Assert-eq: Result '",
1301+ string-join(util:serialize-result($result),' '),
1302+ "' &#xA;doesn't match expected item '",
1303+ xs:string($expResult),
1304+ "'.")
1305+ }
1306+ } catch * {
1307+ concat("&#xA;Comparison to '",
1308+ $expResult/text(),
1309+ "' failed with error: ",
1310+ $err:code,
1311+ " : ",
1312+ $err:description)
1313+ }
1314+};
1315+
1316+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-true :)
1317+declare %private function eval:assert-true(
1318+ $result as item()*
1319+) as xs:string? {
1320+ if($result eq fn:true())
1321+ then ()
1322+ else "&#xA;Query doesn't evaluate to true."
1323+};
1324+
1325+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-false :)
1326+declare %private function eval:assert-false(
1327+ $result as item()*
1328+) as xs:string? {
1329+ if($result eq fn:false())
1330+ then ()
1331+ else "&#xA;Query doesn't evaluate to false."
1332+};
1333+
1334+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-permutation :)
1335+declare %private %ann:sequential function eval:assert-permutation(
1336+ $result as item()*,
1337+ $expResult as element()
1338+) as xs:string? {
1339+ try {
1340+ {
1341+ variable $queryText := concat(
1342+ "xquery version '3.0';",
1343+ "declare namespace o = 'http://www.zorba-xquery.com/options/features';",
1344+ "declare option o:enable 'hof';",
1345+ "declare variable $x external;",
1346+ "let $y := (",string(data($expResult)),") return ",
1347+ (: if count(intersection(M1,M2)) = count(union(M1,M2)) = count(M1) then the sequences are identical :)
1348+ "(count(distinct-values($x[ . = $y])) = count(distinct-values(($x, $y)))) = count(distinct-values($x))");
1349+ variable $queryKey := xqxq:prepare-main-module($queryText),
1350+ $queryKeyResult := xqxq:bind-variable($queryKey,
1351+ xs:QName('x'),
1352+ $result),
1353+ $queryResult := xqxq:evaluate($queryKey);
1354+ if($queryResult)
1355+ then ()
1356+ else concat("&#xA;Result isn't a permutation of '",
1357+ $expResult,
1358+ "'&#xA;")
1359+ }
1360+ } catch * {
1361+ concat("&#xA;Assert-permutation failed with error: ",
1362+ $err:code,
1363+ " : ",
1364+ $err:description)
1365+ }
1366+};
1367+
1368+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-xml :)
1369+declare %private function eval:assert-xml(
1370+ $result as item()*,
1371+ $expResult as element()
1372+) {
1373+(:TODO call xml-canonicalization after bug #1076919 is implemented.:)
1374+ try {
1375+ let $serRes := util:serialize-result($result),
1376+ $result1 as xs:string := string-join($serRes,''),
1377+ $result2 as xs:string := string-join($serRes,' ')
1378+ return
1379+ if((normalize-space($result1) eq normalize-space(string($expResult))) or
1380+ (normalize-space($result2) eq normalize-space(string($expResult))))
1381+ then ()
1382+ else concat("&#xA;Result '",
1383+ $result1,
1384+ "'&#xA; is different from the expected result &#xA;'",
1385+ string($expResult),
1386+ "'.")
1387+ } catch * {
1388+ concat("&#xA;Assert-xml failed with error:",
1389+ $err:code,
1390+ " : ",
1391+ $err:description)
1392+ }
1393+};
1394+
1395+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-serialization-error :)
1396+declare %private %ann:sequential function eval:assert-serialization-error(
1397+ $result as item()*,
1398+ $expResult as element()
1399+) as xs:string? {
1400+ try {
1401+ let $serializedResult as xs:string := string-join(
1402+ util:serialize-result($result), '')
1403+ return
1404+ concat("&#xA;Expected serialization error but got result: ",
1405+ $serializedResult)
1406+ } catch * {
1407+ eval:error((),
1408+ $expResult,
1409+ $err:code,
1410+ $err:description,
1411+ fn:true())
1412+ }
1413+};
1414+
1415+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_serialization-matches :)
1416+declare %private function eval:serialization-matches(
1417+ $result as item()*,
1418+ $expResult as element()
1419+) as xs:string? {
1420+ let $serResult := string-join(util:serialize-result($result,
1421+ $util:serParamXml),
1422+ ''),
1423+ $serExpResult := string-join(util:serialize-result(data($expResult),
1424+ $util:serParamXml),
1425+ '')
1426+ let $matchesFlags := data($expResult/@flags)
1427+ return
1428+ if(exists($matchesFlags))
1429+ then
1430+ if(matches($serResult, $serExpResult, $matchesFlags))
1431+ then ()
1432+ else concat("&#xA;Expected '",
1433+ $serResult,
1434+ "'&#xA; does not match &#xA;'",
1435+ $serExpResult,
1436+ "' with flags '",
1437+ $matchesFlags,
1438+ "'")
1439+ else
1440+ if(matches($serResult, $serExpResult))
1441+ then ()
1442+ else concat("&#xA;Expected ",
1443+ $serResult,
1444+ "'&#xA; does not match &#xA;'",
1445+ $serExpResult,
1446+ "'")
1447+};
1448+
1449+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-string-value :)
1450+declare %private function eval:assert-string-value(
1451+ $result as item()*,
1452+ $expResult as element()
1453+) as xs:string? {
1454+ try {
1455+ let $serRes := string-join(util:serialize-result($result), ' '),
1456+ $res := if (empty($expResult[@normalize-space="true"]))
1457+ then $serRes
1458+ else normalize-space($serRes),
1459+ $expRes := if (empty($expResult[@normalize-space="true"]))
1460+ then xs:string($expResult)
1461+ else normalize-space(xs:string($expResult))
1462+ return
1463+ if($res eq $expRes)
1464+ then ()
1465+ else concat("&#xA;Expected '",
1466+ $expRes,
1467+ "'&#xA; found &#xA;'",
1468+ $res,
1469+ "'")
1470+ } catch * {
1471+ concat("&#xA;String-value failed with error: ",
1472+ $err:code,
1473+ " : ",
1474+ $err:description)
1475+ }
1476+};
1477+
1478+(: http://dev.w3.org/2011/QT3-test-suite/catalog-schema.html#elem_assert-type :)
1479+declare %private %ann:sequential function eval:assert-type(
1480+ $result as item()*,
1481+ $expResult as element()
1482+) as xs:string? {
1483+ try {
1484+ {
1485+ variable $queryText := concat( "declare variable $x external; $x instance of ",
1486+ data($expResult));
1487+ variable $queryKey := xqxq:prepare-main-module($queryText),
1488+ $queryKeyResult := xqxq:bind-variable($queryKey,
1489+ xs:QName('x'),
1490+ $result),
1491+ $queryResult := xqxq:evaluate($queryKey);
1492+ if($queryResult)
1493+ then ()
1494+ else concat("&#xA;Result doesn't have type '",
1495+ data($expResult),
1496+ "'")
1497+ }
1498+ } catch * {
1499+ concat("&#xA;Assert-type failed with error: ",
1500+ $err:code,
1501+ " : ",
1502+ $err:description)
1503+ }
1504+};
1505
1506=== added file 'test/fots_driver/fots-driver.xq'
1507--- test/fots_driver/fots-driver.xq 1970-01-01 00:00:00 +0000
1508+++ test/fots_driver/fots-driver.xq 2012-12-18 11:57:23 +0000
1509@@ -0,0 +1,752 @@
1510+(:
1511+ : Copyright 2006-2011 The FLWOR Foundation.
1512+ :
1513+ : Licensed under the Apache License, Version 2.0 (the "License");
1514+ : you may not use this file except in compliance with the License.
1515+ : You may obtain a copy of the License at
1516+ :
1517+ : http://www.apache.org/licenses/LICENSE-2.0
1518+ :
1519+ : Unless required by applicable law or agreed to in writing, software
1520+ : distributed under the License is distributed on an "AS IS" BASIS,
1521+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1522+ : See the License for the specific language governing permissions and
1523+ : limitations under the License.
1524+ :)
1525+
1526+(:~
1527+ : Zorba FOTS driver
1528+ : @author Sorin Nasoi
1529+ :)
1530+
1531+module namespace driver =
1532+ "http://www.zorba-xquery.com/fots-driver";
1533+
1534+import module namespace functx =
1535+ "http://www.functx.com/";
1536+
1537+import module namespace xqxq =
1538+ "http://www.zorba-xquery.com/modules/xqxq";
1539+import module namespace datetime =
1540+ "http://www.zorba-xquery.com/modules/datetime";
1541+
1542+import module namespace eval =
1543+ "http://www.zorba-xquery.com/fots-driver/evaluate" at "evaluate.xq";
1544+import module namespace env =
1545+ "http://www.zorba-xquery.com/fots-driver/environment" at "environment.xq";
1546+import module namespace util =
1547+ "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
1548+import module namespace fots-err =
1549+ "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
1550+
1551+declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
1552+
1553+declare namespace err =
1554+ "http://www.w3.org/2005/xqt-errors";
1555+declare namespace fots =
1556+ "http://www.w3.org/2010/09/qt-fots-catalog";
1557+
1558+declare namespace ann =
1559+ "http://www.zorba-xquery.com/annotations";
1560+
1561+(:~
1562+ : Loops through the FOTS catalog and returns all available test set names.
1563+ : @param $fotsPath path to the FOTS catalog file.
1564+ : @param $testSetPrefixes name/criteria for the test sets
1565+ : (empty string means all).
1566+ : @return available FOTS test sets.
1567+ :)
1568+declare %ann:nondeterministic function driver:list-test-sets(
1569+ $fotsPath as xs:string,
1570+ $testSetPrefixes as xs:string*
1571+) as xs:string* {
1572+ let $doc := doc(resolve-uri($fotsPath))
1573+ return
1574+ if(string-join($testSetPrefixes,'') = '')
1575+ then
1576+ for $testSet in $doc/fots:catalog/fots:test-set
1577+ return data($testSet/@name)
1578+ else
1579+ for $prefix in $testSetPrefixes
1580+ for $testSet in $doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)]
1581+ return data($testSet/@name)
1582+};
1583+
1584+declare %private function driver:matches-dependency(
1585+ $dependencies as element(fots:dependency)*,
1586+ $filter as xs:string
1587+) as xs:boolean {
1588+ let $filter := tokenize($filter, '_')
1589+ let $depValue := $filter[1]
1590+ let $depSatisfied as xs:string := if(exists($filter[2]) and
1591+ ($filter[2] = 'true' or $filter[2]='false'))
1592+ then $filter[2]
1593+ else 'true'
1594+ return
1595+ if(xs:boolean($depSatisfied))
1596+
1597+ (: $depSatisfied = 'true' :)
1598+ then (exists($dependencies[@value = $depValue and
1599+ @satisfied = $depSatisfied]) or
1600+ exists($dependencies[@value = $depValue and empty(@satisfied)]))
1601+
1602+ (: $depSatisfied = 'false' :)
1603+ else exists($dependencies[@value = $depValue and
1604+ @satisfied = $depSatisfied])
1605+};
1606+
1607+(:~
1608+ : Loops through the given test set and returns the test cases that have the
1609+ : given dependencies defined.
1610+ : @param $testSet test set document.
1611+ : @param $dependency defined dependency
1612+ : (empty string means all test cases).
1613+ : @return matching test case names.
1614+ :)
1615+declare function driver:list-test-cases(
1616+ $testSetDoc as document-node(),
1617+ $dependency as xs:string*
1618+) as xs:string* {
1619+ if(string-join($dependency,'') = '')
1620+ then $testSetDoc//fots:test-case/@name
1621+ else for $testCase in $testSetDoc//fots:test-case
1622+ let $cond := driver:matches-dependency(($testSetDoc/fots:test-set/fots:dependency,
1623+ $testCase/fots:dependency),
1624+ $dependency)
1625+ where $cond
1626+ return$testCase/@name
1627+
1628+};
1629+
1630+(:~
1631+ : Loops through the given test sets and returns the corresponding test cases.
1632+ : @param $fotsPath path to the FOTS catalog file.
1633+ : @param $testSetPrefixes name/criteria for the test sets
1634+ : (empty string means all test cases).
1635+ : @param $dependency type of dependency that has to be met
1636+ : (empty string means all test cases).
1637+ : @return available FOTS test cases.
1638+ :)
1639+declare %ann:nondeterministic function driver:list-test-cases(
1640+ $fotsPath as xs:string,
1641+ $testSetPrefixes as xs:string*,
1642+ $dependency as xs:string*
1643+) as xs:string* {
1644+ let $doc := doc(resolve-uri($fotsPath)),
1645+ $baseUri:= resolve-uri(util:parent-folder($fotsPath))
1646+ return
1647+ if(string-join($testSetPrefixes,'') = '')
1648+ then
1649+ for $testSet in $doc/fots:catalog/fots:test-set
1650+ let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
1651+ return driver:list-test-cases($testSetDoc, $dependency)
1652+ else
1653+ for $prefix in $testSetPrefixes
1654+ for $testSet in $doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)]
1655+ let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
1656+ return driver:list-test-cases($testSetDoc, $dependency)
1657+};
1658+
1659+(:~
1660+ : Loops through the given test sets and returns the corresponding test cases.
1661+ : @param $fotsPath path to the FOTS catalog file.
1662+ : @param $testSetPrefixes name/criteria for the test sets
1663+ : (empty string means all test cases).
1664+ : @param $testCasePrefixes name/criteria for the test cases
1665+ : (empty string means all test cases).
1666+ : @param $dependency type of dependency that has to be met
1667+ : (empty string means all test cases).
1668+ : @return available FOTS test cases.
1669+ :)
1670+declare %ann:nondeterministic function driver:list-test-cases(
1671+ $fotsPath as xs:string,
1672+ $testSetPrefixes as xs:string*,
1673+ $testCasePrefixes as xs:string*,
1674+ $dependency as xs:string*
1675+) as xs:string* {
1676+ let $doc := doc(resolve-uri($fotsPath)),
1677+ $baseUri:= resolve-uri(util:parent-folder($fotsPath)),
1678+ $testCaseNames := driver:list-test-cases($fotsPath,
1679+ $testSetPrefixes,
1680+ $dependency)
1681+ return
1682+ for $prefix in $testCasePrefixes
1683+ return
1684+ for $name in $testCaseNames
1685+ where starts-with($name,
1686+ $prefix)
1687+ return $name
1688+};
1689+
1690+(:~
1691+ : Loops through all the test cases and returns those that have a 'test' node
1692+ : that matches given pattern using given flags.
1693+ : @param $fotsPath path to the FOTS catalog file.
1694+ : @param $pattern pattern.
1695+ : @param $flags flags.
1696+ : @return available FOTS test cases matching given pattern and flags.
1697+ :)
1698+declare %ann:nondeterministic function driver:list-matching-test-cases(
1699+ $fotsPath as xs:string,
1700+ $pattern as xs:string,
1701+ $flags as xs:string?
1702+) as xs:string* {
1703+ let $doc := doc(resolve-uri($fotsPath)),
1704+ $baseUri:= resolve-uri(util:parent-folder($fotsPath))
1705+ return
1706+ for $testSet in $doc/fots:catalog/fots:test-set
1707+ let $uri := resolve-uri($testSet/@file, $baseUri),
1708+ $testSetDoc := doc($uri)
1709+ for $testCase in $testSetDoc//test-case
1710+ where matches(util:get-value($testCase,
1711+ util:parent-folder($uri),
1712+ "test"),
1713+ $pattern,
1714+ $flags)
1715+ return
1716+ concat(resolve-uri($testSet/@file, $baseUri),
1717+ ", test name:",
1718+ data($testCase/@name))
1719+};
1720+
1721+declare %private function driver:list-assertions(
1722+ $case as element(fots:test-case)
1723+) as xs:string* {
1724+ distinct-values(for $assert in $case/result/descendant-or-self::*
1725+ return local-name-from-QName(node-name($assert)))
1726+};
1727+
1728+(:~
1729+ : Loops through the FOTS catalog and evaluates all test cases that have
1730+ : a certain assert-type.
1731+ : This is useful for testing the implementation of a certain assert type.
1732+ : @param $FOTSCatalogFilePath path to the FOTS catalog file.
1733+ : @param $FOTSZorbaManifestPath the path to the file that describes optional
1734+ : features and implementation defined items in Zorba.
1735+ : @param $testSetPrefixes name/criteria for the test sets (empty string
1736+ : means all).
1737+ : @param $testCasePrefixes name/criteria for the test cases (empty string
1738+ : means all).
1739+ : @param $exceptedTestCases lists of test cases that should not be run(empty
1740+ : string means all tests will be run).
1741+ : @param $exceptedTestSets lists of test sets that should not be run(empty
1742+ : string means all tests will be run).
1743+ : @param $assert lists of tests that contain a certain assert-type(empty
1744+ : string means all tests will be run).
1745+ : @param $verbose if set to TRUE it will also output the actual failures.
1746+ : @param $showResult if set to TRUE it will also show the actual result of the
1747+ : Query run.
1748+ : @return an element containing all failed tests
1749+ :)
1750+declare %ann:sequential function driver:run-fots(
1751+ $FOTSCatalogFilePath as xs:string,
1752+ $FOTSZorbaManifestPath as xs:string,
1753+ $testSetPrefixes as xs:string*,
1754+ $testCasePrefixes as xs:string*,
1755+ $exceptedTestCases as xs:string*,
1756+ $exceptedTestSets as xs:string*,
1757+ $assert as xs:string*,
1758+ $verbose as xs:boolean,
1759+ $showResult as xs:boolean
1760+) as element(fots:test-cases) {
1761+ try {
1762+ let $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
1763+ "Path to FOTS catalog.xml set to: ")),
1764+ $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
1765+ "Path to FOTSZorbaManifest set to:"))
1766+ return driver:run($FOTSCatalog,
1767+ resolve-uri(util:parent-folder($FOTSCatalogFilePath)),
1768+ $FOTSZorbaManifest,
1769+ $testSetPrefixes,
1770+ $testCasePrefixes,
1771+ $exceptedTestCases,
1772+ $exceptedTestSets,
1773+ trace($assert, "The filter for 'assert name' set to: "),
1774+ trace($verbose, "'Verbose' parameter set to: "),
1775+ $showResult)
1776+ }
1777+ catch * {
1778+ error($err:code,
1779+ concat("&#xA;Please make sure the passed 'fotsPath' points to the",
1780+ "exact location of the FOTS catalog.xml:&#xA;",
1781+ resolve-uri($FOTSCatalogFilePath),
1782+ "&#xA;and that the passed 'fotsZorbaManifestPath' points to",
1783+ "a file in the same folder as cli.xq:&#xA;",
1784+ resolve-uri($FOTSZorbaManifestPath)))
1785+ }
1786+};
1787+
1788+(:~
1789+ : Loops through the FOTS catalog and evaluates all test cases
1790+ :
1791+ : @param $FOTSCatalog the FOTS catalog.xml file.
1792+ : @param $FOTSZorbaManifest the file that describes optional features and
1793+ : implementation defined items in Zorba.
1794+ : @param $testSetPrefixes name/criteria for the test sets (empty string means
1795+ : all).
1796+ : @param $testCasePrefixes name/criteria for the test cases (empty string
1797+ : means all).
1798+ : @param $exceptedTestCases lists of test cases that should not be run(empty
1799+ : string means all tests will be run).
1800+ : @param $exceptedTestSets lists of test sets that should not be run(empty
1801+ : string means all tests will be run).
1802+ : @param $assert lists of tests that contain a certain assert-type(empty
1803+ : string means all tests will be run).
1804+ : @param $verbose if set to TRUE it will also output the actual failures.
1805+ : @param $showResult if set to TRUE it will also show the actual result of the
1806+ : Query run.
1807+ : @return an element containing all failed tests
1808+ :)
1809+declare %ann:sequential function driver:run(
1810+ $FOTSCatalog as document-node(),
1811+ $catalogBaseURI as xs:anyURI,
1812+ $FOTSZorbaManifest as document-node(),
1813+ $testSetPrefixes as xs:string*,
1814+ $testCasePrefixes as xs:string*,
1815+ $exceptedTestCases as xs:string*,
1816+ $exceptedTestSets as xs:string*,
1817+ $assert as xs:string*,
1818+ $verbose as xs:boolean,
1819+ $showResult as xs:boolean
1820+) as element(fots:test-cases) {
1821+ <test-cases>{
1822+ let $catalogTestSetNames := $FOTSCatalog//fots:test-set/@name,
1823+ $testSetNames := if ($testSetPrefixes = '')
1824+ then functx:value-except($catalogTestSetNames,
1825+ $exceptedTestSets)
1826+ else functx:value-except(
1827+ functx:value-intersect($testSetPrefixes,
1828+ $catalogTestSetNames),
1829+ $exceptedTestSets)
1830+ for $testSetName in $testSetNames
1831+ let $testSet := $FOTSCatalog//fots:test-set[@name=$testSetName],
1832+ $testSetURI := resolve-uri($testSet/@file,
1833+ $catalogBaseURI),
1834+ $testSetDoc := doc($testSetURI),
1835+ $depMet as xs:string*:= env:check-dependencies($testSetDoc/fots:test-set/fots:dependency,
1836+ $FOTSZorbaManifest)
1837+ return
1838+ if(exists($depMet))
1839+ then <test-set name="{$testSetName}">
1840+ {
1841+ for $testCase in $testSetDoc/fots:test-set/fots:test-case
1842+ let $envName := data($testCase/fots:environment/@ref),
1843+ $envTestSet := $testSetDoc/fots:test-set/fots:environment[@name = $envName],
1844+ $envCatalog := $FOTSCatalog/fots:catalog/fots:environment[@name = $envName],
1845+ $shouldRun := if ($testCasePrefixes = '')
1846+ then functx:value-except(xs:string(data($testCase/@name)),
1847+ $exceptedTestCases)
1848+ else functx:value-except(
1849+ functx:value-intersect(data($testCase/@name),
1850+ $testCasePrefixes),
1851+ $exceptedTestCases),
1852+ (:true if the tests-case has an assertion type that is requested :)
1853+ $hasReqAssert := (($assert = '') or
1854+ exists(functx:value-intersect(
1855+ driver:list-assertions($testCase),
1856+ $assert)))
1857+ where $shouldRun and $hasReqAssert
1858+ return
1859+ driver:not-applicable($testCase,
1860+ $envTestSet,
1861+ string-join($depMet,''),
1862+ $verbose)
1863+ }</test-set>
1864+ else <test-set name="{$testSetName}">
1865+ {
1866+ for $testCase in $testSetDoc/fots:test-set/fots:test-case
1867+ let $envName := data($testCase/fots:environment/@ref),
1868+ $envTestSet := $testSetDoc/fots:test-set/fots:environment[@name = $envName],
1869+ $envCatalog := $FOTSCatalog/fots:catalog/fots:environment[@name = $envName],
1870+ $shouldRun := if ($testCasePrefixes = '')
1871+ then functx:value-except(xs:string(data($testCase/@name)),
1872+ $exceptedTestCases)
1873+ else functx:value-except(
1874+ functx:value-intersect(data($testCase/@name),
1875+ $testCasePrefixes),
1876+ $exceptedTestCases),
1877+ (:true if the tests-case has an assertion type that is requested :)
1878+ $hasReqAssert := (($assert = '') or
1879+ exists(functx:value-intersect(driver:list-assertions($testCase),
1880+ $assert)))
1881+ where $shouldRun and $hasReqAssert
1882+ return
1883+ if(exists(env:check-dependencies($testCase/fots:dependency,
1884+ $FOTSZorbaManifest)))
1885+ then driver:not-applicable( $testCase,
1886+ $envTestSet,
1887+ string-join(distinct-values(env:check-dependencies($testCase/fots:dependency,
1888+ $FOTSZorbaManifest)),
1889+ ''),
1890+ $verbose)
1891+ else if(empty($envTestSet))
1892+ then driver:test( $FOTSZorbaManifest,
1893+ $testCase,
1894+ $envCatalog,
1895+ $catalogBaseURI,
1896+ ($testCase/fots:dependency,
1897+ $testSetDoc/fots:test-set/fots:dependency),
1898+ $testSetName,
1899+ $testSetURI,
1900+ $verbose,
1901+ $showResult)
1902+ else driver:test( $FOTSZorbaManifest,
1903+ $testCase,
1904+ $envTestSet,
1905+ $testSetURI,
1906+ ($testCase/fots:dependency,
1907+ $testSetDoc/fots:test-set/fots:dependency),
1908+ $testSetName,
1909+ $testSetURI,
1910+ $verbose,
1911+ $showResult)
1912+ }</test-set>
1913+ }</test-cases>
1914+};
1915+
1916+(:~
1917+ : Creates the complete query that will be evaluated by adding the necessary
1918+ : XQXQ URL resolvers.
1919+ : @param $queryText the test-case/test after all the additional prolog
1920+ : statements were added.
1921+ : @param $case the test case.
1922+ : @param $env the environment.
1923+ : @param $envBaseURI URI of the environment.
1924+ : @param $testSetBaseURI URI of the test set that defines the test case.
1925+ : @return the query that will be evaluated.
1926+ :)
1927+declare %private function driver:create-XQXQ-query(
1928+ $queryText as xs:string,
1929+ $case as element(fots:test-case),
1930+ $env as element(fots:environment)?,
1931+ $envBaseURI as xs:anyURI?,
1932+ $testSetBaseURI as xs:anyURI
1933+) as xs:string {
1934+ let $resolver as xs:string? := env:resolver($case,
1935+ $env,
1936+ $envBaseURI,
1937+ $testSetBaseURI)
1938+ return string-join(
1939+ ("import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';",
1940+ if (exists($resolver))
1941+ then $resolver
1942+ else (),
1943+ (concat("variable $queryID := xqxq:prepare-main-module('",
1944+ "&#xA;",
1945+ replace($queryText,"'","''"),
1946+ "'",
1947+ "&#xA;",
1948+ if (exists($resolver))
1949+ then ", resolver:url-resolver#2, ());"
1950+ else ");")),
1951+ env:set-context-item($env, $envBaseURI),
1952+ env:set-context-item($case/fots:environment,
1953+ $testSetBaseURI),
1954+ env:set-variables($env,
1955+ $envBaseURI),
1956+ env:set-variables($case/environment,
1957+ $testSetBaseURI),
1958+ "xqxq:evaluate($queryID)"
1959+ ),
1960+ "&#xA;")
1961+};
1962+
1963+(:~
1964+ : XQXQ invoke.
1965+ : @param $xqxqQueryText the query that will be run.
1966+ : @param $case the test case.
1967+ : @return the result of running the query with XQXQ.
1968+ :)
1969+declare %private %ann:sequential function driver:xqxq-invoke(
1970+ $xqxqQueryText as xs:string,
1971+ $case as element(fots:test-case),
1972+ $showResult as xs:boolean?,
1973+ $testSetBaseURI as xs:anyURI
1974+) {
1975+ try {
1976+ {
1977+ variable $queryKey := xqxq:prepare-main-module($xqxqQueryText);
1978+ variable $queryResult := xqxq:evaluate-sequential($queryKey);
1979+ (:TODO check if this works:)
1980+ (:variable $expResult := util:get-value($case, $testSetBaseURI, "result");:)
1981+ eval:result($queryResult,
1982+ $case/fots:result/*,
1983+ $showResult)
1984+ }
1985+ } catch * {
1986+ eval:error((),
1987+ $case/fots:result/*,
1988+ $err:code,
1989+ $err:description,
1990+ $showResult)
1991+ }
1992+};
1993+
1994+(:~
1995+ : Runs a single test case.
1996+ :
1997+ : @param $FOTSZorbaManifest the file that describes optional features and
1998+ : implementation defined items in Zorba.
1999+ : @param $case test case.
2000+ : @param $env the environment.
2001+ : @param $envBaseURI the relative URI used to calculate the full URI for the
2002+ : different children of the environment that have a "file" attribute.
2003+ : @param $deps the dependencies that should be checked for given test case.
2004+ : @param $testSetName the name of the test set.
2005+ : @param $testSetBaseURI the URI of the test set.
2006+ : @param $verbose xs:boolean indicating if a result should be returned in case
2007+ : of success or not.
2008+ : @return the result of running the test case depending on $verbose.
2009+ :)
2010+declare %ann:sequential function driver:test(
2011+ $FOTSZorbaManifest as document-node(),
2012+ $case as element(fots:test-case),
2013+ $env as element(fots:environment)?,
2014+ $envBaseURI as xs:anyURI?,
2015+ $deps as element(fots:dependency)*,
2016+ $testSetName as xs:string?,
2017+ $testSetBaseURI as xs:anyURI,
2018+ $verbose as xs:boolean,
2019+ $showResult as xs:boolean?
2020+) as element(fots:test-case)? {
2021+(:TODO Cover the "(:%VARDECL%:)"when there are tests in FOTS that use it:)
2022+try {
2023+{
2024+ variable $queryName := trace(data($case/@name),
2025+ "processing test case :");
2026+
2027+ variable $test := util:get-value($case,
2028+ $testSetBaseURI,
2029+ "test");
2030+ variable $enableHOF := env:enable-HOF-feature(($deps, $case//fots:dependency),
2031+ $test);
2032+ variable $query := string-join((env:add-xquery-version-decl(($deps, $case//fots:dependency),
2033+ $test),
2034+ env:decl-def-elem-namespace($env,
2035+ $case/fots:environment),
2036+ env:decl-base-uri($env,
2037+ $case/fots:environment),
2038+ env:decl-namespaces($env,
2039+ $case,
2040+ $testSetBaseURI),
2041+ $enableHOF,
2042+ env:decl-decimal-formats(($env/fots:decimal-format,
2043+ $case/fots:environment/fots:decimal-format)),
2044+ env:add-var-decl($env,
2045+ $case,
2046+ $envBaseURI,
2047+ $testSetBaseURI),
2048+ $test
2049+ ),"&#xA;"),
2050+ $xqxqQuery := driver:create-XQXQ-query($query,
2051+ $case,
2052+ $env,
2053+ $envBaseURI,
2054+ $testSetBaseURI),
2055+ $startDateTime := datetime:current-dateTime (),
2056+ $result := driver:xqxq-invoke($xqxqQuery,
2057+ $case,
2058+ $showResult,
2059+ $testSetBaseURI),
2060+ $duration := (datetime:current-dateTime () - $startDateTime);
2061+
2062+ if(empty($result))
2063+ then driver:pass($case,
2064+ $result,
2065+ $xqxqQuery,
2066+ $env,
2067+ (),
2068+ $duration,
2069+ $verbose)
2070+
2071+(: if the exact error code was not found, report the test as 'Pass'
2072+ with an attribute correctError=false :)
2073+ else if(exists($result) and
2074+ contains(string-join($result,''), "Expected error:") and
2075+ contains(string-join($result,''), "Found error:"))
2076+ then driver:pass($case,
2077+ $result,
2078+ $xqxqQuery,
2079+ $env,
2080+ $result,
2081+ $duration,
2082+ $verbose)
2083+ else
2084+ driver:fail($case,
2085+ $result,
2086+ $xqxqQuery,
2087+ $testSetName,
2088+ $env,
2089+ $duration,
2090+ $verbose)
2091+}
2092+} catch * {
2093+ driver:fail($case,
2094+ <result>{$err:description}</result>,
2095+ "",
2096+ $testSetName,
2097+ $env,
2098+ xs:dayTimeDuration("PT0S"),
2099+ $verbose)
2100+}
2101+};
2102+
2103+(:~
2104+ : Gives feedback on a test case that is not run when dependencies are not met.
2105+ :
2106+ : @param $case test case.
2107+ : @param $dependencyError test error returned by the dependency checking.
2108+ : @return the test case.
2109+ :)
2110+declare %private %ann:sequential function driver:not-applicable(
2111+ $case as element(fots:test-case),
2112+ $env as element(fots:environment)?,
2113+ $dependencyError as xs:string,
2114+ $verbose as xs:boolean
2115+) as element(fots:test-case)? {
2116+ trace(data($case/@name), "processing test case :");
2117+ trace($dependencyError, "Dependency error :");
2118+ if($verbose)
2119+ then
2120+ {
2121+ let $tmp := $case
2122+ return {
2123+ insert node
2124+ attribute result{'not applicable'}
2125+ as last into $tmp;
2126+
2127+ insert node
2128+ attribute comment{$dependencyError}
2129+ as last into $tmp;
2130+
2131+ insert node
2132+ <info>
2133+ {$env}
2134+ </info>
2135+ as last into $tmp;
2136+
2137+ delete node $tmp/description;
2138+ delete node $tmp/created;
2139+
2140+ $tmp
2141+ }
2142+ }
2143+ else
2144+ <test-case name="{data($case/@name)}"
2145+ result="not applicable"
2146+ comment="{$dependencyError}" />
2147+};
2148+
2149+(:~
2150+ : Gives feedback on a test case run with success.
2151+ :
2152+ : @param $case test case.
2153+ : @return the test case after certain information was added.
2154+ :)
2155+declare %private %ann:sequential function driver:pass(
2156+ $case as element(fots:test-case),
2157+ $result as item()*,
2158+ $zorbaQuery as xs:string,
2159+ $env as element(fots:environment)?,
2160+ $comment as xs:string?,
2161+ $duration as xs:dayTimeDuration,
2162+ $verbose as xs:boolean
2163+) as element(fots:test-case)? {
2164+ if($verbose)
2165+ then
2166+ {
2167+ let $tmp := $case
2168+ return {
2169+ insert node
2170+ attribute result{'pass'}
2171+ as last into $tmp;
2172+
2173+ if(exists($comment)) then
2174+ insert node
2175+ attribute correctError{'false'}
2176+ as last into $tmp;
2177+ else ();
2178+
2179+ if(exists($comment)) then
2180+ insert node
2181+ attribute comment{$comment}
2182+ as last into $tmp;
2183+ else ();
2184+
2185+ insert node
2186+ attribute executionTime{$duration}
2187+ as last into $tmp;
2188+
2189+ insert node
2190+ <info>
2191+ {$env}
2192+ <query>{$zorbaQuery}</query>
2193+ <actual-result>{$result}</actual-result>
2194+ </info>
2195+ as last into $tmp;
2196+
2197+ delete node $tmp/description;
2198+ delete node $tmp/created;
2199+
2200+ $tmp
2201+ }
2202+ }
2203+ else if(empty($comment))
2204+ then <test-case name="{data($case/@name)}"
2205+ result="pass"
2206+ executionTime="{$duration}" />
2207+ else <test-case name="{data($case/@name)}"
2208+ result="pass"
2209+ correctError="{empty($comment)}"
2210+ executionTime="{$duration}" />
2211+};
2212+
2213+(:~
2214+ : Gives feedback on a test case run without success.
2215+ :
2216+ : @param $case test case.
2217+ : @return the test case after certain information was added.
2218+ :)
2219+declare %private %ann:sequential function driver:fail(
2220+ $case as element(fots:test-case),
2221+ $result as item()*,
2222+ $zorbaQuery as xs:string,
2223+ $testSetName as xs:string?,
2224+ $env as element(fots:environment)?,
2225+ $duration as xs:dayTimeDuration,
2226+ $verbose as xs:boolean
2227+) as element(fots:test-case)? {
2228+ trace($testSetName, "test set name");
2229+ trace("above test case failed", "result");
2230+
2231+ if($verbose)
2232+ then
2233+ {
2234+ let $tmp := $case
2235+ return {
2236+ insert node
2237+ attribute result{'fail'}
2238+ as last into $tmp;
2239+
2240+ insert node
2241+ attribute executionTime{$duration}
2242+ as last into $tmp;
2243+
2244+ insert node
2245+ <info>
2246+ {$env}
2247+ <query>{$zorbaQuery}</query>
2248+ <actual-result>{$result}</actual-result>
2249+ </info>
2250+ as last into $tmp;
2251+
2252+ delete node $tmp/description;
2253+ delete node $tmp/created;
2254+
2255+ $tmp
2256+ }
2257+ }
2258+ else <test-case name="{data($case/@name)}"
2259+ result="fail"
2260+ executionTime="{$duration}"/>
2261+};
2262
2263=== added file 'test/fots_driver/reporting.xq'
2264--- test/fots_driver/reporting.xq 1970-01-01 00:00:00 +0000
2265+++ test/fots_driver/reporting.xq 2012-12-18 11:57:23 +0000
2266@@ -0,0 +1,244 @@
2267+(:
2268+ : Copyright 2006-2011 The FLWOR Foundation.
2269+ :
2270+ : Licensed under the Apache License, Version 2.0 (the "License");
2271+ : you may not use this file except in compliance with the License.
2272+ : You may obtain a copy of the License at
2273+ :
2274+ : http://www.apache.org/licenses/LICENSE-2.0
2275+ :
2276+ : Unless required by applicable law or agreed to in writing, software
2277+ : distributed under the License is distributed on an "AS IS" BASIS,
2278+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2279+ : See the License for the specific language governing permissions and
2280+ : limitations under the License.
2281+ :)
2282+
2283+(:~
2284+ : Zorba FOTS driver reporting
2285+ : @author Sorin Nasoi
2286+ :)
2287+
2288+module namespace reporting =
2289+ "http://www.zorba-xquery.com/fots-driver/reporting";
2290+
2291+import module namespace file =
2292+ "http://expath.org/ns/file";
2293+
2294+import module namespace driver =
2295+ "http://www.zorba-xquery.com/fots-driver" at "fots-driver.xq";
2296+import module namespace util =
2297+ "http://www.zorba-xquery.com/fots-driver/util" at "util.xq";
2298+import module namespace fots-err =
2299+ "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
2300+
2301+declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
2302+
2303+declare namespace err =
2304+ "http://www.w3.org/2005/xqt-errors";
2305+declare namespace fots =
2306+ "http://www.w3.org/2010/09/qt-fots-catalog";
2307+
2308+declare namespace ann =
2309+ "http://www.zorba-xquery.com/annotations";
2310+
2311+(:~
2312+ : Loops through the test-sets, runs then and creates statistics.
2313+ : @param $FOTSCatalogFilePath path to the FOTS catalog file.
2314+ : @param $FOTSZorbaManifestPath path to the FOTS Zorba manifest file.
2315+ : @param $testSetPrefixes name/criteria for the test sets( empty string means
2316+ : all).
2317+ : @param $testCasePrefixes name/criteria for the test cases(empty string means
2318+ : all).
2319+ : @param $exceptedTestCases lists of test cases that are not run( empty string
2320+ : means all tests will be run).
2321+ : @param $exceptedTestSets lists of test sets that are not run(empty string
2322+ : means all tests will be run).
2323+ : @param $verbose if set to TRUE it will also output the actual failures.
2324+ : @param $showResult if set to TRUE it will also show the actual result of the
2325+ : Query run.
2326+ : @return a report of tests run.
2327+ :)
2328+declare %ann:sequential function reporting:run-and-report(
2329+ $FOTSCatalogFilePath as xs:string,
2330+ $FOTSZorbaManifestPath as xs:string,
2331+ $testSetPrefixes as xs:string*,
2332+ $testCasePrefixes as xs:string*,
2333+ $exceptedTestCases as xs:string*,
2334+ $exceptedTestSets as xs:string*,
2335+ $assert as xs:string*,
2336+ $verbose as xs:boolean,
2337+ $showResult as xs:boolean
2338+) {
2339+try {
2340+ {
2341+ variable $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
2342+ "Path to FOTS catalog.xml set to: "));
2343+
2344+ variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
2345+
2346+ variable $FOTSZorbaManifest := doc(trace(resolve-uri($FOTSZorbaManifestPath),
2347+ "Path to FOTSZorbaManifest set to:"));
2348+
2349+ variable $failures := <fots:FOTS-test-suite-result>{
2350+ ( $FOTSZorbaManifest//fots:implementation,
2351+ $FOTSZorbaManifest//fots:dependencies-satisfied,
2352+ driver:run($FOTSCatalog,
2353+ $catalogBaseURI,
2354+ $FOTSZorbaManifest,
2355+ $testSetPrefixes,
2356+ $testCasePrefixes,
2357+ $exceptedTestCases,
2358+ $exceptedTestSets,
2359+ $assert,
2360+ $verbose,
2361+ $showResult)
2362+ )
2363+ }</fots:FOTS-test-suite-result>;
2364+
2365+ file:write("failures.xml",
2366+ $failures,
2367+ $util:writeXML);
2368+
2369+ reporting:do-reporting($FOTSCatalog,
2370+ $catalogBaseURI,
2371+ $failures,
2372+ $exceptedTestCases,
2373+ $exceptedTestSets,
2374+ $verbose)
2375+ }
2376+}
2377+catch *
2378+{
2379+ error($err:code,
2380+ $err:description,
2381+ concat("&#xA;Please make sure the passed 'fotsPath' points to the ",
2382+ "exact location of the FOTS catalog.xml:&#xA;",
2383+ resolve-uri($FOTSCatalogFilePath),
2384+ "&#xA;and that the passed 'fotsZorbaManifestPath' points to",
2385+ " a file in the same folder as cli.xq:&#xA;",
2386+ resolve-uri($FOTSZorbaManifestPath)))
2387+}
2388+};
2389+
2390+(:~
2391+ : Loops through the test cases report and creates statistics.
2392+ : @param $pathFOTSCatalog path to the FOTS catalog file.
2393+ : @param $pathFailures path to the FOTS failures.
2394+ : @param $exceptedTestCases lists of test cases that are not run( empty string
2395+ : means all tests will be run).
2396+ : @param $exceptedTestSets lists of test sets that are not run(empty string
2397+ : means all tests will be run).
2398+ : @param $verbose if set to TRUE it will also output the actual failures.
2399+ : @param $showResult if set to TRUE it will also show the actual result of the
2400+ : Query run.
2401+ : @return a report of tests run.
2402+ :)
2403+declare %ann:nondeterministic function reporting:report(
2404+ $FOTSCatalogFilePath as xs:string,
2405+ $pathFailures as xs:string,
2406+ $exceptedTestCases as xs:string*,
2407+ $exceptedTestSets as xs:string*,
2408+ $verbose as xs:boolean
2409+) as element(fots:report) {
2410+ try {
2411+ {
2412+ if(not(file:is-file($pathFailures)))
2413+ then
2414+ {
2415+ error($fots-err:errNA,
2416+ "The file failures file was not found. Suggestion: use driver:run-fots to generate it or use reporting:run-and-report function.");
2417+ }
2418+ else ();
2419+
2420+ variable $failures := parse-xml(file:read-text($pathFailures));
2421+
2422+ variable $FOTSCatalog := doc(trace(resolve-uri($FOTSCatalogFilePath),
2423+ "Path to FOTS catalog.xml set to: "));
2424+
2425+ variable $catalogBaseURI := resolve-uri(util:parent-folder($FOTSCatalogFilePath));
2426+
2427+ reporting:do-reporting($FOTSCatalog,
2428+ $catalogBaseURI,
2429+ $failures,
2430+ $exceptedTestCases,
2431+ $exceptedTestSets,
2432+ $verbose)
2433+ }
2434+ }
2435+ catch *
2436+ {
2437+ error($err:code, $err:description)
2438+ }
2439+};
2440+
2441+
2442+(:~
2443+ : Loops through the test-sets and creates statistics.
2444+ : @param $FOTSCatalog FOTS catalog file.
2445+ : @param $failures the test reported by Zorba as failed.
2446+ : @param $exceptedTestCases lists of test cases that are not run(empty string
2447+ : means all tests will be run).
2448+ : @param $exceptedTestSets lists of test sets that are not run(empty string
2449+ : means all tests will be run).
2450+ : @param $verbose is set to TRUE it will also output the actual failures.
2451+ : @return a report of tests run.
2452+ :)
2453+declare %ann:nondeterministic function reporting:do-reporting(
2454+ $FOTSCatalog as document-node(),
2455+ $catalogBaseURI as xs:anyURI,
2456+ $failures,
2457+ $exceptedTestCases as xs:string*,
2458+ $exceptedTestSets as xs:string*,
2459+ $verbose as xs:boolean
2460+) as element(fots:report) {
2461+ let $excepted := count($exceptedTestCases)
2462+ return
2463+ <report>
2464+ {
2465+ let $totalNoTests := count($failures//fots:test-set//fots:test-case),
2466+ $totalPass := sum(for $testSet in $failures//fots:test-set
2467+ return count($testSet//fots:test-case[@result ='pass'])),
2468+ $totalFail := sum(for $testSet in $failures//fots:test-set
2469+ return count($testSet//fots:test-case[@result ='fail'])),
2470+ $totalNotApplicable := sum(for $testSet in $failures//fots:test-set
2471+ return count($testSet//fots:test-case[@result ='not applicable'])),
2472+ $totalNotRun := sum(for $testSet in $failures//fots:test-set
2473+ return count($testSet//fots:test-case[@result ='notRun'])),
2474+ $executionTime := sum(for $testCase in $failures//fots:test-set//fots:test-case return xs:dayTimeDuration($testCase/@executionTime))
2475+ return
2476+ <brief totalTests="{$totalNoTests}"
2477+ totalPass="{$totalPass}"
2478+ totalFail="{$totalFail}"
2479+ totalNotApplicable="{$totalNotApplicable}"
2480+ totalNotRun="{$totalNotRun}"
2481+ totalExecutionTime="{$executionTime}"/>
2482+ }
2483+ {
2484+ for $testSetFile in $FOTSCatalog//fots:test-set
2485+ let $testSetURI := resolve-uri($testSetFile/@file,
2486+ $catalogBaseURI),
2487+ $testSetDoc := doc($testSetURI),
2488+ $testSetName := data($testSetDoc/fots:test-set/@name),
2489+ $totalNoTestCases := count($testSetDoc//fots:test-case),
2490+ $totalFailures := for $testCase in $failures//fots:test-set[@name = $testSetName]//fots:test-case[@result ="fail"]
2491+ return $testCase,
2492+ $percent := round((1 - (count($totalFailures) div $totalNoTestCases))*100,2),
2493+ $executionTime := sum(for $testCase in $failures//fots:test-set[@name = $testSetName]//fots:test-case
2494+ return xs:dayTimeDuration($testCase/@executionTime))
2495+ order by count($totalFailures) descending
2496+ return
2497+ <test-set name="{$testSetName}"
2498+ executionTime="{$executionTime}"
2499+ noFailures="{count($totalFailures)}"
2500+ noTestCases="{$totalNoTestCases}"
2501+ percent="{$percent}"
2502+ failedTestNames="{string-join( for $failure in $totalFailures
2503+ order by data($failure/@name)
2504+ return data($failure/@name)
2505+ ,",")}">
2506+ {if (not($verbose)) then $totalFailures else ()}
2507+ </test-set>
2508+ }
2509+ </report>
2510+};
2511
2512=== added directory 'test/fots_driver/tools'
2513=== added file 'test/fots_driver/tools/dependencies.xq'
2514--- test/fots_driver/tools/dependencies.xq 1970-01-01 00:00:00 +0000
2515+++ test/fots_driver/tools/dependencies.xq 2012-12-18 11:57:23 +0000
2516@@ -0,0 +1,27 @@
2517+(: this query loads a rezults.xml file and reports the number of 'non applicable' tests grouped by feature :)
2518+(:
2519+ sample usage
2520+ ./zorba -f -q ../../test/fots_driver/tools/dependencies.xq
2521+ -e pathFailures:=results_12_nov.xml
2522+ -o driver_dependencies.xml
2523+ --indent
2524+:)
2525+
2526+ import module namespace file = "http://expath.org/ns/file";
2527+
2528+ declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
2529+ declare namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
2530+
2531+ declare variable $pathFailures external;
2532+
2533+ variable $failures := fn:parse-xml(file:read-text($pathFailures));
2534+
2535+ <report> {
2536+ for $d in distinct-values(data($failures/fots:test-cases/fots:test-set/fots:test-case[@result="not applicable"]/@comment))
2537+ order by $d
2538+ return
2539+ <dependency type="{$d}"> {
2540+ <value number-of-tests="{count($failures/fots:test-cases//fots:test-set//fots:test-case[@result="not applicable" and @comment=$d])}" />
2541+ }</dependency>
2542+ }</report>
2543+
2544\ No newline at end of file
2545
2546=== added file 'test/fots_driver/tools/process.xq'
2547--- test/fots_driver/tools/process.xq 1970-01-01 00:00:00 +0000
2548+++ test/fots_driver/tools/process.xq 2012-12-18 11:57:23 +0000
2549@@ -0,0 +1,130 @@
2550+(:
2551+ : Copyright 2006-2011 The FLWOR Foundation.
2552+ :
2553+ : Licensed under the Apache License, Version 2.0 (the "License");
2554+ : you may not use this file except in compliance with the License.
2555+ : You may obtain a copy of the License at
2556+ :
2557+ : http://www.apache.org/licenses/LICENSE-2.0
2558+ :
2559+ : Unless required by applicable law or agreed to in writing, software
2560+ : distributed under the License is distributed on an "AS IS" BASIS,
2561+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2562+ : See the License for the specific language governing permissions and
2563+ : limitations under the License.
2564+ :)
2565+
2566+(:~
2567+ : Run every test case that matches a given criterion in a different process
2568+ : and report every test case that HANGS or ends in a SEG FAULT.
2569+ :
2570+ : @author Sorin Nasoi
2571+ :)
2572+
2573+
2574+import module namespace proc =
2575+ "http://www.zorba-xquery.com/modules/process";
2576+import module namespace util =
2577+ "http://www.zorba-xquery.com/fots-driver/util" at "../util.xq";
2578+import module namespace d =
2579+ "http://www.zorba-xquery.com/fots-driver" at "../fots-driver.xq";
2580+import module namespace fots-err =
2581+ "http://www.zorba-xquery.com/fots-driver/errors" at "../errors.xq";
2582+
2583+declare namespace ann =
2584+ "http://www.zorba-xquery.com/annotations";
2585+declare namespace fots =
2586+ "http://www.w3.org/2010/09/qt-fots-catalog";
2587+
2588+declare variable $fotsPath as xs:string external := "";
2589+declare variable $dependency as xs:string external := "";
2590+declare variable $testSetPrefixes as xs:string external := "";
2591+
2592+
2593+(:~
2594+ : Return the exit-code after invoking the FOTS driver with given $params.
2595+ :
2596+ : @param $params additional params.
2597+ : @return the exit-code returned by the invoked application.
2598+ :)
2599+declare %ann:sequential function local:exec(
2600+ $params as xs:string*
2601+) as xs:string {
2602+ variable $pathZorba := normalize-space(xs:string(proc:exec("pwd")/proc:stdout));
2603+
2604+ proc:exec(string-join(($pathZorba, "/zorba"),''),
2605+ ("-f", "-q", concat($pathZorba, "/../../test/fots_driver/cli.xq"),
2606+ "-e", concat("fotsPath:=", $fotsPath),
2607+ "-e", "verbose:=false",
2608+ $params
2609+ )
2610+ )/proc:exit-code
2611+};
2612+
2613+declare %private %ann:sequential function local:invoke-exec(
2614+ $testSets as element(fots:test-set)*,
2615+ $baseUri as xs:anyURI,
2616+ $dependency as xs:string*
2617+) as xs:string* {
2618+ for $testSet in $testSets
2619+ let $testSetDoc := doc(resolve-uri($testSet/@file, $baseUri))
2620+ let $testSetName := xs:string($testSet/@name)
2621+ let $testCaseNames as xs:string* := d:list-test-cases($testSetDoc,
2622+ $dependency)
2623+ return
2624+ for $testCaseName in $testCaseNames
2625+ let $exit-code :=
2626+ trace(local:exec(("-e", "mode:=run-test-case",
2627+ "-e", concat("testSetName:=", $testSetName),
2628+ "-e", concat("testCaseName:=", trace($testCaseName, "processing test case :"))
2629+ )
2630+ ),"exit-code")
2631+ where (xs:integer($exit-code) gt xs:integer(134))
2632+ return $testCaseName
2633+};
2634+
2635+(:~
2636+ : Return the name of the test cases that return an exit-code > 134.
2637+ :
2638+ : @param $fotsPath path to the FOTS catalog file.
2639+ : @param $testSetPrefixes name/criteria for the test sets.
2640+ : @param $dependency defined dependency.
2641+ : @return the exit-codes returned by the invoked applications.
2642+ :)
2643+declare %ann:sequential function local:list-test-cases(
2644+ $fotsPath as xs:string,
2645+ $testSetPrefixes as xs:string*,
2646+ $dependency as xs:string*
2647+) as xs:string* {
2648+ variable $doc := doc(resolve-uri($fotsPath)),
2649+ $baseUri:= resolve-uri(util:parent-folder($fotsPath));
2650+
2651+ if(string-join($testSetPrefixes,'') = '')
2652+ then local:invoke-exec($doc/fots:catalog/fots:test-set,
2653+ $baseUri,
2654+ $dependency)
2655+ else
2656+ for $prefix in $testSetPrefixes
2657+ return
2658+ local:invoke-exec($doc/fots:catalog/fots:test-set[starts-with(@name, $prefix)],
2659+ $baseUri,
2660+ $dependency)
2661+};
2662+
2663+if( $fotsPath = '')
2664+then fn:error($fots-err:errNA,
2665+ "please set the external variable $fotsPath to point to FOTS catalog.xml file.")
2666+else
2667+concat("'",
2668+ string-join(local:list-test-cases($fotsPath, $testSetPrefixes, $dependency),"', '"),
2669+ "'")
2670+
2671+
2672+(:
2673+local:exec(
2674+ ("-e", "mode:=run-test-case",
2675+ "-e", concat("testSetName:=", "misc-HigherOrderFunctions"),
2676+ "-e", concat("testCaseName:=", "xqhof2")
2677+ )
2678+ )
2679+:)
2680\ No newline at end of file
2681
2682=== added file 'test/fots_driver/util.xq'
2683--- test/fots_driver/util.xq 1970-01-01 00:00:00 +0000
2684+++ test/fots_driver/util.xq 2012-12-18 11:57:23 +0000
2685@@ -0,0 +1,119 @@
2686+(:
2687+ : Copyright 2006-2011 The FLWOR Foundation.
2688+ :
2689+ : Licensed under the Apache License, Version 2.0 (the "License");
2690+ : you may not use this file except in compliance with the License.
2691+ : You may obtain a copy of the License at
2692+ :
2693+ : http://www.apache.org/licenses/LICENSE-2.0
2694+ :
2695+ : Unless required by applicable law or agreed to in writing, software
2696+ : distributed under the License is distributed on an "AS IS" BASIS,
2697+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2698+ : See the License for the specific language governing permissions and
2699+ : limitations under the License.
2700+ :)
2701+
2702+(:~
2703+ : Zorba FOTS driver util
2704+ : @author Sorin Nasoi
2705+ :)
2706+
2707+module namespace util =
2708+ "http://www.zorba-xquery.com/fots-driver/util";
2709+
2710+import schema namespace output =
2711+ "http://www.w3.org/2010/xslt-xquery-serialization";
2712+
2713+import module namespace file =
2714+ "http://expath.org/ns/file";
2715+
2716+import module namespace fots-err =
2717+ "http://www.zorba-xquery.com/fots-driver/errors" at "errors.xq";
2718+
2719+declare namespace err =
2720+ "http://www.w3.org/2005/xqt-errors";
2721+declare namespace fots =
2722+ "http://www.w3.org/2010/09/qt-fots-catalog";
2723+
2724+declare namespace ann =
2725+ "http://www.zorba-xquery.com/annotations";
2726+
2727+
2728+(:~
2729+ : The serialization parameters for XML serialization.
2730+ :)
2731+ declare variable $util:serParamXml :=
2732+ <output:serialization-parameters>
2733+ <output:method value="xml" />
2734+ <output:indent value="no" />
2735+ <output:omit-xml-declaration value="yes" />
2736+ </output:serialization-parameters>;
2737+
2738+(:~
2739+ : The serialization parameters for XML serialization.
2740+ :)
2741+ declare variable $util:writeXML :=
2742+ <output:serialization-parameters>
2743+ <output:method value="xml" />
2744+ <output:indent value="yes" />
2745+ <output:omit-xml-declaration value="no" />
2746+ </output:serialization-parameters>;
2747+
2748+(:~
2749+ : Retrieve the value of from the given node that is either given as text node
2750+ : or in a file attribute.
2751+ :
2752+ : @param $case test-case element.
2753+ : @param $path the path of the test-set.
2754+ : @return the query text.
2755+ :)
2756+declare %ann:nondeterministic function util:get-value(
2757+ $case as element(fots:test-case),
2758+ $envBaseURI as xs:anyURI,
2759+ $node-name as xs:string
2760+) as xs:string {
2761+ try {
2762+ for $node in $case/descendant-or-self::*
2763+ where (fn:local-name-from-QName(fn:node-name($node)) = $node-name)
2764+ return
2765+ if(exists($node/@file))
2766+ then fn:unparsed-text(resolve-uri($node/@file, $envBaseURI))
2767+ else fn:data($node)
2768+ } catch * {
2769+ fn:error($fots-err:errNA, $err:description)
2770+ }
2771+};
2772+
2773+(:~
2774+ : returns the parent folder of the given file path.
2775+ : example: util:parent-folder('/home/user/file.ext') returns '/home/user'.
2776+ : @param $path Path.
2777+ : @return the parent folder of the given file.
2778+ :)
2779+
2780+declare function util:parent-folder(
2781+ $path as xs:string
2782+) as xs:anyURI {
2783+ xs:anyURI(fn:substring-before($path,
2784+ file:base-name($path)))
2785+};
2786+
2787+declare function util:serialize-result(
2788+ $result as item()*
2789+) as xs:string* {
2790+util:serialize-result($result,
2791+ $util:serParamXml)
2792+};
2793+
2794+declare function util:serialize-result(
2795+ $result as item()*,
2796+ $SerParams
2797+) as xs:string* {
2798+ for $res in $result
2799+ return
2800+ if($res instance of node())
2801+ then fn:serialize($res,
2802+ $SerParams)
2803+ else fn:string($res)
2804+};

Subscribers

People subscribed via source and target branches