Skip to content

Commit

Permalink
Use AUTHOR_TESTING instead of RELEASE_TESTING
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Jun 10, 2018
1 parent 605236b commit d739885
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 73 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ Revision history for Geo-Coder-US-Census
0.03
Added the run() method
Allow counties in the location. Caveat: they will be ignored
Use AUTHOR_TESTING instead of RELEASE_TESTING

0.02 Tue Oct 24 17:57:14 EDT 2017
Bump the minimum version of Net::SSLeay
Expand Down
74 changes: 39 additions & 35 deletions Makefile.PL
Expand Up @@ -6,15 +6,19 @@ use IO::Socket::INET;

my $online_tests;

if($ENV{RELEASE_TESTING}) {
if($ENV{AUTHOR_TESTING}) {
$online_tests = are_online();
} elsif($ENV{AUTOMATED_TESTING} || $ENV{NO_NETWORK_TESTING} || (!-t STDIN)) {
$online_tests = 0;
} else {
Getopt::Long::GetOptions('online-tests!' => \$online_tests);

if(!defined($online_tests)) {
$online_tests = are_online();
if($ENV{AUTHOR_TESTING}) {
$online_tests = are_online();
} else {
$online_tests = 0;
}
}
}

Expand All @@ -37,43 +41,43 @@ if($online_tests) {
}

WriteMakefile(
NAME => 'Geo::Coder::US::Census',
AUTHOR => q{Nigel Horne <njh@bandsman.co.uk>},
VERSION_FROM => 'lib/Geo/Coder/US/Census.pm',
ABSTRACT_FROM => 'lib/Geo/Coder/US/Census.pm',
((defined($ExtUtils::MakeMaker::VERSION) &&
($ExtUtils::MakeMaker::VERSION >= 6.3002))
? ('LICENSE'=> 'GPL')
: ()),
PL_FILES => {},
TEST_REQUIRES => $test_requires,
PREREQ_PM => {
'Encode' => 0,
'JSON' => 0,
'HTTP::Request' => 0,
'LWP::UserAgent' => 0,
'LWP::Protocol::https' => 0,
'URI' => 0,
'Geo::StreetAddress::US' => 0,
'Net::SSLeay' => 1.81,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Geo-Coder-US-Census-*' },
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
NAME => 'Geo::Coder::US::Census',
AUTHOR => q{Nigel Horne <njh@bandsman.co.uk>},
VERSION_FROM => 'lib/Geo/Coder/US/Census.pm',
ABSTRACT_FROM => 'lib/Geo/Coder/US/Census.pm',
((defined($ExtUtils::MakeMaker::VERSION) &&
($ExtUtils::MakeMaker::VERSION >= 6.3002))
? ('LICENSE'=> 'GPL')
: ()),
PL_FILES => {},
TEST_REQUIRES => $test_requires,
PREREQ_PM => {
'Encode' => 0,
'JSON' => 0,
'HTTP::Request' => 0,
'LWP::UserAgent' => 0,
'LWP::Protocol::https' => 0,
'URI' => 0,
'Geo::StreetAddress::US' => 0,
'Net::SSLeay' => 1.81,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Geo-Coder-US-Census-*' },
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'git://github.com/nigelhorne/Geo-Coder-US-Census.git',
web => 'https://github.com/nigelhorne/Geo-Coder-US-Census',
},
bugtracker => {
web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Geo-Coder-US-Census',
mailto => 'bug-Geo-Coder-US-Census@rt.cpan.org'
}
},
bugtracker => {
web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Geo-Coder-US-Census',
mailto => 'bug-Geo-Coder-US-Census@rt.cpan.org'
}
},
},
},
MIN_PERL_VERSION => '5.6.2' # Probably would work, but never tested on earlier versions than this
MIN_PERL_VERSION => '5.6.2' # Probably would work, but never tested on earlier versions than this
);

sub are_online
Expand Down
26 changes: 13 additions & 13 deletions lib/Geo/Coder/US/Census.pm
Expand Up @@ -14,7 +14,7 @@ use Geo::StreetAddress::US;

