This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Parse-CPAN-Meta to CPAN version 1.4405
[perl5.git] / cpan / Parse-CPAN-Meta / t / 02_api.t
CommitLineData
34d5bd5d
DG
1#!/usr/bin/perl
2
f87dacdb
CBW
3delete $ENV{PERL_YAML_BACKEND};
4delete $ENV{PERL_JSON_BACKEND};
5
34d5bd5d
DG
6# Testing of a known-bad file from an editor
7
8BEGIN {
9 if( $ENV{PERL_CORE} ) {
10 chdir 't';
11 @INC = ('../lib', 'lib');
12 }
13 else {
14 unshift @INC, 't/lib/';
15 }
16}
17
18use strict;
19BEGIN {
20 $| = 1;
21 $^W = 1;
22}
23
24use File::Spec::Functions ':ALL';
25use Parse::CPAN::Meta;
26use Parse::CPAN::Meta::Test;
27# use Test::More skip_all => 'Temporarily ignoring failing test';
28use Test::More 'no_plan';
29
30#####################################################################
31# Testing that Perl::Smith config files work
32
33my $want = {
34 "abstract" => "a set of version requirements for a CPAN dist",
35 "author" => [ 'Ricardo Signes <rjbs@cpan.org>' ],
36 "build_requires" => {
37 "Test::More" => "0.88"
38 },
39 "configure_requires" => {
40 "ExtUtils::MakeMaker" => "6.31"
41 },
42 "generated_by" => "Dist::Zilla version 2.100991",
43 "license" => "perl",
44 "meta-spec" => {
45 "url" => "http://module-build.sourceforge.net/META-spec-v1.4.html",
46 "version" => 1.4
47 },
48 "name" => "Version-Requirements",
49 "recommends" => {},
50 "requires" => {
51 "Carp" => "0",
52 "Scalar::Util" => "0",
53 "version" => "0.77"
54 },
55 "resources" => {
56 "repository" => "git://git.codesimply.com/Version-Requirements.git"
57 },
58 "version" => "0.101010",
59};
60
342e4710
CBW
61my $meta_json = catfile( test_data_directory(), 'META-VR.json' );
62my $meta_yaml = catfile( test_data_directory(), 'META-VR.yml' );
34d5bd5d
DG
63
64### YAML tests
65{
66 local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
67
68 is(Parse::CPAN::Meta->yaml_backend(), 'CPAN::Meta::YAML', 'yaml_backend()');
69 my $from_yaml = Parse::CPAN::Meta->load_file( $meta_yaml );
70 is_deeply($from_yaml, $want, "load from YAML file results in expected data");
71}
72
73{
74 local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
75
342e4710 76 my $yaml = load_ok( 'META-VR.yml', $meta_yaml, 100);
34d5bd5d
DG
77 my $from_yaml = Parse::CPAN::Meta->load_yaml_string( $yaml );
78 is_deeply($from_yaml, $want, "load from YAML str results in expected data");
79}
80
81SKIP: {
82 skip "YAML module not installed", 2
83 unless eval "require YAML; 1";
84 local $ENV{PERL_YAML_BACKEND} = 'YAML';
85
86 is(Parse::CPAN::Meta->yaml_backend(), 'YAML', 'yaml_backend()');
342e4710 87 my $yaml = load_ok( 'META-VR.yml', $meta_yaml, 100);
34d5bd5d
DG
88 my $from_yaml = Parse::CPAN::Meta->load_yaml_string( $yaml );
89 is_deeply($from_yaml, $want, "load_yaml_string using PERL_YAML_BACKEND");
90}
91
92### JSON tests
93{
94 # JSON tests with JSON::PP
95 local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
96
97 is(Parse::CPAN::Meta->json_backend(), 'JSON::PP', 'json_backend()');
98 my $from_json = Parse::CPAN::Meta->load_file( $meta_json );
99 is_deeply($from_json, $want, "load from JSON file results in expected data");
100}
101
102{
103 # JSON tests with JSON::PP
104 local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
105
342e4710 106 my $json = load_ok( 'META-VR.json', $meta_json, 100);
34d5bd5d
DG
107 my $from_json = Parse::CPAN::Meta->load_json_string( $json );
108 is_deeply($from_json, $want, "load from JSON str results in expected data");
109}
110
111{
112 # JSON tests with JSON::PP, take 2
113 local $ENV{PERL_JSON_BACKEND} = 0; # request JSON::PP
114
342e4710 115 my $json = load_ok( 'META-VR.json', $meta_json, 100);
34d5bd5d
DG
116 my $from_json = Parse::CPAN::Meta->load_json_string( $json );
117 is_deeply($from_json, $want, "load_json_string with PERL_JSON_BACKEND = 0");
118}
119
120{
121 # JSON tests with JSON::PP, take 3
122 local $ENV{PERL_JSON_BACKEND} = 'JSON::PP'; # request JSON::PP
123
342e4710 124 my $json = load_ok( 'META-VR.json', $meta_json, 100);
34d5bd5d
DG
125 my $from_json = Parse::CPAN::Meta->load_json_string( $json );
126 is_deeply($from_json, $want, "load_json_string with PERL_JSON_BACKEND = 'JSON::PP'");
127}
128
129SKIP: {
130 skip "JSON module version 2.5 not installed", 2
131 unless eval "require JSON; JSON->VERSION(2.5); 1";
132 local $ENV{PERL_JSON_BACKEND} = 1;
133
134 is(Parse::CPAN::Meta->json_backend(), 'JSON', 'json_backend()');
342e4710 135 my $json = load_ok( 'META-VR.json', $meta_json, 100);
34d5bd5d
DG
136 my $from_json = Parse::CPAN::Meta->load_json_string( $json );
137 is_deeply($from_json, $want, "load_json_string with PERL_JSON_BACKEND = 1");
138}
139