user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH] tests: switch to XML::TreePP for testing Atom feeds
Date: Thu,  6 Feb 2020 20:59:45 +0000	[thread overview]
Message-ID: <20200206205945.6297-1-e@yhbt.net> (raw)

XML::Feed pulls in a lot of dependencies, some of which XS.
That makes testing with blead or any non-OS-supplied Perl
installations more time consuming and more difficult because
of the need to have development headers and libraries for
libexpat1 or libxml2.

Performance from libexpat1 or libxml2 for our small tests cases
isn't relevant, either, and the pure Perl XML::TreePP seems up
to the task.  It's also available in CentOS 7.x, FreeBSD 11.x,
and Debian, at least.
---
 INSTALL      |  6 +++---
 ci/deps.perl |  2 +-
 t/cgi.t      | 13 +++++++------
 t/feed.t     | 36 +++++++++++++++++++++---------------
 t/psgi_v2.t  | 10 +++++-----
 5 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/INSTALL b/INSTALL
index 0b4c3957..bf1c821a 100644
--- a/INSTALL
+++ b/INSTALL
@@ -174,9 +174,9 @@ Optional packages testing and development:
                                    pkg: perl5
                                    rpm: perl-Test-Simple
 
-- XML::Feed                        deb: libxml-feed-perl
-                                   pkg: p5-XML-Feed
-                                   rpm: perl-XML-Feed
+- XML::TreePP                      deb: libxml-treepp-perl
+                                   pkg: p5-XML-TreePP
+                                   rpm: perl-XML-TreePP
 
 standard MakeMaker installation (Perl)
 --------------------------------------
diff --git a/ci/deps.perl b/ci/deps.perl
index 5ecf9c9f..b960089f 100755
--- a/ci/deps.perl
+++ b/ci/deps.perl
@@ -50,7 +50,7 @@ my $profiles = {
 
 	# optional developer stuff
 	devtest => [ qw(
-		XML::Feed
+		XML::TreePP
 		curl
 		w3m
 		) ],
diff --git a/t/cgi.t b/t/cgi.t
index dc1c8b8a..97bdebd9 100644
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -121,18 +121,19 @@ EOF
 		SKIP: { skip 'DBD::SQLite not available', 2 };
 	}
 
-	my $have_xml_feed = eval { require XML::Feed; 1 } if $indexed;
-	if ($have_xml_feed) {
+	my $have_xml_treepp = eval { require XML::TreePP; 1 } if $indexed;
+	if ($have_xml_treepp) {
 		$path = "/test/blahblah\@example.com/t.atom";
 		$res = cgi_run($path);
 		like($res->{head}, qr/^Status: 200 /, "atom returned 200");
 		like($res->{head}, qr!^Content-Type: application/atom\+xml!m,
 			"search returned atom");
-		my $p = XML::Feed->parse(\($res->{body}));
-		is($p->format, "Atom", "parsed atom feed");
-		is(scalar $p->entries, 3, "parsed three entries");
+		my $t = XML::TreePP->new->parse($res->{body});
+		is(scalar @{$t->{feed}->{entry}}, 3, "parsed three entries");
+		like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
+				'looks like an an Atom feed');
 	} else {
-		SKIP: { skip 'DBD::SQLite or XML::Feed missing', 2 };
+		SKIP: { skip 'DBD::SQLite or XML::TreePP missing', 2 };
 	}
 }
 
diff --git a/t/feed.t b/t/feed.t
index 5333d582..cfa09a7c 100644
--- a/t/feed.t
+++ b/t/feed.t
@@ -7,7 +7,7 @@ use Email::MIME;
 use PublicInbox::Feed;
 use PublicInbox::Import;
 use PublicInbox::Inbox;
-my $have_xml_feed = eval { require XML::Feed; 1 };
+my $have_xml_treepp = eval { require XML::TreePP; 1 };
 use PublicInbox::TestCommon;
 
 sub string_feed {
@@ -79,12 +79,14 @@ EOF
 	{
 		my $feed = string_feed({ -inbox => $ibx });
 		SKIP: {
-			skip 'XML::Feed missing', 2 unless $have_xml_feed;
-			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:test@example',
-				"id is set to default");
+			skip 'XML::TreePP missing', 3 unless $have_xml_treepp;
+			my $t = XML::TreePP->new->parse($feed);
+			like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
+				'looks like an an Atom feed');
+			is(scalar @{$t->{feed}->{entry}}, 3,
+				'parsed three entries');
+			is($t->{feed}->{id}, 'mailto:test@example',
+				'id is set to default');
 		}
 
 		like($feed, qr/drop me/, "long quoted text kept");
@@ -111,10 +113,12 @@ EOF
 	{
 		my $spammy_feed = string_feed({ -inbox => $ibx });
 		SKIP: {
-			skip 'XML::Feed missing', 2 unless $have_xml_feed;
-			my $p = XML::Feed->parse(\$spammy_feed);
-			is($p->format, "Atom", "parsed atom feed");
-			is(scalar $p->entries, 3, "parsed three entries");
+			skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
+			my $t = XML::TreePP->new->parse($spammy_feed);
+			like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
+				'looks like an an Atom feed');
+			is(scalar @{$t->{feed}->{entry}}, 3,
+				'parsed three entries');
 		}
 		like($spammy_feed, qr/SPAM/s, "spam showed up :<");
 	}
@@ -127,10 +131,12 @@ EOF
 	{
 		my $feed = string_feed({ -inbox => $ibx });
 		SKIP: {
-			skip 'XML::Feed missing', 2 unless $have_xml_feed;
-			my $p = XML::Feed->parse(\$feed);
-			is($p->format, "Atom", "parsed atom feed");
-			is(scalar $p->entries, 3, "parsed three entries");
+			skip 'XML::TreePP missing', 2 unless $have_xml_treepp;
+			my $t = XML::TreePP->new->parse($feed);
+			like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
+				'looks like an an Atom feed');
+			is(scalar @{$t->{feed}->{entry}}, 3,
+				'parsed three entries');
 		}
 		unlike($feed, qr/SPAM/, "spam gone :>");
 	}
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index fc825acf..2c9387a4 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -160,11 +160,11 @@ test_psgi(sub { $www->call(@_) }, sub {
 	$res = $cb->(GET('/v2test/?q=m:a-mid@b&x=A'));
 	is($res->code, 200, 'success with Atom search');
 	SKIP: {
-		require_mods(qw(XML::Feed), 2);
-		$raw = $res->content;
-		my $p = XML::Feed->parse(\$raw);
-		is($p->format, "Atom", "parsed atom feed");
-		is(scalar $p->entries, 3, "parsed three entries");
+		require_mods(qw(XML::TreePP), 2);
+		my $t = XML::TreePP->new->parse($res->content);
+		like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
+			'looks like an an Atom feed');
+		is(scalar @{$t->{feed}->{entry}}, 3, 'parsed three entries');
 	};
 
 	local $SIG{__WARN__} = 'DEFAULT';

                 reply	other threads:[~2020-02-06 20:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200206205945.6297-1-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).