Skip to content

Commit

Permalink
improve N:P:C coverage; make it warn about exports, which have been d…
Browse files Browse the repository at this point in the history
…eprecated since forever
  • Loading branch information
DrHyde committed Oct 11, 2016
1 parent a8bb478 commit 0f3474f
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(see https://github.com/DrHyde/perl-modules-Number-Phone/issues/60);
Minor coverage improvements by getting rid of some redundant
code paths;
Number::Phone::Country will now warn that exporting is deprecated;

2016-09-07 3.2001 Data updates

Expand Down
2 changes: 1 addition & 1 deletion build-data.nanp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use XML::XPath;
use Data::Dumper;local $Data::Dumper::Indent = 1;

use lib 'lib';
use Number::Phone::Country;
use Number::Phone::Country qw(noexport);

$| = 1;

Expand Down
4 changes: 3 additions & 1 deletion lib/Number/Phone/Country.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Number::Phone::Country::Data;

# *_codes are global so we can mock in some tests
use vars qw($VERSION %idd_codes %prefix_codes);
$VERSION = 1.9;
$VERSION = 1.91;
my $use_uk = 0;

sub import {
Expand All @@ -18,6 +18,7 @@ sub import {
if($export) {
my $callpkg = caller(1);
no strict 'refs';
warn("Exporting from Number::Phone::Country is deprecated at ".join(' line ', (caller())[1,2])."\n");
*{"$callpkg\::phone2country"} = \&{__PACKAGE__."\::phone2country"};
}
}
Expand Down Expand Up @@ -80,6 +81,7 @@ our %NANP_areas = (

# private sub, returns list of NANP areas for the given ISO country code
sub _NANP_area_codes {
# uncoverable subroutine - only used in build scripts
return split('\|', $NANP_areas{shift()});
}

Expand Down
2 changes: 1 addition & 1 deletion t/40-no-stubs.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Test::More;

END { done_testing(); }

use Number::Phone::Country;
use Number::Phone::Country qw(noexport);

is(Number::Phone->new("+442087712924")->country_code(), 44, "known countries return objects");

Expand Down
2 changes: 1 addition & 1 deletion t/42-libphonenumber.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ isa_ok($CLASS->new('UK', '020 8771 2924'), 'Number::Phone::StubCountry::GB', "N:
isa_ok($CLASS->new('GB', '20 8771 2924'), 'Number::Phone::StubCountry::GB', "N::P::Lib->new('GB', 'NNNNN')");

# switch N::P::C into "UK mode", make sure that N::P::Lib still DTRT
eval "use Number::Phone::Country qw(uk)";
eval "use Number::Phone::Country qw(uk noexport)";
isa_ok($CLASS->new('GB', '020 8771 2924'), 'Number::Phone::StubCountry::GB', "N::P::Lib->new('GB', '0NNNNN') with N::P::C in 'uk mode'");
isa_ok($CLASS->new('UK', '020 8771 2924'), 'Number::Phone::StubCountry::GB', "N::P::Lib->new('UK', '0NNNNN') with N::P::C in 'uk mode'");
9 changes: 8 additions & 1 deletion t/50_number-phone-country.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ END { done_testing }
use lib 't/inc';
use fatalwarnings;

use Number::Phone::Country;
use Number::Phone::Country qw(noexport);

sub phone2country { goto &Number::Phone::Country::phone2country }

# return nothing for nonsense country codes
ok(!defined(Number::Phone::Country::country_code("XX")), "N::P::C::country_code returns undef for a nonsense country code");
ok(!defined(Number::Phone::Country::idd_code("XX")), "N::P::C::idd_code returns undef for a nonsense country code");
ok(!defined(Number::Phone::Country::ndd_code("XX")), "N::P::C::ndd_code returns undef for a nonsense country code");

# NANP formats
is(phone2country( "219-555-0199"), "US", "NANP: xxx-xxx-xxxx format");
Expand Down
16 changes: 0 additions & 16 deletions t/51_number-phone-country-noexport.t

This file was deleted.

18 changes: 18 additions & 0 deletions t/51_number-phone-country-warns-about-exports.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/perl -w

use strict;

use Test::More;

END { done_testing(); }

BEGIN { $SIG{__WARN__} = sub {
is(
shift(),
"Exporting from Number::Phone::Country is deprecated at t/51_number-phone-country-warns-about-exports.t line 17\n",
"Number::Phone::Country warns when asked to export"
);
} }

use Number::Phone::Country;

2 changes: 1 addition & 1 deletion t/52_number-phone-country-uk.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ use Test::More;

END { done_testing(); }

use Number::Phone::Country qw(uk);
use Number::Phone::Country qw(noexport uk);

is(Number::Phone::Country::phone2country('+44 20 12345678'), 'UK', "can return UK instead of GB");
2 changes: 1 addition & 1 deletion t/53_number-phone-country-idd.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Test::More;

END { done_testing(); }

use Number::Phone::Country;
use Number::Phone::Country qw(noexport);

country_and_idd('+44 20 12345678', 'GB', '44', "phone2country_and_idd works for GB");
country_and_idd('212 333 3333', 'US', '1', "phone2country_and_idd works for US");
Expand Down
2 changes: 1 addition & 1 deletion t/54_number-phone-country-prefix.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Test::More;

END { done_testing(); }

use_ok('Number::Phone::Country') or exit 1;
use Number::Phone::Country qw(noexport);

while (<DATA>) {
chomp;
Expand Down
2 changes: 1 addition & 1 deletion t/55_number-phone-country-multiple.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Test::More;

END { done_testing(); }

use Number::Phone::Country;
use Number::Phone::Country qw(noexport);

is(Number::Phone::Country::phone2country('+47 1234 5678'), 'NO', "first of three");
is(Number::Phone::Country::phone2country('+44 20 12345678'), 'GB', "uk not set accidentally");
2 changes: 1 addition & 1 deletion t/902_bugfix-rt61177.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Test::More;
END { done_testing(); }

use Number::Phone;
use Number::Phone::Country;
use Number::Phone::Country qw(noexport);

is(Number::Phone->new("442087712924")->country_code(), 44, "known countries return objects");
is(Number::Phone->new("+442087712924")->country_code(), 44, "known countries with a + return objects");
Expand Down

0 comments on commit 0f3474f

Please sign in to comment.