eXist-db / exist

eXist Native XML Database and Application Platform
https://exist-db.org
GNU Lesser General Public License v2.1
429 stars 179 forks source link

XQSuite: %test:stats causes NullPointerException #1752

Open mathias-goebel opened 6 years ago

mathias-goebel commented 6 years ago

What is the problem

Using XQSuite Unit tests in eXist 4.0.0 with %test:stats causes an NullPointerException. All tests will fail until db restart.

Describe how to reproduce or add a test

xquery version "3.1";
(:~ Test Module :)
module namespace tests="https://sade.textgrid.de/ns/test";

import module namespace config="https://sade.textgrid.de/ns/config" at "config.xqm";
import module namespace app="https://sade.textgrid.de/ns/app" at "app.xqm";

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

declare variable $tests:node := <node/>;
declare variable $tests:model := map{};

(: ******* :)
(: * APP * :)
(: ******* :)

declare
    %test:assertXPath("matches($result, ""^20\d{2}$"")")
function test:app-currentyear() {
    app:currentyear($tests:node, $tests:model)
};

(: ********** :)
(: * CONFIG * :)
(: ********** :)

declare
    %test:stats
    %test:assertExists
function tests:config-app-root() {
    $config:app-root
};

returns on first run:

<testsuites>
  <testsuite package="http://exist-db.org/xquery/xqsuite" timestamp="2018-02-26T08:10:51.921+01:00" failures="0" pending="0" tests="1" time="PT0.03S">
    <testcase name="app-currentyear" class="test:app-currentyear"/>
</testsuite>
<testsuite package="https://sade.textgrid.de/ns/test" timestamp="2018-02-26T08:10:51.934+01:00" failures="0" pending="0" tests="1" time="PT0.01S">
  <testcase name="config-app-root" class="tests:config-app-root">
    <error type="java:java.lang.NullPointerException" message=""/>
  </testcase>
</testsuite> 
</testsuites>

on any later run until restarting eXist:

<testsuites>
<testsuite package="http://exist-db.org/xquery/xqsuite" timestamp="2018-02-26T08:12:24.472+01:00" failures="0" pending="0" tests="1" time="PT0.008S">
  <testcase name="app-currentyear" class="test:app-currentyear">
    <error type="java:java.lang.NullPointerException" message=""/>
  </testcase>
</testsuite>
<testsuite package="https://sade.textgrid.de/ns/test" timestamp="2018-02-26T08:12:24.483+01:00" failures="0" pending="0" tests="1" time="PT0.007S">
  <testcase name="config-app-root" class="tests:config-app-root">
    <error type="java:java.lang.NullPointerException" message=""/>
  </testcase
 </testsuite>
</testsuites>

Context information

Please always add the following information

dizzzz commented 6 years ago

to be able to reproduce.... don't we need config.xqm and app.xqm? The test is not self containing.... (as suggested in the issue template)

mathias-goebel commented 6 years ago

sure, config is (standard)

declare variable $config:app-root :=
    let $rawPath := system:get-module-load-path()
    let $modulePath :=
        (: strip the xmldb: part :)
        if (starts-with($rawPath, "xmldb:exist://")) then
            if (starts-with($rawPath, "xmldb:exist://embedded-eXist-server")) then
                substring($rawPath, 36)
            else
                substring($rawPath, 15)
        else
            $rawPath
    return
        substring-before($modulePath, "/modules");

app is:

declare function app:currentyear($node as node(), $model as map(*)) {
    year-from-date( current-date() )
};

but anyway, no matter whats in config or app, as long as the named functions/variables are exposed by the module, %test:stats will cause this issue here.

dizzzz commented 6 years ago

ok, clear, thnx for the addition. We'll investigate your report.

adamretter commented 6 years ago

@mathias-goebel just to be clear is the problem with 4.0.0 or 4.1-SNAPSHOT?

mathias-goebel commented 6 years ago

4.0.0

adamretter commented 6 years ago

@mathias-goebel Okay, did you have the problem in 3.6.1?

mathias-goebel commented 6 years ago

not checked yet. should i do this?

adamretter commented 6 years ago

@mathias-goebel Have you used it in a previous version, and if so what version? I am just trying to understand if this is a regression or not?

mathias-goebel commented 6 years ago

sorry, i am just about to setup all unit tests in this application. so there is no previous version where i did the same.

adamretter commented 6 years ago

@mathias-goebel okie dokie, we can treat it as a new bug then...