| 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 |
ok exists $data{'_source'}, '_source exists in hash'; |
| 31 |
is $data{'_source'}, $file, '_source is the file'; |
| 32 |
}; |
| 33 |
|
| 34 |
subtest 'ISBN_RANGE_MESSAGE file does not exist' => sub { |
| 35 |
my $file = 'lib/Business/ISBN/RangeMessage.yaml'; |
| 36 |
ok ! -e $file, "$file does not exist"; |
| 37 |
local $ENV{$KEY} = $file; |
| 38 |
|
| 39 |
my $warning; |
| 40 |
local $SIG{'__WARN__'} = sub { $warning .= $_[0] }; |
| 41 |
my %data = Business::ISBN::Data->_get_data(); |
| 42 |
like $warning, qr/does not exist/, 'warning message notes the file is not there'; |
| 43 |
ok exists $data{'_source'}, '_source exists in hash'; |
| 44 |
is basename($data{'_source'}), 'RangeMessage.xml', '_source is distributed file'; |
| 45 |
}; |
| 46 |
|
| 47 |
done_testing(); |