X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Ffeed.t;h=71cbb7356e7287b6b304330b70b15c6feec8b27c;hb=f76f265a851944b5dedcc3be5f3b5224b6ebda89;hp=379f8d398fbcead3e31b899af73a3e303bc00412;hpb=c5f0993848ffe4e781015e0b19fadba3f16692b9;p=public-inbox.git diff --git a/t/feed.t b/t/feed.t index 379f8d39..71cbb735 100644 --- a/t/feed.t +++ b/t/feed.t @@ -1,12 +1,19 @@ -# Copyright (C) 2014, Eric Wong and all contributors +# Copyright (C) 2014-2015 all contributors # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) use strict; use warnings; use Test::More; use Email::Simple; use PublicInbox::Feed; +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"; @@ -16,12 +23,6 @@ my $git_dir = "$tmpdir/gittest"; local $ENV{GIT_DIR} = $git_dir; foreach my $i (1..6) { - my $pid = open(my $pipe, "|-"); - defined $pid or die "fork/pipe failed: $!\n"; - if ($pid == 0) { - exec("ssoma-mda", $git_dir); - } - my $simple = Email::Simple->new(< To: U @@ -35,6 +36,15 @@ Date: Thu, 01 Jan 1970 00:00:00 +0000 > I quote to much > I quote to much > I quote to much +> I quote to much +> I quote to much +> I quote to much +> I quote to much +> I quote to much +> I quote to much +> I quote to much +> I quote to much +> I quote to much msg $i @@ -43,13 +53,17 @@ msg $i keep me EOF - print $pipe $simple->as_string or die "print failed: $!\n"; - close $pipe or die "close pipe failed: $!\n"; + my $str = $simple->as_string; + run(['ssoma-mda', $git_dir], \$str) or + die "mda failed: $?\n"; } +} +# spam check +{ # check initial feed { - my $feed = PublicInbox::Feed->generate({ + my $feed = string_feed({ git_dir => $git_dir, max => 3 }); @@ -58,8 +72,13 @@ EOF my $p = XML::Feed->parse(\$feed); is($p->format, "Atom", "parsed atom feed"); is(scalar $p->entries, 3, "parsed three entries"); + is($p->id, 'mailto:public-inbox@example.com', + "id is set to default"); } + unlike($feed, qr/drop me/, "long quoted text dropped"); + like($feed, qr!/\d%40example\.com/f/#q!, + "/f/ url generated for long quoted text"); like($feed, qr/inline me here/, "short quoted text kept"); like($feed, qr/keep me/, "unquoted text saved"); } @@ -87,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 }); @@ -102,18 +121,14 @@ EOF # nuke spam { - my $pid = open(my $pipe, "|-"); - defined $pid or die "fork/pipe failed: $!\n"; - if ($pid == 0) { - exec("ssoma-rm", $git_dir); - } - print $pipe $spam->as_string or die "print failed: $!\n"; - close $pipe or die "close pipe failed: $!\n"; + my $spam_str = $spam->as_string; + run(["ssoma-rm", $git_dir], \$spam_str) or + die "ssoma-rm failed: $?\n"; } # spam no longer shows up { - my $feed = PublicInbox::Feed->generate({ + my $feed = string_feed({ git_dir => $git_dir, max => 3 }); @@ -127,4 +142,26 @@ EOF } } +# check pi_config +{ + foreach my $addr (('a@example.com'), ['a@example.com','b@localhost']) { + my $feed = string_feed({ + git_dir => $git_dir, + max => 3, + listname => 'asdf', + pi_config => bless({ + 'publicinbox.asdf.address' => $addr, + }, 'PublicInbox::Config'), + }); + SKIP: { + skip 'XML::Feed missing', 3 unless $have_xml_feed; + my $p = XML::Feed->parse(\$feed); + is($p->id, 'mailto:a@example.com', + "ID is set correctly"); + is($p->format, "Atom", "parsed atom feed"); + is(scalar $p->entries, 3, "parsed three entries"); + } + } +} + done_testing();