=head1 NAME
Geo::Coder::US::Census - Provides a geocoding functionality for the US using http:://geocoding.geo.census.gov
Geo::Coder::US::Census - Provides a Geo-Coding functionality for the US using http:://geocoding.geo.census.gov
=head1 VERSION
Expand All @@ -28,10 +28,10 @@ our $VERSION = '0.02';
use Geo::Coder::US::Census;
my $geocoder = Geo::Coder::US::Census->new();
my $location = $geocoder->geocode(location => '4600 Silver Hill Rd., Suitland, MD');
my $geo_coder = Geo::Coder::US::Census->new();
my $location = $geo_coder->geocode(location => '4600 Silver Hill Rd., Suitland, MD');
# Sometimes the server gives a 500 error on this
$location = $geocoder->geocode(location => '4600 Silver Hill Rd., Suitland, MD, USA');
$location = $geo_coder->geocode(location => '4600 Silver Hill Rd., Suitland, MD, USA');
=head1 DESCRIPTION
Expand All @@ -41,10 +41,10 @@ Geo::Coder::US::Census provides an interface to geocoding.geo.census.gov. Geo::
=head2 new
$geocoder = Geo::Coder::US::Census->new();
$geo_coder = Geo::Coder::US::Census->new();
my $ua = LWP::UserAgent->new();
$ua->env_proxy(1);
$geocoder = Geo::Coder::US::Census->new(ua => $ua);
$geo_coder = Geo::Coder::US::Census->new(ua => $ua);
=cut

