summaryrefslogtreecommitdiff
path: root/cpan/CPAN-Meta/t/load-bad.t
blob: 22a651079ee59074f45e125dab72a8da4907ca84 (plain)
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
use strict;
use warnings;
use Test::More 0.88;

use CPAN::Meta;
use File::Spec;
use IO::Dir;

sub _slurp { do { local(@ARGV,$/)=shift(@_); <> } }

delete $ENV{$_} for qw/PERL_JSON_BACKEND PERL_YAML_BACKEND/; # use defaults

my $data_dir = IO::Dir->new( 't/data-bad' );
my @files = sort grep { /^\w/ } $data_dir->read;

for my $f ( sort @files ) {
  my $path = File::Spec->catfile('t','data-bad',$f);
  my $meta = eval { CPAN::Meta->load_file( $path, { fix_errors => 1 }  ) };
  ok( defined $meta, "load_file('$f')" ) or diag $@;
  my $string = _slurp($path);
  my $method =  $path =~ /\.json/ ? "load_json_string" : "load_yaml_string";
  my $meta2 = eval { CPAN::Meta->$method( $string, { fix_errors => 1 } ) };
  ok( defined $meta2, "$method(slurp('$f'))" ) or diag $@;
}

done_testing;