File: 02metafiles.t

package info (click to toggle)
libtest-cpan-meta-yaml-perl 0.22-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 260 kB
  • ctags: 27
  • sloc: perl: 833; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w
use strict;

use Test::More  tests => 68;
use Test::CPAN::Meta::YAML::Version;

    my $syck_loaded = 0;
	eval {
	    require YAML::Syck;
	    eval "use YAML::Syck qw(LoadFile)";
	    $syck_loaded = 1;
    };
    if(!$syck_loaded){
        require YAML;
        eval "use YAML qw(LoadFile)";
    }

my $vers = '1.3';
my @tests = (
    { file => 't/samples/00-META.yml', fail => 0, errors => 0, bad => 0, faults => 0 },
    { file => 't/samples/01-META.yml', fail => 0, errors => 0, bad => 0, faults => 0 },
    { file => 't/samples/02-META.yml', fail => 1, errors => 2, bad => 1, faults => 1 },
    { file => 't/samples/03-META.yml', fail => 0, errors => 0, bad => 0, faults => 0 },
    { file => 't/samples/04-META.yml', fail => 1, errors => 1, bad => 1, faults => 1 },
    { file => 't/samples/05-META.yml', fail => 0, errors => 0, bad => 0, faults => 0 },
    { file => 't/samples/06-META.yml', fail => 1, errors => 3, bad => 1, faults => 3 },
    { file => 't/samples/07-META.yml', fail => 0, errors => 0, bad => 0, faults => 0 },
    { file => 't/samples/08-META.yml', fail => 0, errors => 0, bad => 0, faults => 0 },
    { file => 't/samples/09-META.yml', fail => 1, errors => 1, bad => 1, faults => 1 },
    { file => 't/samples/10-META.yml', fail => 1, errors => 1, bad => 1, faults => 1 },
    { file => 't/samples/11-META.yml', fail => 1, errors => 2, bad => 1, faults => 1 },
    { file => 't/samples/12-META.yml', fail => 1, errors => 1, bad => 0, faults => 0 },
    { file => 't/samples/13-META.yml', fail => 1, errors => 1, bad => 0, faults => 0 },
    { file => 't/samples/14-META.yml', fail => 1, errors => 1, bad => 0, faults => 0 },
    { file => 't/samples/15-META.yml', fail => 1, errors => 1, bad => 0, faults => 0 },
    { file => 't/samples/16-META.yml', fail => 0, errors => 0, bad => 0, faults => 0 },
);

for my $test (@tests) {
    my $yaml = LoadFile($test->{file});

    my $spec = Test::CPAN::Meta::YAML::Version->new(spec => $vers, data => $yaml);

    my $result = $spec->parse();
    my @errors = $spec->errors();

    is($result,         $test->{fail},   "check result for $test->{file}");
    is(scalar(@errors), $test->{errors}, "check errors for $test->{file}");

    if(scalar(@errors) != $test->{errors}) {
        print STDERR "# failed: $test->{file}\n";
        print STDERR "# errors: $_\n"  for(@errors);
    }
}

for my $test (@tests) {
    my $yaml = LoadFile($test->{file});

    my $spec = Test::CPAN::Meta::YAML::Version->new(data => $yaml);

    my $result = $spec->parse();
    my @errors = $spec->errors();

    is($result,         $test->{bad},    "check result for $test->{file}");
    is(scalar(@errors), $test->{faults}, "check errors for $test->{file}");

    if(scalar(@errors) != $test->{faults}) {
        print STDERR "# failed: $test->{file}\n";
        print STDERR "# errors: $_\n"  for(@errors);
    }
}