Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday March 31, 2008
05:42 AM

No Test::RelaxNG?

[ #36010 ]

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;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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...

    --

    --rjray

    • 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.

      • Yeah, I've had some moments like that... (like realizing how long it's been since my book came out)

        --

        --rjray

  • Test::RelaxNG and Test::YAML (the hypothetical one) are in different categories IMHO. RelaxNG is XML specific validation YAML, otoh, is just a format Validating the data (not the serialization of the data) seems to be what you care about, so why not just use Test::Deep? It's complete, robust, well tested, featureful... I don't see why a data validation test suite has to be redone for every serliazation format out there. In fact, I'd much rather see RelaxNG validation become applicable to non XML format
  • 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.

    --

    --rjray

  • Woot! Ask and thou shalt receive. Thanks :)