Skip to content

Commit

Permalink
Get to 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
briandfoy committed Feb 29, 2024
1 parent b5675c3 commit b778d0b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions MANIFEST
Expand Up @@ -10,9 +10,12 @@ Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
README.pod
t/business-isbn.t
t/check_data_structure.t
t/default_data.t
t/get_data.t
t/load.t
t/parse.t
t/pod.t
t/pod_coverage.t
t/test_manifest
Expand Down
24 changes: 24 additions & 0 deletions t/business-isbn.t
@@ -0,0 +1,24 @@
use Test::More;

use File::Basename;

my $class = 'Business::ISBN::Data';
use_ok $class;

my @subs = qw(
isbn_data_source
);

can_ok 'Business::ISBN', @subs;

subtest 'source' => sub {
ok exists $Business::ISBN::country_data{'_source'}, 'country_data has _source';
like $Business::ISBN::country_data{'_source'}, qr/RangeMessage\.xml/, 'source is RangeMessage';
is Business::ISBN::isbn_data_source(), $Business::ISBN::country_data{'_source'}, 'isbn_data_source returns _source';

delete local $Business::ISBN::country_data{'_source'};
unlike $Business::ISBN::country_data{'_source'}, qr/RangeMessage\.xml/, 'source is not RangeMessage';
is basename( Business::ISBN::isbn_data_source() ), 'Data.pm', 'source is module';
};

done_testing();
36 changes: 36 additions & 0 deletions t/get_data.t
@@ -0,0 +1,36 @@
use Test::More;

use File::Basename;

my $class = 'Business::ISBN::Data';
use_ok $class;

my @subs = qw(
_get_data
);

can_ok $class, @subs;

subtest 'ISBN_RANGE_MESSAGE exists' => sub {
my $file = 'lib/Business/ISBN/RangeMessage.xml';
ok -e $file, "$file exists";
local $ENV{ISBN_RANGE_MESSAGE} = $file;

my %data = Business::ISBN::Data->_get_data();
ok exists $data{'_source'}, '_source exists in hash';
is $data{'_source'}, $file, '_source is the file';
};

subtest 'ISBN_RANGE_MESSAGE does not exist' => sub {
my $file = 'lib/Business/ISBN/RangeMessage.yaml';
ok ! -e $file, "$file does not exist";
local $ENV{ISBN_RANGE_MESSAGE} = $file;

diag( "This will be a warning here" );
my %data = Business::ISBN::Data->_get_data();
diag( "There should be no more warnings" );
ok exists $data{'_source'}, '_source exists in hash';
like $data{'_source'}, qr|lib/Business/ISBN/RangeMessage.xml\z|, '_source is distributed file';
};

done_testing();
24 changes: 24 additions & 0 deletions t/parse.t
@@ -0,0 +1,24 @@
use Test::More;

use File::Basename;

my $class = 'Business::ISBN::Data';
use_ok $class;

my @subs = qw(
_parse_range_message
);

can_ok $class, @subs;

subtest 'file does not exist' => sub {
my $file = 'lib/Business/ISBN/RangeMessage.yamml';
ok ! -e $file, "$file does not exist";

diag( "This will be a warning here" );
my $result = Business::ISBN::Data::_parse_range_message( $file );
diag( "There should be no more warnings" );
ok ! defined $result, "_parse_range_message returns undef if file does not exist";
};

done_testing();

0 comments on commit b778d0b

Please sign in to comment.