Debian Codegraph @

cpan/CPAN-Meta-YAML/t/21_yamlpm_compat.t

raw
1 use strict;
2 use warnings;
3 use lib 't/lib/';
4 use Test::More 0.88;
5 use TestBridge;
6 use File::Spec::Functions 'catfile';
7 use File::Temp 0.19; # newdir
8
9 #--------------------------------------------------------------------------#
10 # This file test that the YAML.pm compatible Dump/Load/DumpFile/LoadFile
11 # work as documented
12 #--------------------------------------------------------------------------#
13
14 use CPAN::Meta::YAML;
15
16 {
17 my $scalar = 'this is a string';
18 my $arrayref = [ 1 .. 5 ];
19 my $hashref = { alpha => 'beta', gamma => 'delta' };
20
21 my $yamldump = CPAN::Meta::YAML::Dump( $scalar, $arrayref, $hashref );
22 my @yamldocsloaded = CPAN::Meta::YAML::Load($yamldump);
23 cmp_deeply(
24 [ @yamldocsloaded ],
25 [ $scalar, $arrayref, $hashref ],
26 "Functional interface: Dump to Load roundtrip works as expected"
27 );
28 }
29
30 {
31 my $scalar = 'this is a string';
32 my $arrayref = [ 1 .. 5 ];
33 my $hashref = { alpha => 'beta', gamma => 'delta' };
34
35 my $tempdir = File::Temp->newdir("YTXXXXXX", TMPDIR => 1 );
36 my $filename = catfile($tempdir, 'compat');
37
38 my $rv = CPAN::Meta::YAML::DumpFile(
39 $filename, $scalar, $arrayref, $hashref);
40 ok($rv, "DumpFile returned true value");
41
42 my @yamldocsloaded = CPAN::Meta::YAML::LoadFile($filename);
43 cmp_deeply(
44 [ @yamldocsloaded ],
45 [ $scalar, $arrayref, $hashref ],
46 "Functional interface: DumpFile to LoadFile roundtrip works as expected"
47 );
48 }
49
50 {
51 my $str = "This is not real YAML";
52 my @yamldocsloaded;
53 eval { @yamldocsloaded = CPAN::Meta::YAML::Load("$str\n"); };
54 error_like(
55 qr/CPAN::Meta::YAML failed to classify line '$str'/,
56 "Correctly failed to load non-YAML string"
57 );
58 }
59
60 done_testing;