使用xqsuite for exists-db中的库模块

时间:2017-03-06 23:13:00

标签: xquery exist-db

我喜欢编写只需调用xq文件即可执行的库模块。但是,这些还包含我想测试的功能。这样的事情some.xql

xquery version "3.0";
 import module namespace xmldb="http://exist-db.org/xquery/xmldb";
 declare namespace no="http://none";
 declare namespace test="http://exist-db.org/xquery/xqsuite";

 declare 
    %test:arg('1')
    %test:assertEquals('2')
    function no:something ($num as xs:string?) as xs:string {
     return 
          $num + 1
};

 xmldb:store('/db/data/', 'two.xml',<root>{no:something(1)}</root>)

但是我无法测试整个模块或其中的no:something函数。使用以下方法访问其他上下文中的函数没有问题:

import module namespace no="http://none" at "some.xql";

然而,当尝试从包装函数运行测试套件时,我不断收到xpty00004错误:

xquery version "3.0";
 import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
 test:suite(
     inspect:module-functions(xs:anyURI("some.xql"))
)

我尝试了获取no:some函数的不同变体,但没有锁定。我只是编写非常糟糕的查询,使用xqsuite错误,或者这是一个错误?

1 个答案:

答案 0 :(得分:2)

您的some.xql主模块,您只能导入和测试库模块中的功能。

请考虑重构为no.xqm

等库模块
xquery version "3.0";

module namespace no="http://none";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare 
  %test:arg('1')
  %test:assertEquals('2')
function no:something ($num as xs:string?) as xs:string {
  $num + 1
};

您的应用主模块some.xq

xquery version "3.0";

import module namespace no="http://none" at "no.xqm";

xmldb:store('/db/data/', 'two.xml',<root>{no:something(1)}</root>

您的测试运行器主模块tests.xq

xquery version "3.0";
import module namespace test="http://exist-db.org/xquery/xqsuite" 
at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";

test:suite(
    inspect:module-functions(xs:anyURI("no.xqm"))
)