From cb47f569266875d6464a4078eaa3f41097982c1a Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Tue, 15 Oct 2024 07:41:26 -0400 Subject: [PATCH] Start to use Test::DescribeMe --- t/noopentickets.t | 105 ++++++++++++++++++++++------------------------ t/pod-snippets.t | 14 +++---- 2 files changed, 55 insertions(+), 64 deletions(-) diff --git a/t/noopentickets.t b/t/noopentickets.t index 163d8a2..aefcf93 100644 --- a/t/noopentickets.t +++ b/t/noopentickets.t @@ -2,34 +2,32 @@ use strict; use warnings; + +use Test::DescribeMe qw(author); use Test::Most tests => 4; + use constant URL => 'https://api.github.com/repos/nigelhorne/CGI-Info/issues'; use constant SITE =>'api.github.com'; RT: { # RT system, deprecated SKIP: { - if($ENV{AUTHOR_TESTING}) { - eval 'use WWW::RT::CPAN'; # FIXME: use a REST client - if($@) { - diag('WWW::RT::CPAN required to check for open tickets'); - skip('WWW::RT::CPAN required to check for open tickets', 3); - } elsif(my @rc = @{WWW::RT::CPAN::list_dist_active_tickets(dist => 'CGI-Info')}) { - cmp_ok($rc[0], '==', 200); - cmp_ok($rc[1], 'eq', 'OK'); - my @tickets = $rc[2] ? @{$rc[2]} : (); + eval 'use WWW::RT::CPAN'; # FIXME: use a REST client + if($@) { + diag('WWW::RT::CPAN required to check for open tickets'); + skip('WWW::RT::CPAN required to check for open tickets', 3); + } elsif(my @rc = @{WWW::RT::CPAN::list_dist_active_tickets(dist => 'CGI-Info')}) { + cmp_ok($rc[0], '==', 200); + cmp_ok($rc[1], 'eq', 'OK'); + my @tickets = $rc[2] ? @{$rc[2]} : (); - foreach my $ticket(@tickets) { - diag($ticket->{id}, ': ', $ticket->{title}, ', broken since ', $ticket->{'broken_in'}[0]); - } - ok(scalar(@tickets) == 0); - } else { - diag("Can't connect to rt.cpan.org"); - skip("Can't connect to rt.cpan.org", 3); + foreach my $ticket(@tickets) { + diag($ticket->{id}, ': ', $ticket->{title}, ', broken since ', $ticket->{'broken_in'}[0]); } + ok(scalar(@tickets) == 0); } else { - diag('Author tests not required for installation'); - skip('Author tests not required for installation', 3); + diag("Can't connect to rt.cpan.org"); + skip("Can't connect to rt.cpan.org", 3); } } } @@ -37,53 +35,48 @@ RT: { GITHUB: { # https://docs.github.com/en/rest/reference/issues#list-repository-issues SKIP: { - if($ENV{'AUTHOR_TESTING'}) { - eval 'use JSON::MaybeXS'; + eval 'use JSON::MaybeXS'; + if($@) { + diag('JSON::MaybeXS required to check for open tickets'); + skip('JSON::MaybeXS required to check for open tickets', 1); + } else { + eval 'use IO::Socket::INET'; if($@) { - diag('JSON::MaybeXS required to check for open tickets'); - skip('JSON::MaybeXS required to check for open tickets', 1); + diag('IO::Socket::INET required to check for open tickets'); + skip('IO::Socket::INET required to check for open tickets', 1); } else { - eval 'use IO::Socket::INET'; - if($@) { - diag('IO::Socket::INET required to check for open tickets'); - skip('IO::Socket::INET required to check for open tickets', 1); - } else { - my $s = IO::Socket::INET->new( - PeerAddr => SITE, - PeerPort => 'http(80)', - Timeout => 5 - ); - if($s) { - eval 'use LWP::Simple'; + my $s = IO::Socket::INET->new( + PeerAddr => SITE, + PeerPort => 'http(80)', + Timeout => 5 + ); + if($s) { + eval 'use LWP::Simple'; - if($@) { - diag('LWP::Simple required to check for open tickets'); - skip('LWP::Simple required to check for open tickets', 1); - } elsif(my $data = LWP::Simple::get(URL)) { - my $json = JSON::MaybeXS->new()->utf8(); - my @issues = @{$json->decode($data)}; - # diag(Data::Dumper->new([\@issues])->Dump()); - if($ENV{'TEST_VERBOSE'}) { - foreach my $issue(@issues) { - # diag($issues[0]->{'user'}->{'login'}); - diag($issue->{'html_url'}); - } + if($@) { + diag('LWP::Simple required to check for open tickets'); + skip('LWP::Simple required to check for open tickets', 1); + } elsif(my $data = LWP::Simple::get(URL)) { + my $json = JSON::MaybeXS->new()->utf8(); + my @issues = @{$json->decode($data)}; + # diag(Data::Dumper->new([\@issues])->Dump()); + if($ENV{'TEST_VERBOSE'}) { + foreach my $issue(@issues) { + # diag($issues[0]->{'user'}->{'login'}); + diag($issue->{'html_url'}); } - cmp_ok(scalar(@issues), '==', 0, 'There are no opentickets'); - } else { - diag(URL, ': failed to get data - ignoring'); - # fail('Failed to get data'); - skip(URL . ': failed to get data - ignoring', 1); } + cmp_ok(scalar(@issues), '==', 0, 'There are no opentickets'); } else { - diag("Can't connect to ", SITE, ": $IO::Socket::errstr"); - skip("Can't connect to " . SITE . ": $IO::Socket::errstr", 1); + diag(URL, ': failed to get data - ignoring'); + # fail('Failed to get data'); + skip(URL . ': failed to get data - ignoring', 1); } + } else { + diag("Can't connect to ", SITE, ": $IO::Socket::errstr"); + skip("Can't connect to " . SITE . ": $IO::Socket::errstr", 1); } } - } else { - diag('Author tests not required for installation'); - skip('Author tests not required for installation', 1); } } } diff --git a/t/pod-snippets.t b/t/pod-snippets.t index 0f7e03c..3f7aa9d 100644 --- a/t/pod-snippets.t +++ b/t/pod-snippets.t @@ -2,15 +2,13 @@ use strict; use warnings; + +use Test::DescribeMe qw(author); use Test::Most; use Test::Needs 'Test::Pod::Snippets'; -if($ENV{'AUTHOR_TESTING'}) { - my @modules = qw/ CGI::Info /; - Test::Pod::Snippets->import(); - Test::Pod::Snippets->new()->runtest(module => $_, testgroup => 1) for @modules; +my @modules = qw/ CGI::Info /; +Test::Pod::Snippets->import(); +Test::Pod::Snippets->new()->runtest(module => $_, testgroup => 1) for @modules; - done_testing(); -} else { - plan(skip_all => 'Author tests not required for installation'); -} +done_testing();