xsl-list
[Top] [All Lists]

Re: [xsl] junit test... for xslt2?

2010-03-08 04:23:24
On 8 March 2010 09:20, Dave Pawson <davep(_at_)dpawson(_dot_)co(_dot_)uk> wrote:
On 08/03/10 09:12, Andrew Welch wrote:


Ultimately though, for checking the "correctness" of the result of a
transform, I think you just need to execute XPaths against it, which
are more tolerant of subtle changes in the output.  That was the idea
behind xchecker, which then became running xquery and transforms to
overcome the limitations of what xpath can check.

Would you expand on that a little please Andrew?
I can see (initially) that xpath comparisons would
be easier (ws etc), but what made you change to
'running xquery and transforms'?
What was xpath missing?

The idea behind xchecker is that each test returns true() or a
sequence of true()s to pass, and fails if any item is the sequence is
not true(). For example, checking each <para> with @type = 'simple'
should not have a title:

for $p in //para[(_at_)type eq 'simple'] return not(exists($p/title))

That returns a sequence of booleans.

As any value other than true causes the test to fail, you can rewrite
that to return a nicer message:

for $p in //para[(_at_)type eq 'simple'] return
  if not(exists($p/title)) then
    true()
  else
    concat('Simple paras must not have titles: ', $p/@id)

So now it returns a sequence of true()s and/or strings.  Any values
other than true are returned as the failure message, so it can be a
complex as needed.  There are no "asserts".

Allowing transforms or xqueries to be just makes it easier to test
what you need (say you need a variable) and construct a better failure
message, and means you can test however you like.. comparing xml if
you really wanted to, or just simple xpaths.


I'm thinking of testing the output of a single template
against an expected 'structure'.

Using a schema aware transform you could add an "as" attribute to the
template which refers to a custom type, or if using a basic processor
just validate the result yourself.

Using something like xchecker you could use straight xpaths, or use
deep-equal() to compare expected and actual, or some other way you can
think of thats possible using xslt or xquery.


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--