From: Marius Gavrilescu Date: Tue, 30 Dec 2014 21:11:38 +0000 (+0200) Subject: Add tests for Zeal::Feed X-Git-Tag: 0.000_002~5 X-Git-Url: http://git.ieval.ro/?p=zeal.git;a=commitdiff_plain;h=adb8c7927a60a9023c48290a606b749d26c48515 Add tests for Zeal::Feed --- diff --git a/MANIFEST b/MANIFEST index 4ca629c..a7300bd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -6,6 +6,9 @@ lib/Zeal/Feed.pm Makefile.PL MANIFEST README +t/a.tar +t/a.tar.bz2 +t/a.tar.gz t/ds/a.docset/Contents/Info.plist t/ds/a.docset/Contents/Resources/docSet.dsidx t/ds/a.docset/Contents/Resources/Documents/about.html @@ -19,7 +22,9 @@ t/ds/c.docset/Contents/Resources/docSet.dsidx t/ds/c.docset/Contents/Resources/Documents/category.html t/ds/c.docset/Contents/Resources/Documents/class.html t/ds/dummy-file +t/feed.xml t/mkindex.pl t/perlcritic.t t/perlcriticrc t/Zeal.t +t/Zeal-Feed.t diff --git a/t/Zeal-Feed.t b/t/Zeal-Feed.t new file mode 100644 index 0000000..9113bc9 --- /dev/null +++ b/t/Zeal-Feed.t @@ -0,0 +1,34 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Test::More tests => 23; +BEGIN { use_ok('Zeal::Feed') }; + +my $feed = Zeal::Feed->new_from_file('t/feed.xml'); +is $feed->version, '1.2.3', 'feed version is 1.2.3'; +my @urls = sort $feed->urls; +my $url_re = qr,^http://srv[12]\.example\.com/feed\.tar\.gz$,; +like $urls[$_-1], $url_re, "feed url $_ is correct" for 1, 2; +like $feed->url, $url_re, 'feed random url is correct'; + +use File::Temp qw/tempdir/; + +sub test_unpack { + my ($arch) = @_; + my $dir = tempdir 'zeal-testXXXX', TMPDIR => 1, CLEANUP => 1; + note "Testing unpack of $arch"; + Zeal::Feed::_unpack_tar_to_dir($arch, $dir); + ok -d "$dir/a.docset", 'Root directory of unpacked docset exists'; + ok -f "$dir/a.docset/Contents/Info.plist", 'Info.plist exists'; +} + +note "Testing unpack with default tar"; +test_unpack $_ for 't/a.tar', 't/a.tar.gz', 't/a.tar.bz2'; +note "Testing unpack with Archive::Tar by env variable"; +$ENV{ZEAL_USE_INTERNAL_TAR} = 1; +test_unpack $_ for 't/a.tar', 't/a.tar.gz', 't/a.tar.bz2'; +note "Testing unpack with Archive::Tar by clearing PATH"; +$ENV{ZEAL_USE_INTERNAL_TAR} = 0; +$ENV{PATH} = ''; +test_unpack $_ for 't/a.tar', 't/a.tar.gz', 't/a.tar.bz2'; diff --git a/t/a.tar b/t/a.tar new file mode 100644 index 0000000..362cc8c Binary files /dev/null and b/t/a.tar differ diff --git a/t/a.tar.bz2 b/t/a.tar.bz2 new file mode 100644 index 0000000..41454e8 Binary files /dev/null and b/t/a.tar.bz2 differ diff --git a/t/a.tar.gz b/t/a.tar.gz new file mode 100644 index 0000000..1c8d473 Binary files /dev/null and b/t/a.tar.gz differ diff --git a/t/feed.xml b/t/feed.xml new file mode 100644 index 0000000..3ad8cb2 --- /dev/null +++ b/t/feed.xml @@ -0,0 +1,5 @@ + + 1.2.3 + http://srv1.example.com/feed.tar.gz + http://srv2.example.com/feed.tar.gz +