Hi,
Been a long time since posting. Work is very busy recently. Luckily for me a lot of it involves XQuery ;-)
I am elaborating some examples [1] that show off the use of my Origami [2] library. The most promising ones I will turn in to blog posts or a wiki at some point.
Recently I've been reading a bit about generative testing (or property-based testing) and libraries like Haskell's QuickCheck. I hope to be able to show that we can use such techniques in combination with RelaxNG and the concepts that Eric van der Vlist describes in Examplotron [3] to mutate XML instances guided by a schema that I can then turn into automatically generated tests.
It's still early days and time is limited but I did stumble onto something interesting that I wanted to share here. If you already use similar techniques I would be very interested to hear about it.
I was contemplating if it was possible to create anonymous unit test functions that I can invoke with generated test input.
So, a bit to my amazement, the following works:
let $equals := %unit:test function($a,$b) { unit:assert-equals($a,$b, 'Not equal') } return $equals(4,3)
This function raises the unit:UNIT0001 exception with the message "Item 1: 3 expected, 4 returned". Cool!
So if this is possible can we also catch a failure and turn it into data?
let $equals := %unit:test function($a,$b) { unit:assert-equals($a,$b, 'Not equal') } return try { $equals(4,3) } catch * { <error> <code>{ $err:code }</code> <description>{ $err:description }</description> <value>{ $err:value }</value> <module>{ $err:module }</module> <line-number>{ $err:line-number }</line-number> <column-number>{ $err:column-number }</column-number> </error> }
This too works and produces an XML fragment recording the failure. Very cool!
<error> <code>unit:UNIT0001</code> <description>Item 1: 3 expected, 4 returned.</description> <value>Not equal</value> <module>.../origami-examples/check/demo.xq</module> <line-number>23</line-number> <column-number>24</column-number> </error>
I am not sure if this a hidden or an intentional feature of the BaseX unit module. I sure hope that it doesn't go away in future releases as I intend to leverage this in an alternative testing module.
BaseX, the gift that keeps on giving, thanks to all that make it possible.
--Marc
[1] https://github.com/xokomola/origami-examples [2] https://github.com/xokomola/origami [3] http://examplotron.org/