Debian Codegraph @

t/get_data.t

raw ◀ ▶
1 Debian patch touch this file
1 use Test::More;
2
3 use File::Basename;
4
5 my $class = 'Business::ISBN::Data';
6 use_ok $class;
7
8 my @subs = qw(
9 _get_data
10 );
11
12 can_ok $class, @subs;
13
14 my $KEY = 'ISBN_RANGE_MESSAGE';
15
16 # https://github.com/briandfoy/business-isbn-data/issues/236
17 subtest 'ISBN_RANGE_MESSAGE env var does not exist before or after' => sub {
18 delete local $ENV{$KEY};
19 ok ! exists $ENV{$KEY}, "env var key <$KEY> does not exist (before)";
20 my %data = Business::ISBN::Data->_get_data();
21 ok ! exists $ENV{$KEY}, "env var key <$KEY> does not exist (after)";
22 };
23
24 subtest 'ISBN_RANGE_MESSAGE file exists' => sub {
25 my $file = 'lib/Business/ISBN/RangeMessage.xml';
26 ok -e $file, "$file exists";
27 local $ENV{$KEY} = $file;
28
29 my %data = Business::ISBN::Data->_get_data();
•30 SKIP: {
31 skip "No RangeMessage.xml in installed package", 1 if $ENV{AUTOPKGTEST_TMP};
32 }
33 ok exists $data{'_source'}, '_source exists in hash';
34 is $data{'_source'}, $file, '_source is the file';
35 };
36
37 subtest 'ISBN_RANGE_MESSAGE file does not exist' => sub {
•38 plan skip_all => "Debian doesn't include a RangeMessage.xml that could be tested here" if $ENV{AUTOPKGTEST_TMP};
39 my $file = 'lib/Business/ISBN/RangeMessage.yaml';
40 ok ! -e $file, "$file does not exist";
41 local $ENV{$KEY} = $file;
42
43 my $warning;
44 local $SIG{'__WARN__'} = sub { $warning .= $_[0] };
45 my %data = Business::ISBN::Data->_get_data();
46 like $warning, qr/does not exist/, 'warning message notes the file is not there';
47 ok exists $data{'_source'}, '_source exists in hash';
48 is basename($data{'_source'}), 'RangeMessage.xml', '_source is distributed file';
49 };
50
51 done_testing();