-
Notifications
You must be signed in to change notification settings - Fork 4
/
fots.xqm
146 lines (137 loc) · 4.59 KB
/
fots.xqm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
(:~
: XQuery driver for the QT3 Test Suite.
:
: @author BaseX Team 2005-11, BSD License
: @author Leo Wörteler
: @version 0.1
:)
module namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
import module namespace env = "http://www.w3.org/2010/09/qt-fots-catalog/environment"
at "fots-environment.xqm";
import module namespace check = "http://www.w3.org/2010/09/qt-fots-catalog/check"
at 'fots-check.xqm';
declare default element namespace "http://www.w3.org/2010/09/qt-fots-catalog";
(:~
: Loops throgh the test set and evaluates all test cases.
: @param $path - path to the FOTS catalog file
: @return an element containing all failed tests
:)
declare function fots:run(
$eval as function(xs:string) as item()*,
$path as xs:string
) as element(fots:failures) {
fots:run($eval, $path, function($name, $val) { true() }, '', '')
};
(:~
: Loops throgh the test set and evaluates all test cases.
: @param $path - path to the FOTS catalog file
: @param $exclude - predicate function for excluding dependencies
: @return an element containing all failed tests
:)
declare function fots:run(
$eval as function(xs:string) as item()*,
$path as xs:string,
$exclude as function(xs:string, xs:string) as xs:boolean
) as element(fots:failures) {
fots:run($eval, $path, $exclude, '', '')
};
(:~
: Loops throgh the test set and evaluates all test cases.
: @param $path - path to the FOTS catalog file
: @param $exclude - predicate function for excluding dependencies
: @param $catalog - name f the catalog to use (empty string means all)
: @return an element containing all failed tests
:)
declare function fots:run(
$eval as function(xs:string) as item()*,
$path as xs:string,
$exclude as function(xs:string, xs:string) as xs:boolean,
$catalog as xs:string
) as element(fots:failures) {
fots:run($eval, $path, $exclude, $catalog, '')
};
(:~
: Loops throgh the test set and evaluates all test cases.
: @param $path - path to the FOTS catalog file
: @param $exclude - predicate function for excluding dependencies
: @param $catalog - name f the catalog to use (empty string means all)
: @param $prefix - prefix of test-cases to use (empty string means all)
: @return an element containing all failed tests
:)
declare function fots:run(
$eval as function(xs:string) as item()*,
$path as xs:string,
$exclude as function(xs:string, xs:string) as xs:boolean,
$catalog as xs:string,
$prefix as xs:string
) as element(fots:failures) {
<failures>{
let $doc := doc(concat($path, 'catalog.xml')),
$env := $doc//environment
for $set in $doc//test-set[starts-with(@name, $catalog)]
let $href := $set/@href,
$doc := doc(concat($path, $href))
for $case in $doc//test-case[starts-with(@name, $prefix)]
let $env := $env | $doc//environment,
$map := env:environment($case/environment, $env)
where not(map:contains($map, 'collation'))
and fold-left(
function($rest, $dep) {
$rest and not($exclude($dep/@type, $dep/@value))
},
true(),
$case/dependency
)
return fots:test($eval, $case, $map, $path, replace($href, '/.*','/'))
}</failures>
};
(:~
: Runs a single test.
:
: @param $case - test-case element
: @param $map - environment map
: @param $path - path to the test suite
: @param $sub - relative path to the test group
: @return <code>()</code> on success, the failed
: test-case element with additional information otherwise
:)
declare function fots:test(
$eval as function(xs:string) as item()*,
$case as element(fots:test-case),
$map as map(*),
$path as xs:string,
$sub as xs:string
) as element(fots:test-case)? {
let $query := $case/test/text(),
$source := $map('source'),
$prolog := env:prolog($map, $path, $sub),
$query := string-join(($prolog, $query), '
'),
$result :=
try {
let $res := $eval($query)
return check:result($eval, $res, $case/result/*)
} catch * {
check:error($err:code, $err:description, $case/result/*)
}
return if(empty($result)) then ()
else fots:wrong($case, $result, $query)
};
(: gives feedback on an erroneous query :)
declare function fots:wrong(
$test as element(fots:test-case),
$result as item()*,
$query as xs:string
) as element(fots:test-case)? {
copy $c := $test
modify (
insert node
<wrong>
<query>{ $query }</query>
{$result}
</wrong> into $c,
delete node $c/description,
delete nodes $c/descendant::comment()
)
return $c
};