diff options
Diffstat (limited to 't')
-rw-r--r-- | t/common.perl | 16 | ||||
-rw-r--r-- | t/feed.t | 13 | ||||
-rw-r--r-- | t/html_index.t | 14 |
3 files changed, 27 insertions, 16 deletions
diff --git a/t/common.perl b/t/common.perl new file mode 100644 index 00000000..a3585bf6 --- /dev/null +++ b/t/common.perl @@ -0,0 +1,16 @@ +require IO::File; +use POSIX qw/dup/; + +sub stream_to_string { + my ($cb) = @_; + my $headers; + my $io = IO::File->new_tmpfile; + my $dup = dup($io->fileno); + my $response = sub { $headers = \@_, $io }; + $cb->($response); + $io = IO::File->new; + $io->fdopen($dup, 'r+'); + $io->seek(0, 0); + $io->read(my $str, ($io->stat)[7]); + $str; +} @@ -9,6 +9,11 @@ use PublicInbox::Config; use IPC::Run qw/run/; use File::Temp qw/tempdir/; my $have_xml_feed = eval { require XML::Feed; 1 }; +require 't/common.perl'; + +sub string_feed { + stream_to_string(PublicInbox::Feed::generate($_[0])); +} my $tmpdir = tempdir(CLEANUP => 1); my $git_dir = "$tmpdir/gittest"; @@ -58,7 +63,7 @@ EOF { # check initial feed { - my $feed = PublicInbox::Feed->generate({ + my $feed = string_feed({ git_dir => $git_dir, max => 3 }); @@ -101,7 +106,7 @@ EOF # check spam shows up { - my $spammy_feed = PublicInbox::Feed->generate({ + my $spammy_feed = string_feed({ git_dir => $git_dir, max => 3 }); @@ -123,7 +128,7 @@ EOF # spam no longer shows up { - my $feed = PublicInbox::Feed->generate({ + my $feed = string_feed({ git_dir => $git_dir, max => 3 }); @@ -140,7 +145,7 @@ EOF # check pi_config { foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) { - my $feed = PublicInbox::Feed->generate({ + my $feed = string_feed({ git_dir => $git_dir, max => 3, listname => 'asdf', diff --git a/t/html_index.t b/t/html_index.t index 6286fc47..73311f65 100644 --- a/t/html_index.t +++ b/t/html_index.t @@ -55,18 +55,8 @@ EOF git_dir => $git_dir, max => 3 }); - my $headers; - my $io = IO::File->new_tmpfile; - use POSIX qw/dup/; - my $dup = dup($io->fileno); - my $response = sub { $headers = \@_, $io }; - $cb->($response); - $io = IO::File->new; - $io->fdopen($dup, 'r+'); - $io->seek(0, 0); - $io->read(my $feed, 666666); - like($feed, qr/html/, "feed is valid HTML :)"); - $io->close; + require 't/common.perl'; + like(stream_to_string($cb), qr/html/, "feed is valid HTML :)"); } done_testing(); |