Shared context for different modes not working for me

15 views
Skip to first unread message

Bob Stuart

unread,
Sep 25, 2020, 12:27:50 PM9/25/20
to xspec...@googlegroups.com
Having confessed that my last error was all namespace bugs on my part. I hope that I’m doing something silly one of you can point out.


I want to use the same data in several tests using different modes and therefore different expectations.
I got the inspiration from Jeni Tennison’s paper from XMLPrague 2009 at https://archive.xmlprague.cz/2009/presentations/Jeni-Tennison-Testing-XSLT-with-XSpec.pdf where she talked about shared Expectations.


<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="./demo.xsl">

<x:scenario label="TestShare" shared="yes">
<x:context>
<sample>asdf</sample>
<sample>asdf</sample>
</x:context>
</x:scenario>

<x:scenario label="TestShare-mode1">
<x:context mode="mode1"/>
<x:like label="TestShare"/>
<x:expect label="Shouldwork " test="./sample[1] ='asdf'"/>
</x:scenario>

<x:scenario label="TestShare-mode1">
<x:context mode="mode2"/>
<x:like label="TestShare"/>
<x:expect label="Shouldwork " test="./sample[1] ='as'"/>
</x:scenario>


</x:description>


This type of thing is another that worked in older Oxygen/XSpec but does not work anymore.

I get an error

System ID: /Applications/Oxygen XML Editor 22.1/frameworks/xspec/src/compiler/generate-common-tests.xsl
Scenario: XSpec for XSLT using XProc
XProc file: /Applications/Oxygen XML Editor 22.1/frameworks/xspec/src/harnesses/saxon/saxon-xslt-harness.xproc
Document type: XSpec
Engine name: Add-on for Calabash XProc Engine
Severity: error
Description: A sequence of more than one item is not allowed as the value of variable $new-context (<x:context>, <x:context>)


I get the same error with Calabash or Ant. Is what I was doing not the intended use of shared?

Thanks for your help again.



AirQuick

unread,
Sep 25, 2020, 7:39:09 PM9/25/20
to xspec...@googlegroups.com
After resolving x:like and @shared, your x:description is equal to this one:

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="./demo.xsl">

<x:scenario label="TestShare-mode1">
<x:context mode="mode1"/>
<x:context>
<sample>asdf</sample>
<sample>asdf</sample>
</x:context>
<x:expect label="Shouldwork " test="./sample[1] ='asdf'"/>
</x:scenario>

<x:scenario label="TestShare-mode1">
<x:context mode="mode2"/>
<x:context>
<sample>asdf</sample>
<sample>asdf</sample>
</x:context>
<x:expect label="Shouldwork " test="./sample[1] ='as'"/>
</x:scenario>

</x:description>

Since x:scenario[count(x:context) ge 2] is not allowed, it doesn't work on the current version of XSpec.
It works on older versions of XSpec (~v1.4.0), but it seems to me it's just a loophole.

You probably want to use nesting instead of sharing:

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="./demo.xsl">

<x:scenario label="base context">
<x:context>
<sample>asdf</sample>
<sample>asdf</sample>
</x:context>

<x:scenario label="mode1">
<x:context mode="mode1"/>
<x:expect label="Shouldwork " test="./sample[1] ='asdf'"/>
</x:scenario>

<x:scenario label="mode2">
<x:context mode="mode2"/>
<x:expect label="Shouldwork " test="./sample[1] ='as'"/>
</x:scenario>
</x:scenario>

</x:description>

See the "Example Nesting" page of Jeni's slide.

--
AirQuick
--
You received this message because you are subscribed to the Google Groups "XSpec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xspec-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xspec-users/11C481A4-9C69-41C6-83E2-23A60DD01C58%40gmail.com.

Bob Stuart

unread,
Sep 26, 2020, 5:33:39 PM9/26/20
to xspec...@googlegroups.com
THANKS that fixed things.

If you have an easy example of when I would use @shared and x:like? Now that I’ve got nesting I’m not able to think of a scenario for @shared.
Hate to have nesting be the new way that leaves me blind to the uses of @shared.
> To view this discussion on the web visit https://groups.google.com/d/msgid/xspec-users/c92119cb-56f6-486d-858e-4f64b89e7a40%40www.fastmail.com.

bobstu...@gmail.com

unread,
Sep 26, 2020, 5:46:08 PM9/26/20
to XSpec
Maybe I have an answer to my own question. When I want to re-use the context entirely and am not playing mode games. Although then I think I'm "just" adding expect tests that have a different grouping because of being a different scenario. 

AirQuick

unread,
Sep 26, 2020, 9:46:13 PM9/26/20
to xspec...@googlegroups.com
Apart from the schema annotation (
https://github.com/xspec/xspec/blob/3d9c0801410472e06d710f94204823bd269ca05b/src/schemas/xspec.rnc#L141-L153
), Jeni's presentation is the only explanation I've found so far. I hope
someone documents the feature: https://github.com/xspec/xspec/issues/477

I guess x:like is helpful, for example, in these cases:

- when you invoke your tested component repeatedly

<x:scenario label="call my template with lots of parameters"
shared="yes">
<x:call template="my-template">
<x:param name="p1" select="..." />
<x:param name="p2" select="..." />
...
</x:call>
</x:scenario>

<x:scenario label="with context-A">
<x:context>context-A</x:context>
<x:like label="call my template with lots of parameters" />
<x:expect label="expect something suitable for context-A"
select="..." />
</x:scenario>

<x:scenario label="with context-B">
<x:context>context-B</x:context>
<x:like label="call my template with lots of parameters" />
<x:expect label="expect something suitable for context-B"
select="..." />
</x:scenario>

- when you expect some common things

<x:scenario label="expect some common things" shared="yes">
<x:expect label="a common expectation" select="..." />
<x:expect label="another common expectation" select="..." />
...
</x:scenario>

<x:scenario label="with context-A">
<x:context>context-A</x:context>
<x:like label="expect some common things"/>
<x:expect label="expect something specific to context A"
select="..." />
</x:scenario>

<x:scenario label="with context-B">
<x:context>context-B</x:context>
<x:like label="expect some common things" />
<x:expect label="expect something specific to context-B"
select="..." />
</x:scenario>


--
AirQuick
> https://groups.google.com/d/msgid/xspec-users/eba9b9f9-0dd4-4b04-81dd-c1599887f857n%40googlegroups.com.

Bob Stuart

unread,
Sep 26, 2020, 9:57:56 PM9/26/20
to xspec...@googlegroups.com
Thanks those are good thoughts. Sharing the call template itself or a bunch of common expectations. I’ll have to keep that in mind in when writing new tests.
> To view this discussion on the web visit https://groups.google.com/d/msgid/xspec-users/8aecce315ea64e1d8398ebe3cbb06f4b%40mailso.net.

Reply all
Reply to author
Forward
0 new messages