I can't believe there's no Test::RelaxNG or similar on the CPAN. On the other hand, I can't believe there's no Test::YAML out there, either. Oh, wait, there is is Test::YAML, but it not only doesn't do anything particularly useful (that I can tell), it also relies on Spiffy. Jonathan Rockway has Test::YAML::Valid, but it only tests that YAML is valid (well, duh :). It doesn't let me test whether or not the YAML contents are correct. Of course, this is why I wrote Test::JSON, a module which I was astonished hadn't already existed.
Someone (hint, hint!), really needs to take XML, JSON, and YAML and create one giant Test::SomeCleverName module which lets people bundle all of those needs together.
For the curious, here's a rather naive implementation of Test::RelaxNG that I just wrote:
package Bermuda::Data::Test; use strict; use warnings; use Test::Builder; use XML::LibXML; use base 'Exporter'; our @EXPORT = 'is_valid_against_rng'; my $TEST = Test::Builder->new; sub is_valid_against_rng ($$;$) { my ( $xml, $schema, $name ) = @_; $name ||= 'XML validates against RNG'; my $parser = XML::LibXML->new; my $rng = XML::LibXML::RelaxNG->new( string => $schema ); eval { $rng->validate($parser->parse_string($xml)); }; if ( my $error = $@ ) { $TEST->ok( 0, $name ); $TEST->diag($error); return; } else { $TEST->ok( 1, $name ); return 1; } } 1;
This plants seeds of interesting ideas into my brain. I see that Test::XML exists but seems to be abandoned. Now I must go take some notes before I forget these things...
Re:Hmm...
Ovid on 2008-04-01T21:33:36
I was about to say that it's not abandoned as the author recently accepted a patch from me, but then I noticed that the patch was sent in 2005.
Re:Hmm...
rjray on 2008-04-01T21:52:35
Yeah, I've had some moments like that... (like realizing how long it's been since my book came out)
I am actively working on this now. Keep an eye to CPAN for something in the next 2-4 days. Still trying to think of a good base namespace that applies equally to XML, JSON and YAML.
I'm tempted to call it Test::Markup with the full knowledge that the use of the word "Markup" will wind up the YAML guys.
Woot! Ask and thou shalt receive. Thanks