1 package Parse::CPAN::Meta::Test;
8 use vars qw{@ISA @EXPORT};
11 @ISA = qw{ Exporter };
13 tests yaml_ok yaml_error slurp load_ok
18 sub test_data_directory {
21 ? File::Spec->catdir(File::Spec->updir, qw(lib Parse CPAN Meta t data))
22 : File::Spec->catdir(qw(t data))
26 # 22 tests per call to yaml_ok
27 # 4 tests per call to load_ok
29 return ( tests => count(@_) );
33 my $yaml_ok = shift || 0;
34 my $load_ok = shift || 0;
35 my $single = shift || 0;
36 my $count = $yaml_ok * 3 + $load_ok * 4 + $single;
43 my $name = shift || 'unnamed';
45 # Does the string parse to the structure
46 my $yaml_copy = $string;
47 my @yaml = eval { Parse::CPAN::Meta::Load( $yaml_copy ); };
48 Test::More::is( $@, '', "$name: Parse::CPAN::Meta parses without error" );
49 Test::More::is( $yaml_copy, $string, "$name: Parse::CPAN::Meta does not modify the input string" );
51 Test::More::skip( "Shortcutting after failure", 1 ) if $@;
52 Test::More::is_deeply( \@yaml, $array, "$name: Parse::CPAN::Meta parses correctly" );
55 # Return true as a convenience
61 my $yaml = eval { Parse::CPAN::Meta::Load( $string ); };
62 Test::More::like( $@, qr/$_[0]/, "YAML::Tiny throws expected error" );
68 open( FILE, " $file" ) or die "open($file) failed: $!";
70 close( FILE ) or die "close($file) failed: $!";
78 Test::More::ok( -f $file, "Found $name" ) or Test::More::diag("Searched at '$file'");
79 Test::More::ok( -r $file, "Can read $name" );
80 my $content = slurp( $file );
81 Test::More::ok( (defined $content and ! ref $content), "Loaded $name" );
82 Test::More::ok( ($size < length $content), "Content of $name larger than $size bytes" );