Expand All @@ -59,8 +59,8 @@ sub new {

=head2 geocode
$location = $geocoder->geocode(location => $location);
# @location = $geocoder->geocode(location => $location);
$location = $geo_coder->geocode(location => $location);
# @location = $geo_coder->geocode(location => $location);
print 'Latitude: ', $location->{'latt'}, "\n";
print 'Longitude: ', $location->{'longt'}, "\n";
Expand All @@ -78,7 +78,7 @@ sub geocode {
}

my $location = $param{location}
or Carp::croak("Usage: geocode(location => \$location)");
or Carp::croak('Usage: geocode(location => $location)');

if (Encode::is_utf8($location)) {
$location = Encode::encode_utf8($location);
Expand All @@ -90,7 +90,7 @@ sub geocode {

# Remove county from the string, if that's included
# Assumes not more than one town in a state with the same name
# in different counties - but the census geocoding doesn't support that
# in different counties - but the census Geo-Coding doesn't support that
# anyway
if($location =~ /^(\d+\s+[\w\s]+),\s*([\w\s]+),\s*[\w\s]+,\s*([A-Za-z]+)$/) {
$location = "$1, $2, $3";
Expand Down Expand Up @@ -137,11 +137,11 @@ Accessor method to get and set UserAgent object used internally. You
can call I<env_proxy> for example, to get the proxy information from
environment variables:
$geocoder->ua()->env_proxy(1);
$geo_coder->ua()->env_proxy(1);
You can also set your own User-Agent object:
$geocoder->ua(LWP::UserAgent::Throttled->new());
$geo_coder->ua(LWP::UserAgent::Throttled->new());
=cut

Expand All @@ -155,7 +155,7 @@ sub ua {

=head2 reverse_geocode
# $location = $geocoder->reverse_geocode(latlng => '37.778907,-122.39732');
# $location = $geo_coder->reverse_geocode(latlng => '37.778907,-122.39732');
# Similar to geocode except it expects a latitude/longitude parameter.
Expand Down
10 changes: 9 additions & 1 deletion t/bin.t
Expand Up @@ -9,7 +9,15 @@ script_compiles('bin/census');

BIN: {
SKIP: {
skip 'Test requires Internet access', 5 unless(-e 't/online.enabled');
if(!-e 't/online.enabled') {
if(!$ENV{RELEASE_TESTING}) {
diag('Author tests not required for installation');
skip('Author tests not required for installation', 5);
} else {
diag('Test requires Internet access');
skip('Test requires Internet access', 5);
}
}

script_runs(['bin/census']);

Expand Down
2 changes: 1 addition & 1 deletion t/changes.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use Test::Most;

if(not $ENV{RELEASE_TESTING}) {
if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

Expand Down
2 changes: 1 addition & 1 deletion t/critic.t
Expand Up @@ -6,7 +6,7 @@ use File::Spec;
use Test::Most;
use English qw(-no_match_vars);

unless($ENV{RELEASE_TESTING}) {
unless($ENV{AUTHOR_TESTING}) {
plan( skip_all => "Author tests not required for installation" );
}

Expand Down
2 changes: 1 addition & 1 deletion t/cv.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use Test::Most;

if(not $ENV{RELEASE_TESTING}) {
if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

Expand Down
2 changes: 1 addition & 1 deletion t/dist.t
Expand Up @@ -4,7 +4,7 @@ use warnings;
use Test::Most;

BEGIN {
if($ENV{RELEASE_TESTING}) {
if($ENV{AUTHOR_TESTING}) {
eval {
require Test::Distribution;
};
Expand Down
2 changes: 1 addition & 1 deletion t/gv.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use Test::Most;

if(not $ENV{RELEASE_TESTING}) {
if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

Expand Down
2 changes: 1 addition & 1 deletion t/kwalitee.t
Expand Up @@ -3,7 +3,7 @@ use warnings;

use Test::Most;

unless($ENV{RELEASE_TESTING}) {
unless($ENV{AUTHOR_TESTING}) {
plan( skip_all => "Author tests not required for installation" );
}

Expand Down
2 changes: 1 addition & 1 deletion t/manifest.t
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;
use Test::Most;

unless ( $ENV{RELEASE_TESTING} ) {
unless ( $ENV{AUTHOR_TESTING} ) {
plan( skip_all => "Author tests not required for installation" );
}

Expand Down
2 changes: 1 addition & 1 deletion t/metrics.t
Expand Up @@ -5,7 +5,7 @@ use warnings;
use File::Spec;
use Test::Most;

if(not $ENV{RELEASE_TESTING}) {
if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

Expand Down
2 changes: 1 addition & 1 deletion t/namespaces.t
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;
use Test::Most;

if($ENV{RELEASE_TESTING}) {
if($ENV{AUTHOR_TESTING}) {
eval {
require Test::CleanNamespaces;
};
Expand Down
2 changes: 1 addition & 1 deletion t/noplan.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use Test::Most;

unless($ENV{RELEASE_TESTING}) {
unless($ENV{AUTHOR_TESTING}) {
plan( skip_all => "Author tests not required for installation" );
}

Expand Down
2 changes: 1 addition & 1 deletion t/pod.t
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;
use Test::Most;

if(not $ENV{RELEASE_TESTING}) {
if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

Expand Down
2 changes: 1 addition & 1 deletion t/prereq.t
Expand Up @@ -4,7 +4,7 @@ use strict;

use Test::Most;

unless($ENV{RELEASE_TESTING}) {
unless($ENV{AUTHOR_TESTING}) {
plan( skip_all => "Author tests not required for installation" );
}

Expand Down
2 changes: 1 addition & 1 deletion t/snippets.t
Expand Up @@ -5,7 +5,7 @@ use warnings;
use File::Spec;
use Test::Most;

if(not $ENV{RELEASE_TESTING}) {
if(not $ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

Expand Down
2 changes: 1 addition & 1 deletion t/spelling.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use Test::Most;

unless($ENV{RELEASE_TESTING}) {
unless($ENV{AUTHOR_TESTING}) {
plan( skip_all => "Author tests not required for installation" );
}

Expand Down
2 changes: 1 addition & 1 deletion t/strict.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use Test::Most;

unless($ENV{RELEASE_TESTING}) {
unless($ENV{AUTHOR_TESTING}) {
plan( skip_all => "Author tests not required for installation" );
}

Expand Down
4 changes: 2 additions & 2 deletions t/unused.t
Expand Up @@ -4,11 +4,11 @@ use strict;
use warnings;
use Test::Most;

unless($ENV{RELEASE_TESTING}) {
unless($ENV{AUTHOR_TESTING}) {
plan(skip_all => "Author tests not required for installation");
}

eval 'use warnings::unused -global';
eval 'use warnings::unused';
if($@ || ($warnings::unused::VERSION < 0.04)) {
plan(skip_all => 'warnings::unused >= 0.04 needed for testing');
} else {
Expand Down
22 changes: 17 additions & 5 deletions t/us.t
Expand Up @@ -12,7 +12,15 @@ BEGIN {

US: {
SKIP: {
skip 'Test requires Internet access', 12 unless(-e 't/online.enabled');
if(!-e 't/online.enabled') {
if(!$ENV{RELEASE_TESTING}) {
diag('Author tests not required for installation');
skip('Author tests not required for installation', 12);
} else {
diag('Test requires Internet access');
skip('Test requires Internet access', 12);
}
}

require Test::LWP::UserAgent;
Test::LWP::UserAgent->import();
Expand All @@ -27,10 +35,14 @@ US: {
delta_ok($location->{result}{addressMatches}[0]->{coordinates}{y}, 38.90); # Lat
delta_ok($location->{result}{addressMatches}[0]->{coordinates}{x}, -77.04); # Long

# Test counties
$location = $geocoder->geocode('1363 Kelly Road, Coal, Owen, Indiana, USA');
delta_ok($location->{result}{addressMatches}[0]->{coordinates}{y}, 39.27); # Lat
delta_ok($location->{result}{addressMatches}[0]->{coordinates}{x}, -87.03); # Long
TODO: {
# Test counties
local $TODO = "geocoding.geo.census.gov doesn't support counties";

$location = $geocoder->geocode('1363 Kelly Road, Coal City, Owen, Indiana, USA');
delta_ok($location->{result}{addressMatches}[0]->{coordinates}{y}, 39.27); # Lat
delta_ok($location->{result}{addressMatches}[0]->{coordinates}{x}, -87.03); # Long
}

$location = $geocoder->geocode(location => '6502 SW. 102nd Avenue, Bushnell, Florida, USA');
delta_ok($location->{result}{addressMatches}[0]->{coordinates}{y}, 28.61); # Lat
Expand Down

0 comments on commit d739885

Please sign in to comment.