From 059940301fa02d98573e56e8c978ddf8e2031267 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sat, 24 Sep 2016 23:30:06 +0100 Subject: [PATCH] - Addressed github issue #1. --- dist.ini | 4 +- t/0-load.t | 32 ++++++++++++++++ t/00-load.t | 97 ------------------------------------------------ t/01-unit-test.t | 39 +++++++++++++++++++ 4 files changed, 74 insertions(+), 98 deletions(-) create mode 100644 t/0-load.t delete mode 100644 t/00-load.t create mode 100644 t/01-unit-test.t diff --git a/dist.ini b/dist.ini index 3de9dea..460fec6 100644 --- a/dist.ini +++ b/dist.ini @@ -3,4 +3,6 @@ author = Zoffix Znet license = Perl_5 copyright_holder = Zoffix Znet -[@Author::ZOFFIX] \ No newline at end of file +[@Author::ZOFFIX] +[Prereqs / TestRequires] +Test::RequiresInternet = 0 \ No newline at end of file diff --git a/t/0-load.t b/t/0-load.t new file mode 100644 index 0000000..8293042 --- /dev/null +++ b/t/0-load.t @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More tests => 6; +use Test::Deep; + +BEGIN { + use_ok('WWW::Pastebin::Base::Retrieve'); + use_ok('HTML::TokeParser::Simple'); + use_ok('HTML::Entities'); + use_ok('WWW::Pastebin::PastebinCa::Retrieve'); +} + +diag( "Testing WWW::Pastebin::PastebinCa::Retrieve $WWW::Pastebin::PastebinCa::Retrieve::VERSION, Perl $], $^X" ); + +use WWW::Pastebin::PastebinCa::Retrieve; +my $paster = WWW::Pastebin::PastebinCa::Retrieve->new( timeout => 10 ); + +isa_ok($paster, 'WWW::Pastebin::PastebinCa::Retrieve'); +can_ok($paster, qw( + new + retrieve + error + results + id + uri + ua + _parse + _set_error + ) +); diff --git a/t/00-load.t b/t/00-load.t deleted file mode 100644 index eaf9037..0000000 --- a/t/00-load.t +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use Test::More tests => 19; -use Test::Deep; - -my $ID = '931145'; -my $PASTE_DUMP = { - "language" => "Perl Source", - "desc" => "perl stuff", - "content" => "{\r\n\ttrue => sub { 1 },\r\n\tfalse => sub { 0 },\r\n\ttime => scalar localtime(),\r\n}", - "post_date" - => re('Thursday, March 6th, 2008 at \d{1,2}:\d{2}:\d{2}(pm)? [A-Z]{2,4}'), - "name" => "Zoffix" - }; - -BEGIN { - use_ok('WWW::Pastebin::Base::Retrieve'); - use_ok('HTML::TokeParser::Simple'); - use_ok('HTML::Entities'); - use_ok('WWW::Pastebin::PastebinCa::Retrieve'); -} - -diag( "Testing WWW::Pastebin::PastebinCa::Retrieve $WWW::Pastebin::PastebinCa::Retrieve::VERSION, Perl $], $^X" ); - -use WWW::Pastebin::PastebinCa::Retrieve; -my $paster = WWW::Pastebin::PastebinCa::Retrieve->new( timeout => 10 ); -isa_ok($paster, 'WWW::Pastebin::PastebinCa::Retrieve'); -can_ok($paster, qw( - new - retrieve - error - results - id - uri - ua - _parse - _set_error - ) -); - -SKIP: { - my $ret = $paster->retrieve($ID) - or skip "Got error on ->retrieve($ID): " . $paster->error, 16; - - SKIP: { - my $ret2 = $paster->retrieve("http://pastebin.ca/$ID") - or skip "Got error on ->retrieve('http://pastebin.ca/$ID'): " - . $paster->error, 3; - cmp_deeply( - $ret, - $ret2, - 'calls with ID and URI must return the same' - ); - } - - is ( $paster->content, $ret->{content}, 'content() method'); - is ( "$paster", $ret->{content}, 'content() overloads'); - - cmp_deeply( - $ret, - $PASTE_DUMP, - q|dump from Dumper must match ->retrieve()'s response|, - ); - - for ( qw(language content post_date name) ) { - ok( exists $ret->{$_}, "$_ key must exist in the return" ); - } - - cmp_deeply( - $ret, - $paster->results, - '->results() must now return whatever ->retrieve() returned', - ); - - is( - $paster->id, - $ID, - 'paste ID must match the return from ->id()', - ); - - isa_ok( $paster->uri, 'URI::http', '->uri() method' ); - - is( - $paster->uri, - "http://pastebin.ca/$ID", - 'uri() must contain a URI to the paste', - ); - - isa_ok( $paster->ua, 'LWP::UserAgent', '->ua() method' ); -} # SKIP{} - - - - - diff --git a/t/01-unit-test.t b/t/01-unit-test.t new file mode 100644 index 0000000..5884faf --- /dev/null +++ b/t/01-unit-test.t @@ -0,0 +1,39 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::RequiresInternet ('pastebin.ca' => 80); +use Test::Deep; +use WWW::Pastebin::PastebinCa::Retrieve; + +my $ID = '931145'; +my $PASTE_DUMP = { + "language" => "Perl Source", + "desc" => "perl stuff", + "content" => "{\r\n\ttrue => sub { 1 },\r\n\tfalse => sub { 0 },\r\n\ttime => scalar localtime(),\r\n}", + "post_date" => re('Thursday, March 6th, 2008 at \d{1,2}:\d{2}:\d{2}(pm)? [A-Z]{2,4}'), + "name" => "Zoffix" +}; + +my $paster = WWW::Pastebin::PastebinCa::Retrieve->new(timeout => 10); + +my $ret1 = $paster->retrieve($ID); +my $ret2 = $paster->retrieve("http://pastebin.ca/$ID"); +cmp_deeply($ret1, $ret2, 'calls with ID and URI must return the same'); + +is($paster->content, $ret1->{content}, 'content() method'); +is("$paster", $ret1->{content}, 'content() overloads'); +cmp_deeply($ret1, $PASTE_DUMP, q|dump from Dumper must match ->retrieve()'s response|); + +for (qw(language content post_date name)) { + ok(exists $ret1->{$_}, "$_ key must exist in the return"); +} +cmp_deeply($ret1, $paster->results, '->results() must now return whatever ->retrieve() returned'); + +is($paster->id, $ID, 'paste ID must match the return from ->id()'); +isa_ok($paster->uri, 'URI::http', '->uri() method'); +is($paster->uri, "http://pastebin.ca/$ID", 'uri() must contain a URI to the paste'); +isa_ok($paster->ua, 'LWP::UserAgent', '->ua() method'); + +done_testing();