Sanity Tests

Ovid on 2008-12-16T10:52:17

Sometimes a test doesn't really need to be written because something else tests something so thoroughly that the other test isn't strictly necessary, but "isn't strictly necessary" doesn't mean "isn't useful". Case in point, try loading the following "YAML" with &YAML::LoadFile:

---
aliases:
  - &RevisionErrorXPath '/p:pips/p:import/p:error[@type="SomeError"]'
xpath_is:
  - *RevisionFailureXPath

That gives you the following error:

YAML Error: No anchor for alias '*RevisionFailureXPath'
   Code: YAML_PARSE_ERR_NO_ANCHOR
   Line: 5
   Document: 1
 at /home/ovid/trunk/deps/lib/perl5/YAML.pm line 33

Notice anything interesting there? How about no file name!?!? (I haven't reported the bug due to years of neglect for this module. Why bother?) Unfortunately, our code doesn't blow up on this until about 20 minutes into the test suite run and since we don't see which file we loaded, I was a bit annoyed. My first pass attempt to fix this failed and I was even more annoyed to have to wait another 20 minutes to find this out. As a result, I gave in an wrote the following:

#!/usr/bin/env perl

use strict;
use warnings;

use Test::Most;
use File::Find::Rule;
use YAML;

my @yaml = File::Find::Rule->file->name('*.yml')->in(qw/t aggtests/);
plan tests => scalar @yaml;

for my $yaml (@yaml) {
    lives_ok { YAML::LoadFile($yaml) } "YAML should load OK - $yaml";
}

It's now taken me 9 seconds to find the bug.

I might just rejigger out test suite so that our "sanity" tests such as this one always run first.


report that bug

rjbs on 2008-12-16T15:55:31

YAML is getting work again, although YAML.pm, now YAML::Old, is not the target of most of it.

I'd report it while stuff is happening, anyway.

Test::YAML::Valid

fireartist on 2008-12-16T17:25:32

For anyone else reading this, I'll just point to Test::YAML::Valid - which already provides yaml file testing.

Re:Test::YAML::Valid

Ovid on 2008-12-16T20:46:38

Which is an excellent module and one I should have used. Thanks!