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