unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/3] remove Email::MIME->create use
@ 2020-04-25  5:52 Eric Wong
  2020-04-25  5:52 ` [PATCH 1/3] testcommon: introduce mime_load sub Eric Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Wong @ 2020-04-25  5:52 UTC (permalink / raw)
  To: meta

Instead, I used Email::MIME->create for a final time with [1/3]
to generate the data for [2/3].  Reducing dependencies on
Email::MIME will make it easier for us to switch it out with
a potentially better alternative.

Eric Wong (3):
  testcommon: introduce mime_load sub
  tests: remove Email::MIME->create use entirely
  tests: replace mime_from_path with mime_load

 MANIFEST                      | 12 ++++++++
 lib/PublicInbox/TestCommon.pm |  8 +++++-
 t/filter_base-junk.eml        | 19 +++++++++++++
 t/filter_base-xhtml.eml       | 19 +++++++++++++
 t/filter_base.t               | 53 ++---------------------------------
 t/filter_mirror.t             | 30 ++------------------
 t/mda-mime.eml                | 21 ++++++++++++++
 t/mda.t                       | 37 ++----------------------
 t/msg_iter-nested.eml         | 26 +++++++++++++++++
 t/msg_iter-order.eml          | 16 +++++++++++
 t/msg_iter.t                  | 24 ++++------------
 t/nntpd-tls.t                 |  4 +--
 t/plack-2-txt-bodies.eml      | 17 +++++++++++
 t/plack-attached-patch.eml    | 20 +++++++++++++
 t/plack-qp.eml                |  8 ++++++
 t/plack.t                     | 53 ++---------------------------------
 t/psgi_attach.eml             | 38 +++++++++++++++++++++++++
 t/psgi_attach.t               | 44 ++---------------------------
 t/psgi_v2-new.eml             | 17 +++++++++++
 t/psgi_v2-old.eml             | 17 +++++++++++
 t/psgi_v2.t                   | 22 ++-------------
 t/search-amsg.eml             | 23 +++++++++++++++
 t/search.t                    | 36 ++----------------------
 t/solver_git.t                |  4 +--
 24 files changed, 286 insertions(+), 282 deletions(-)
 create mode 100644 t/filter_base-junk.eml
 create mode 100644 t/filter_base-xhtml.eml
 create mode 100644 t/mda-mime.eml
 create mode 100644 t/msg_iter-nested.eml
 create mode 100644 t/msg_iter-order.eml
 create mode 100644 t/plack-2-txt-bodies.eml
 create mode 100644 t/plack-attached-patch.eml
 create mode 100644 t/plack-qp.eml
 create mode 100644 t/psgi_attach.eml
 create mode 100644 t/psgi_v2-new.eml
 create mode 100644 t/psgi_v2-old.eml
 create mode 100644 t/search-amsg.eml


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] testcommon: introduce mime_load sub
  2020-04-25  5:52 [PATCH 0/3] remove Email::MIME->create use Eric Wong
@ 2020-04-25  5:52 ` Eric Wong
  2020-04-25  5:52 ` [PATCH 2/3] tests: remove Email::MIME->create use entirely Eric Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-04-25  5:52 UTC (permalink / raw)
  To: meta

We'll use this to create, memoize, and reuse .eml files.  This
will be used to reduce (and eventually eliminate) our dependency
on Email::MIME in tests.
---
 lib/PublicInbox/TestCommon.pm | 25 ++++++++++++++++++++++++-
 t/filter_base.t               | 12 +++++++-----
 t/filter_mirror.t             |  9 +++++----
 t/mda.t                       |  5 +++--
 t/msg_iter.t                  | 10 +++++++---
 t/plack.t                     | 20 ++++++++++++--------
 t/psgi_attach.t               | 13 ++++---------
 t/psgi_v2.t                   |  5 +++--
 t/search.t                    |  6 ++++--
 9 files changed, 69 insertions(+), 36 deletions(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index b50871e8..ac14d27b 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -9,7 +9,30 @@ use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek);
 use POSIX qw(dup2);
 use IO::Socket::INET;
 our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
-	run_script start_script key2sub xsys xqx);
+	run_script start_script key2sub xsys xqx mime_load);
+
+sub mime_load ($;&) {
+	my ($path, $cb) = @_;
+	if (open(my $fh, '<', $path)) {
+		PublicInbox::MIME->new(\(do { local $/; <$fh> }));
+	} elsif ($cb) {
+		require File::Temp;
+
+		my $mime = $cb->();
+		my ($dir) = ($path =~ m!(.+)/(?:[^/]+)\z!);
+		-d $dir or die "BUG: dir=$dir is not the dir of $path";
+		my $fh = File::Temp->new(DIR => $dir);
+		$fh->autoflush(1);
+		print $fh $mime->as_string or die "print: $!";
+		my $fn = $fh->filename;
+		rename($fn, $path) or die "link $fn => $path: $!";
+		$fh->unlink_on_destroy(0);
+		pop @_; # retry via tail recursion
+		goto &mime_load;
+	} else {
+		die "open $path: $!";
+	}
+}
 
 sub tmpdir (;$) {
 	my ($base) = @_;
diff --git a/t/filter_base.t b/t/filter_base.t
index f25d2dd7..7919dd65 100644
--- a/t/filter_base.t
+++ b/t/filter_base.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
+use PublicInbox::TestCommon;
 use_ok 'PublicInbox::Filter::Base';
 
 {
@@ -21,6 +21,7 @@ use_ok 'PublicInbox::Filter::Base';
 
 {
 	my $f = PublicInbox::Filter::Base->new;
+	my $email = mime_load 't/filter_base-xhtml.eml', sub {
 	my $html_body = "<html><body>hi</body></html>";
 	my $parts = [
 		Email::MIME->create(
@@ -38,19 +39,20 @@ use_ok 'PublicInbox::Filter::Base';
 			body => 'hi = "bye"',
 		)
 	];
-	my $email = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 		  From => 'a@example.com',
 		  Subject => 'blah',
 		  'Content-Type' => 'multipart/alternative'
 		],
 		parts => $parts,
-	);
+	)}; # mime_load sub
 	is($f->delivery($email), 100, "xhtml rejected");
 }
 
 {
 	my $f = PublicInbox::Filter::Base->new;
+	my $email = mime_load 't/filter_base-junk.eml', sub {
 	my $parts = [
 		Email::MIME->create(
 			attributes => {
@@ -67,14 +69,14 @@ use_ok 'PublicInbox::Filter::Base';
 			body => 'junk',
 		)
 	];
-	my $email = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 		  From => 'a@example.com',
 		  Subject => 'blah',
 		  'Content-Type' => 'multipart/mixed'
 		],
 		parts => $parts,
-	);
+	)}; # mime_load sub
 	is($f->delivery($email), 100, 'proprietary format rejected on glob');
 }
 
diff --git a/t/filter_mirror.t b/t/filter_mirror.t
index b1946146..694209d9 100644
--- a/t/filter_mirror.t
+++ b/t/filter_mirror.t
@@ -3,12 +3,13 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
+use PublicInbox::TestCommon;
 use_ok 'PublicInbox::Filter::Mirror';
 
 my $f = PublicInbox::Filter::Mirror->new;
 ok($f, 'created PublicInbox::Filter::Mirror object');
 {
+	my $email = mime_load 't/filter_mirror.eml', sub {
 	my $html_body = "<html><body>hi</body></html>";
 	my $parts = [
 		Email::MIME->create(
@@ -26,15 +27,15 @@ ok($f, 'created PublicInbox::Filter::Mirror object');
 			body => 'hi = "bye"',
 		)
 	];
-	my $email = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 		  From => 'a@example.com',
 		  Subject => 'blah',
 		  'Content-Type' => 'multipart/alternative'
 		],
 		parts => $parts,
-	);
+	)}; # mime_laod sub
 	is($f->ACCEPT, $f->delivery($email), 'accept any trash that comes');
 }
 
-done_testing();
+ done_testing();
diff --git a/t/mda.t b/t/mda.t
index fb505146..5457f17f 100644
--- a/t/mda.t
+++ b/t/mda.t
@@ -233,6 +233,7 @@ EOF
 		"learned ham idempotently ");
 
 	# ensure trained email is filtered, too
+	$mime = mime_load 't/mda-mime.eml', sub {
 	my $html_body = "<html><body>hi</body></html>";
 	my $parts = [
 		Email::MIME->create(
@@ -251,7 +252,7 @@ EOF
 		)
 	];
 	$mid = 'multipart-html-sucks@11';
-	$mime = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 		  From => 'a@example.com',
 		  Subject => 'blah',
@@ -260,7 +261,7 @@ EOF
 		  'Content-Type' => 'multipart/alternative',
 		],
 		parts => $parts,
-	);
+	)}; # mime_load sub
 
 	{
 		$in = $mime->as_string;
diff --git a/t/msg_iter.t b/t/msg_iter.t
index 573ee412..ac2066a2 100644
--- a/t/msg_iter.t
+++ b/t/msg_iter.t
@@ -3,16 +3,18 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
+use PublicInbox::TestCommon;
 use PublicInbox::Hval qw(ascii_html);
 use PublicInbox::InboxWritable;
 use_ok('PublicInbox::MsgIter');
 
 {
+	my $mime = mime_load 't/msg_iter-order.eml', sub {
 	my $parts = [ Email::MIME->create(body => "a\n"),
 			Email::MIME->create(body => "b\n") ];
-	my $mime = Email::MIME->create(parts => $parts,
+	Email::MIME->create(parts => $parts,
 				header_str => [ From => 'root@localhost' ]);
+	}; # mime_load sub
 	my @parts;
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
@@ -24,13 +26,15 @@ use_ok('PublicInbox::MsgIter');
 }
 
 {
+	my $mime = mime_load 't/msg_iter-nested.eml', sub {
 	my $parts = [ Email::MIME->create(body => 'a'),
 			Email::MIME->create(body => 'b') ];
 	$parts = [ Email::MIME->create(parts => $parts,
 				header_str => [ From => 'sub@localhost' ]),
 			Email::MIME->create(body => 'sig') ];
-	my $mime = Email::MIME->create(parts => $parts,
+	Email::MIME->create(parts => $parts,
 				header_str => [ From => 'root@localhost' ]);
+	}; # mime_load sub
 	my @parts;
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
diff --git a/t/plack.t b/t/plack.t
index b16bc8de..d45dbcd2 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -52,11 +52,12 @@ EOF
 
 	# multipart with two text bodies
 	my %attr_text = (attributes => { content_type => 'text/plain' });
+	$mime = mime_load 't/plack-2-txt-bodies.eml', sub {
 	my $parts = [
 		Email::MIME->create(%attr_text, body => 'hi'),
 		Email::MIME->create(%attr_text, body => 'bye')
 	];
-	$mime = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 			From => 'a@example.com',
 			Subject => 'blargh',
@@ -64,11 +65,13 @@ EOF
 			'In-Reply-To' => '<irp@example.com>'
 		],
 		parts => $parts,
-	);
+	)}; # mime_load sub
 	$im->add($mime);
 
 	# multipart with attached patch + filename
-	$parts = [ Email::MIME->create(%attr_text, body => 'hi, see attached'),
+	$mime = mime_load 't/plack-attached-patch.eml', sub {
+	my $parts = [
+		Email::MIME->create(%attr_text, body => 'hi, see attached'),
 		Email::MIME->create(
 			attributes => {
 					content_type => 'text/plain',
@@ -78,18 +81,19 @@ EOF
 				"@@ -49, 7 +49,34 @@\n"
 			)
 	];
-	$mime = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 			From => 'a@example.com',
 			Subject => '[PATCH] asdf',
 			'Message-ID' => '<patch@example.com>'
 		],
 		parts => $parts
-	);
+	)}; # mime_load sub
 	$im->add($mime);
 
 	# multipart collapsed to single quoted-printable text/plain
-	$parts = [
+	$mime = mime_load 't/plack-qp.eml', sub {
+	my $parts = [
 		Email::MIME->create(
 			attributes => {
 				content_type => 'text/plain',
@@ -98,14 +102,14 @@ EOF
 			body => 'hi = bye',
 		)
 	];
-	$mime = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 			From => 'qp@example.com',
 			Subject => 'QP',
 			'Message-ID' => '<qp@example.com>',
 			],
 		parts => $parts,
-	);
+	)};
 	like($mime->body_raw, qr/hi =3D bye=/, 'our test used QP correctly');
 	$im->add($mime);
 
diff --git a/t/psgi_attach.t b/t/psgi_attach.t
index 2376bba7..0dde9323 100644
--- a/t/psgi_attach.t
+++ b/t/psgi_attach.t
@@ -26,13 +26,11 @@ my $im = PublicInbox::Import->new($git, 'test', $addr);
 $im->init_bare;
 
 {
-	open my $fh, '<', '/dev/urandom' or die "unable to open urandom: $!\n";
-	sysread($fh, my $buf, 8);
-	is(8, length($buf), 'read some random data');
 	my $qp = "abcdef=g\n==blah\n";
-	my $b64 = 'b64'.$buf."\n";
+	my $b64 = "b64\xde\xad\xbe\xef\n";
 	my $txt = "plain\ntext\npass\nthrough\n";
 	my $dot = "dotfile\n";
+	my $mime = mime_load 't/psgi_attach.eml', sub {
 	my $parts = [
 		Email::MIME->create(
 			attributes => {
@@ -61,14 +59,11 @@ $im->init_bare;
 			},
 			body => $dot),
 	];
-	my $mime = Email::MIME->create(
+	Email::MIME->create(
 		parts => $parts,
 		header_str => [ From => 'root@z', 'Message-Id' => '<Z@B>',
 			Subject => 'hi']
-	);
-	$mime = $mime->as_string;
-	$mime =~ s/\r\n/\n/g; # normalize to LF only
-	$mime = PublicInbox::MIME->new($mime);
+	)}; # mime_load sub
 	$im->add($mime);
 	$im->done;
 
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index bc26a112..5d212ca6 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -225,6 +225,7 @@ test_psgi(sub { $www->call(@_) }, sub {
 
 	# ensure conflicted attachments can be resolved
 	foreach my $body (qw(old new)) {
+		$mime = mime_load "t/psgi_v2-$body.eml", sub {
 		my $parts = [
 			Email::MIME->create(
 				attributes => { content_type => 'text/plain' },
@@ -238,12 +239,12 @@ test_psgi(sub { $www->call(@_) }, sub {
 				body => $body
 			)
 		];
-		$mime = Email::MIME->create(
+		Email::MIME->create(
 			parts => $parts,
 			header_str => [ From => 'root@z',
 				'Message-ID' => '<a@dup>',
 				Subject => 'hi']
-		);
+		)}; # mime_load sub
 		ok($im->add($mime), "added attachment $body");
 	}
 	$im->done;
diff --git a/t/search.t b/t/search.t
index 0fd5fdee..0301fd90 100644
--- a/t/search.t
+++ b/t/search.t
@@ -371,6 +371,7 @@ $ibx->with_umask(sub {
 }
 
 $ibx->with_umask(sub {
+	my $amsg = mime_load 't/search-amsg.eml', sub {
 	my $part1 = Email::MIME->create(
                  attributes => {
                      content_type => 'text/plain',
@@ -391,7 +392,7 @@ $ibx->with_umask(sub {
                  },
                  body_str => 'inside another',
 	);
-	my $amsg = Email::MIME->create(
+	Email::MIME->create(
 		header_str => [
 			Subject => 'see attachment',
 			'Message-ID' => '<file@attached>',
@@ -399,7 +400,8 @@ $ibx->with_umask(sub {
 			To => 'list@example.com',
 		],
 		parts => [ $part1, $part2 ],
-	);
+	)}; # mime_load sub
+
 	ok($rw->add_message($amsg), 'added attachment');
 	$rw_commit->();
 	$ro->reopen;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] tests: remove Email::MIME->create use entirely
  2020-04-25  5:52 [PATCH 0/3] remove Email::MIME->create use Eric Wong
  2020-04-25  5:52 ` [PATCH 1/3] testcommon: introduce mime_load sub Eric Wong
@ 2020-04-25  5:52 ` Eric Wong
  2020-04-25  5:52 ` [PATCH 3/3] tests: replace mime_from_path with mime_load Eric Wong
  2020-04-26  7:35 ` [PATCH 4/3] testcommon: mime_load: drop extra $cb arg Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-04-25  5:52 UTC (permalink / raw)
  To: meta

Replace them with .eml files generated with the help of
Email::MIME, but without some extraneous and unnecessary
headers, and strip mime_load down to just loading files.

This will give us more freedom to experiment with other mail
libraries which may be more correct, better maintained, use
less memory and/or be faster than Email::MIME.
---
 MANIFEST                      | 12 ++++++++
 lib/PublicInbox/TestCommon.pm | 23 ++------------
 t/filter_base-junk.eml        | 19 ++++++++++++
 t/filter_base-xhtml.eml       | 19 ++++++++++++
 t/filter_base.t               | 53 ++------------------------------
 t/filter_mirror.t             | 27 +----------------
 t/mda-mime.eml                | 21 +++++++++++++
 t/mda.t                       | 34 ++-------------------
 t/msg_iter-nested.eml         | 26 ++++++++++++++++
 t/msg_iter-order.eml          | 16 ++++++++++
 t/msg_iter.t                  | 17 ++---------
 t/plack-2-txt-bodies.eml      | 17 +++++++++++
 t/plack-attached-patch.eml    | 20 ++++++++++++
 t/plack-qp.eml                |  8 +++++
 t/plack.t                     | 57 ++---------------------------------
 t/psgi_attach.eml             | 38 +++++++++++++++++++++++
 t/psgi_attach.t               | 37 +----------------------
 t/psgi_v2-new.eml             | 17 +++++++++++
 t/psgi_v2-old.eml             | 17 +++++++++++
 t/psgi_v2.t                   | 23 ++------------
 t/search-amsg.eml             | 23 ++++++++++++++
 t/search.t                    | 34 ++-------------------
 22 files changed, 271 insertions(+), 287 deletions(-)
 create mode 100644 t/filter_base-junk.eml
 create mode 100644 t/filter_base-xhtml.eml
 create mode 100644 t/mda-mime.eml
 create mode 100644 t/msg_iter-nested.eml
 create mode 100644 t/msg_iter-order.eml
 create mode 100644 t/plack-2-txt-bodies.eml
 create mode 100644 t/plack-attached-patch.eml
 create mode 100644 t/plack-qp.eml
 create mode 100644 t/psgi_attach.eml
 create mode 100644 t/psgi_v2-new.eml
 create mode 100644 t/psgi_v2-old.eml
 create mode 100644 t/search-amsg.eml

diff --git a/MANIFEST b/MANIFEST
index b06aa679..e3e0f2a8 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -231,6 +231,8 @@ t/emergency.t
 t/epoll.t
 t/fail-bin/spamc
 t/feed.t
+t/filter_base-junk.eml
+t/filter_base-xhtml.eml
 t/filter_base.t
 t/filter_mirror.t
 t/filter_rubylang.t
@@ -257,10 +259,13 @@ t/init.t
 t/iso-2202-jp.eml
 t/linkify.t
 t/main-bin/spamc
+t/mda-mime.eml
 t/mda.t
 t/mda_filter_rubylang.t
 t/mid.t
 t/mime.t
+t/msg_iter-nested.eml
+t/msg_iter-order.eml
 t/msg_iter.t
 t/msgmap.t
 t/msgtime.t
@@ -270,8 +275,12 @@ t/nntpd-tls.t
 t/nntpd.t
 t/nulsubject.t
 t/over.t
+t/plack-2-txt-bodies.eml
+t/plack-attached-patch.eml
+t/plack-qp.eml
 t/plack.t
 t/precheck.t
+t/psgi_attach.eml
 t/psgi_attach.t
 t/psgi_bad_mids.t
 t/psgi_mount.t
@@ -279,12 +288,15 @@ t/psgi_multipart_not.t
 t/psgi_scan_all.t
 t/psgi_search.t
 t/psgi_text.t
+t/psgi_v2-new.eml
+t/psgi_v2-old.eml
 t/psgi_v2.t
 t/purge.t
 t/qspawn.t
 t/replace.t
 t/reply.t
 t/run.perl
+t/search-amsg.eml
 t/search-thr-index.t
 t/search.t
 t/sigfd.t
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index ac14d27b..27390ab2 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -11,27 +11,10 @@ use IO::Socket::INET;
 our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
 	run_script start_script key2sub xsys xqx mime_load);
 
-sub mime_load ($;&) {
+sub mime_load ($) {
 	my ($path, $cb) = @_;
-	if (open(my $fh, '<', $path)) {
-		PublicInbox::MIME->new(\(do { local $/; <$fh> }));
-	} elsif ($cb) {
-		require File::Temp;
-
-		my $mime = $cb->();
-		my ($dir) = ($path =~ m!(.+)/(?:[^/]+)\z!);
-		-d $dir or die "BUG: dir=$dir is not the dir of $path";
-		my $fh = File::Temp->new(DIR => $dir);
-		$fh->autoflush(1);
-		print $fh $mime->as_string or die "print: $!";
-		my $fn = $fh->filename;
-		rename($fn, $path) or die "link $fn => $path: $!";
-		$fh->unlink_on_destroy(0);
-		pop @_; # retry via tail recursion
-		goto &mime_load;
-	} else {
-		die "open $path: $!";
-	}
+	open(my $fh, '<', $path) or die "open $path: $!";
+	PublicInbox::MIME->new(\(do { local $/; <$fh> }));
 }
 
 sub tmpdir (;$) {
diff --git a/t/filter_base-junk.eml b/t/filter_base-junk.eml
new file mode 100644
index 00000000..4733bbe5
--- /dev/null
+++ b/t/filter_base-junk.eml
@@ -0,0 +1,19 @@
+From: a@example.com
+Subject: blah
+Content-Type: multipart/mixed; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: application/vnd.ms-excel
+Content-Transfer-Encoding: base64
+
+anVuaw==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+junk=
+
+--b--
diff --git a/t/filter_base-xhtml.eml b/t/filter_base-xhtml.eml
new file mode 100644
index 00000000..d13a11cd
--- /dev/null
+++ b/t/filter_base-xhtml.eml
@@ -0,0 +1,19 @@
+From: a@example.com
+Subject: blah
+Content-Type: multipart/alternative; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: text/xhtml; charset=UTF-8
+Content-Transfer-Encoding: base64
+
+PGh0bWw+PGJvZHk+aGk8L2JvZHk+PC9odG1sPg==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+hi =3D "bye"=
+
+--b--
diff --git a/t/filter_base.t b/t/filter_base.t
index 7919dd65..bbd64189 100644
--- a/t/filter_base.t
+++ b/t/filter_base.t
@@ -21,62 +21,13 @@ use_ok 'PublicInbox::Filter::Base';
 
 {
 	my $f = PublicInbox::Filter::Base->new;
-	my $email = mime_load 't/filter_base-xhtml.eml', sub {
-	my $html_body = "<html><body>hi</body></html>";
-	my $parts = [
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/xhtml; charset=UTF-8',
-				encoding => 'base64',
-			},
-			body => $html_body,
-		),
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/plain',
-				encoding => 'quoted-printable',
-			},
-			body => 'hi = "bye"',
-		)
-	];
-	Email::MIME->create(
-		header_str => [
-		  From => 'a@example.com',
-		  Subject => 'blah',
-		  'Content-Type' => 'multipart/alternative'
-		],
-		parts => $parts,
-	)}; # mime_load sub
+	my $email = mime_load 't/filter_base-xhtml.eml';
 	is($f->delivery($email), 100, "xhtml rejected");
 }
 
 {
 	my $f = PublicInbox::Filter::Base->new;
-	my $email = mime_load 't/filter_base-junk.eml', sub {
-	my $parts = [
-		Email::MIME->create(
-			attributes => {
-				content_type => 'application/vnd.ms-excel',
-				encoding => 'base64',
-			},
-			body => 'junk',
-		),
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/plain',
-				encoding => 'quoted-printable',
-			},
-			body => 'junk',
-		)
-	];
-	Email::MIME->create(
-		header_str => [
-		  From => 'a@example.com',
-		  Subject => 'blah',
-		  'Content-Type' => 'multipart/mixed'
-		],
-		parts => $parts,
-	)}; # mime_load sub
+	my $email = mime_load 't/filter_base-junk.eml';
 	is($f->delivery($email), 100, 'proprietary format rejected on glob');
 }
 
diff --git a/t/filter_mirror.t b/t/filter_mirror.t
index 694209d9..0e641a03 100644
--- a/t/filter_mirror.t
+++ b/t/filter_mirror.t
@@ -9,32 +9,7 @@ use_ok 'PublicInbox::Filter::Mirror';
 my $f = PublicInbox::Filter::Mirror->new;
 ok($f, 'created PublicInbox::Filter::Mirror object');
 {
-	my $email = mime_load 't/filter_mirror.eml', sub {
-	my $html_body = "<html><body>hi</body></html>";
-	my $parts = [
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/html; charset=UTF-8',
-				encoding => 'base64',
-			},
-			body => $html_body,
-		),
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/plain',
-				encoding => 'quoted-printable',
-			},
-			body => 'hi = "bye"',
-		)
-	];
-	Email::MIME->create(
-		header_str => [
-		  From => 'a@example.com',
-		  Subject => 'blah',
-		  'Content-Type' => 'multipart/alternative'
-		],
-		parts => $parts,
-	)}; # mime_laod sub
+	my $email = mime_load 't/mda-mime.eml';
 	is($f->ACCEPT, $f->delivery($email), 'accept any trash that comes');
 }
 
diff --git a/t/mda-mime.eml b/t/mda-mime.eml
new file mode 100644
index 00000000..64a92816
--- /dev/null
+++ b/t/mda-mime.eml
@@ -0,0 +1,21 @@
+From: a@example.com
+Subject: blah
+Cc: test-public@example.com
+Message-ID: <multipart-html-sucks@11>
+Content-Type: multipart/alternative; boundary="b"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+
+--b
+Content-Type: text/html; charset=UTF-8
+Content-Transfer-Encoding: base64
+
+PGh0bWw+PGJvZHk+aGk8L2JvZHk+PC9odG1sPg==
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+
+hi =3D "bye"=
+
+--b--
diff --git a/t/mda.t b/t/mda.t
index 5457f17f..863eaf8f 100644
--- a/t/mda.t
+++ b/t/mda.t
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
 use Cwd qw(getcwd);
 use PublicInbox::MID qw(mid2path);
 use PublicInbox::Git;
@@ -22,7 +21,6 @@ my $fail_path = "$fail_bin:$ENV{PATH}"; # for spamc spam mock
 my $addr = 'test-public@example.com';
 my $cfgpfx = "publicinbox.test";
 my $faildir = "$home/faildir/";
-my $mime;
 my $git = PublicInbox::Git->new($maindir);
 
 my $fail_bad_header = sub ($$$) {
@@ -233,36 +231,8 @@ EOF
 		"learned ham idempotently ");
 
 	# ensure trained email is filtered, too
-	$mime = mime_load 't/mda-mime.eml', sub {
-	my $html_body = "<html><body>hi</body></html>";
-	my $parts = [
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/html; charset=UTF-8',
-				encoding => 'base64',
-			},
-			body => $html_body,
-		),
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/plain',
-				encoding => 'quoted-printable',
-			},
-			body => 'hi = "bye"',
-		)
-	];
-	$mid = 'multipart-html-sucks@11';
-	Email::MIME->create(
-		header_str => [
-		  From => 'a@example.com',
-		  Subject => 'blah',
-		  Cc => $addr,
-		  'Message-ID' => "<$mid>",
-		  'Content-Type' => 'multipart/alternative',
-		],
-		parts => $parts,
-	)}; # mime_load sub
-
+	my $mime = mime_load 't/mda-mime.eml';
+	($mid) = ($mime->header_raw('message-id') =~ /<([^>]+)>/);
 	{
 		$in = $mime->as_string;
 		ok(run_script(['-learn', 'ham'], undef, { 0 => \$in }),
diff --git a/t/msg_iter-nested.eml b/t/msg_iter-nested.eml
new file mode 100644
index 00000000..08d0adac
--- /dev/null
+++ b/t/msg_iter-nested.eml
@@ -0,0 +1,26 @@
+From: root@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="outer"
+
+--outer
+From: sub@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="inner"
+
+--inner
+MIME-Version: 1.0
+
+a
+--inner
+MIME-Version: 1.0
+
+b
+--inner--
+
+--outer
+MIME-Version: 1.0
+
+sig
+--outer--
diff --git a/t/msg_iter-order.eml b/t/msg_iter-order.eml
new file mode 100644
index 00000000..153af800
--- /dev/null
+++ b/t/msg_iter-order.eml
@@ -0,0 +1,16 @@
+From: root@localhost
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+MIME-Version: 1.0
+
+a
+
+--b
+MIME-Version: 1.0
+
+b
+
+--b--
diff --git a/t/msg_iter.t b/t/msg_iter.t
index ac2066a2..6adbf165 100644
--- a/t/msg_iter.t
+++ b/t/msg_iter.t
@@ -9,12 +9,7 @@ use PublicInbox::InboxWritable;
 use_ok('PublicInbox::MsgIter');
 
 {
-	my $mime = mime_load 't/msg_iter-order.eml', sub {
-	my $parts = [ Email::MIME->create(body => "a\n"),
-			Email::MIME->create(body => "b\n") ];
-	Email::MIME->create(parts => $parts,
-				header_str => [ From => 'root@localhost' ]);
-	}; # mime_load sub
+	my $mime = mime_load 't/msg_iter-order.eml';
 	my @parts;
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
@@ -26,15 +21,7 @@ use_ok('PublicInbox::MsgIter');
 }
 
 {
-	my $mime = mime_load 't/msg_iter-nested.eml', sub {
-	my $parts = [ Email::MIME->create(body => 'a'),
-			Email::MIME->create(body => 'b') ];
-	$parts = [ Email::MIME->create(parts => $parts,
-				header_str => [ From => 'sub@localhost' ]),
-			Email::MIME->create(body => 'sig') ];
-	Email::MIME->create(parts => $parts,
-				header_str => [ From => 'root@localhost' ]);
-	}; # mime_load sub
+	my $mime = mime_load 't/msg_iter-nested.eml';
 	my @parts;
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
diff --git a/t/plack-2-txt-bodies.eml b/t/plack-2-txt-bodies.eml
new file mode 100644
index 00000000..a06cd688
--- /dev/null
+++ b/t/plack-2-txt-bodies.eml
@@ -0,0 +1,17 @@
+From: a@example.com
+Subject: blargh
+Message-ID: <multipart@example.com>
+In-Reply-To: <irp@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+hi
+--b
+Content-Type: text/plain
+
+bye
+--b--
diff --git a/t/plack-attached-patch.eml b/t/plack-attached-patch.eml
new file mode 100644
index 00000000..bc6d295d
--- /dev/null
+++ b/t/plack-attached-patch.eml
@@ -0,0 +1,20 @@
+From: a@example.com
+Subject: [PATCH] asdf
+Message-ID: <patch@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+hi, see attached
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="foo&.patch"
+
+--- a/file
++++ b/file
+@@ -49, 7 +49,34 @@
+
+--b--
diff --git a/t/plack-qp.eml b/t/plack-qp.eml
new file mode 100644
index 00000000..d9008c8e
--- /dev/null
+++ b/t/plack-qp.eml
@@ -0,0 +1,8 @@
+From: qp@example.com
+Subject: QP
+Message-ID: <qp@example.com>
+MIME-Version: 1.0
+Content-Transfer-Encoding: quoted-printable
+Content-Type: text/plain
+
+hi =3D bye=
diff --git a/t/plack.t b/t/plack.t
index d45dbcd2..4fff9773 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
 use PublicInbox::TestCommon;
 my $psgi = "./examples/public-inbox.psgi";
 my ($tmpdir, $for_destroy) = tmpdir();
@@ -51,65 +50,15 @@ EOF
 	chomp @ls;
 
 	# multipart with two text bodies
-	my %attr_text = (attributes => { content_type => 'text/plain' });
-	$mime = mime_load 't/plack-2-txt-bodies.eml', sub {
-	my $parts = [
-		Email::MIME->create(%attr_text, body => 'hi'),
-		Email::MIME->create(%attr_text, body => 'bye')
-	];
-	Email::MIME->create(
-		header_str => [
-			From => 'a@example.com',
-			Subject => 'blargh',
-			'Message-ID' => '<multipart@example.com>',
-			'In-Reply-To' => '<irp@example.com>'
-		],
-		parts => $parts,
-	)}; # mime_load sub
+	$mime = mime_load 't/plack-2-txt-bodies.eml';
 	$im->add($mime);
 
 	# multipart with attached patch + filename
-	$mime = mime_load 't/plack-attached-patch.eml', sub {
-	my $parts = [
-		Email::MIME->create(%attr_text, body => 'hi, see attached'),
-		Email::MIME->create(
-			attributes => {
-					content_type => 'text/plain',
-					filename => "foo&.patch",
-			},
-			body => "--- a/file\n+++ b/file\n" .
-				"@@ -49, 7 +49,34 @@\n"
-			)
-	];
-	Email::MIME->create(
-		header_str => [
-			From => 'a@example.com',
-			Subject => '[PATCH] asdf',
-			'Message-ID' => '<patch@example.com>'
-		],
-		parts => $parts
-	)}; # mime_load sub
+	$mime = mime_load 't/plack-attached-patch.eml';
 	$im->add($mime);
 
 	# multipart collapsed to single quoted-printable text/plain
-	$mime = mime_load 't/plack-qp.eml', sub {
-	my $parts = [
-		Email::MIME->create(
-			attributes => {
-				content_type => 'text/plain',
-				encoding => 'quoted-printable'
-			},
-			body => 'hi = bye',
-		)
-	];
-	Email::MIME->create(
-		header_str => [
-			From => 'qp@example.com',
-			Subject => 'QP',
-			'Message-ID' => '<qp@example.com>',
-			],
-		parts => $parts,
-	)};
+	$mime = mime_load 't/plack-qp.eml';
 	like($mime->body_raw, qr/hi =3D bye=/, 'our test used QP correctly');
 	$im->add($mime);
 
diff --git a/t/psgi_attach.eml b/t/psgi_attach.eml
new file mode 100644
index 00000000..cfa3622c
--- /dev/null
+++ b/t/psgi_attach.eml
@@ -0,0 +1,38 @@
+From: root@z
+Message-Id: <Z@B>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: inline; filename="queue-pee"
+
+abcdef=3Dg
+=3D=3Dblah
+
+--b
+Content-Type: appication/octet-stream
+Content-Transfer-Encoding: base64
+Content-Disposition: inline; filename="bayce-sixty-four"
+
+YjY03q2+7wo=
+
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="noop.txt"
+
+plain
+text
+pass
+through
+
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename=".dotfile"
+
+dotfile
+
+--b--
diff --git a/t/psgi_attach.t b/t/psgi_attach.t
index 0dde9323..af0fbdd3 100644
--- a/t/psgi_attach.t
+++ b/t/psgi_attach.t
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use Test::More;
-use Email::MIME;
 use PublicInbox::TestCommon;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $maindir = "$tmpdir/main.git";
@@ -30,41 +29,7 @@ $im->init_bare;
 	my $b64 = "b64\xde\xad\xbe\xef\n";
 	my $txt = "plain\ntext\npass\nthrough\n";
 	my $dot = "dotfile\n";
-	my $mime = mime_load 't/psgi_attach.eml', sub {
-	my $parts = [
-		Email::MIME->create(
-			attributes => {
-				filename => 'queue-pee',
-				content_type => 'text/plain',
-				encoding => 'quoted-printable'
-			},
-			body => $qp),
-		Email::MIME->create(
-			attributes => {
-				filename => 'bayce-sixty-four',
-				content_type => 'appication/octet-stream',
-				encoding => 'base64',
-			},
-			body => $b64),
-		Email::MIME->create(
-			attributes => {
-				filename => 'noop.txt',
-				content_type => 'text/plain',
-			},
-			body => $txt),
-		Email::MIME->create(
-			attributes => {
-				filename => '.dotfile',
-				content_type => 'text/plain',
-			},
-			body => $dot),
-	];
-	Email::MIME->create(
-		parts => $parts,
-		header_str => [ From => 'root@z', 'Message-Id' => '<Z@B>',
-			Subject => 'hi']
-	)}; # mime_load sub
-	$im->add($mime);
+	$im->add(mime_load('t/psgi_attach.eml'));
 	$im->done;
 
 	my $www = PublicInbox::WWW->new($config);
diff --git a/t/psgi_v2-new.eml b/t/psgi_v2-new.eml
new file mode 100644
index 00000000..2c264714
--- /dev/null
+++ b/t/psgi_v2-new.eml
@@ -0,0 +1,17 @@
+From: root@z
+Message-ID: <a@dup>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+blah
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="attach.txt"
+
+new
+--b--
diff --git a/t/psgi_v2-old.eml b/t/psgi_v2-old.eml
new file mode 100644
index 00000000..f82dbf2f
--- /dev/null
+++ b/t/psgi_v2-old.eml
@@ -0,0 +1,17 @@
+From: root@z
+Message-ID: <a@dup>
+Subject: hi
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain
+
+blah
+--b
+Content-Type: text/plain
+Content-Disposition: inline; filename="attach.txt"
+
+old
+--b--
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 5d212ca6..9c19b041 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -9,7 +9,7 @@ use PublicInbox::MIME;
 use PublicInbox::Config;
 use PublicInbox::MID qw(mids);
 require_mods(qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
-		URI::Escape Plack::Builder Email::MIME));
+		URI::Escape Plack::Builder));
 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
 use_ok 'PublicInbox::WWW';
 use_ok 'PublicInbox::V2Writable';
@@ -225,26 +225,7 @@ test_psgi(sub { $www->call(@_) }, sub {
 
 	# ensure conflicted attachments can be resolved
 	foreach my $body (qw(old new)) {
-		$mime = mime_load "t/psgi_v2-$body.eml", sub {
-		my $parts = [
-			Email::MIME->create(
-				attributes => { content_type => 'text/plain' },
-				body => 'blah',
-			),
-			Email::MIME->create(
-				attributes => {
-					filename => 'attach.txt',
-					content_type => 'text/plain',
-				},
-				body => $body
-			)
-		];
-		Email::MIME->create(
-			parts => $parts,
-			header_str => [ From => 'root@z',
-				'Message-ID' => '<a@dup>',
-				Subject => 'hi']
-		)}; # mime_load sub
+		$mime = mime_load "t/psgi_v2-$body.eml";
 		ok($im->add($mime), "added attachment $body");
 	}
 	$im->done;
diff --git a/t/search-amsg.eml b/t/search-amsg.eml
new file mode 100644
index 00000000..c87c0f15
--- /dev/null
+++ b/t/search-amsg.eml
@@ -0,0 +1,23 @@
+Subject: see attachment
+Message-ID: <file@attached>
+From: "John Smith" <js@example.com>
+To: list@example.com
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/mixed; boundary="b"
+
+--b
+Content-Type: text/plain; charset="US-ASCII"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment; filename="attached_fart.txt"
+
+inside the attachment=
+
+--b
+Content-Type: text/plain; charset="US-ASCII"
+Content-Disposition: attachment; filename="part_deux.txt"
+Content-Transfer-Encoding: quoted-printable
+
+inside another=
+
+--b--
diff --git a/t/search.t b/t/search.t
index 0301fd90..40264345 100644
--- a/t/search.t
+++ b/t/search.t
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Test::More;
 use PublicInbox::TestCommon;
-require_mods(qw(DBD::SQLite Search::Xapian Email::MIME));
+require_mods(qw(DBD::SQLite Search::Xapian));
 require PublicInbox::SearchIdx;
 require PublicInbox::Inbox;
 require PublicInbox::InboxWritable;
@@ -371,37 +371,7 @@ $ibx->with_umask(sub {
 }
 
 $ibx->with_umask(sub {
-	my $amsg = mime_load 't/search-amsg.eml', sub {
-	my $part1 = Email::MIME->create(
-                 attributes => {
-                     content_type => 'text/plain',
-                     disposition  => 'attachment',
-                     charset => 'US-ASCII',
-		     encoding => 'quoted-printable',
-		     filename => 'attached_fart.txt',
-                 },
-                 body_str => 'inside the attachment',
-	);
-	my $part2 = Email::MIME->create(
-                 attributes => {
-                     content_type => 'text/plain',
-                     disposition  => 'attachment',
-                     charset => 'US-ASCII',
-		     encoding => 'quoted-printable',
-		     filename => 'part_deux.txt',
-                 },
-                 body_str => 'inside another',
-	);
-	Email::MIME->create(
-		header_str => [
-			Subject => 'see attachment',
-			'Message-ID' => '<file@attached>',
-			From => 'John Smith <js@example.com>',
-			To => 'list@example.com',
-		],
-		parts => [ $part1, $part2 ],
-	)}; # mime_load sub
-
+	my $amsg = mime_load 't/search-amsg.eml';
 	ok($rw->add_message($amsg), 'added attachment');
 	$rw_commit->();
 	$ro->reopen;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] tests: replace mime_from_path with mime_load
  2020-04-25  5:52 [PATCH 0/3] remove Email::MIME->create use Eric Wong
  2020-04-25  5:52 ` [PATCH 1/3] testcommon: introduce mime_load sub Eric Wong
  2020-04-25  5:52 ` [PATCH 2/3] tests: remove Email::MIME->create use entirely Eric Wong
@ 2020-04-25  5:52 ` Eric Wong
  2020-04-26  7:35 ` [PATCH 4/3] testcommon: mime_load: drop extra $cb arg Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-04-25  5:52 UTC (permalink / raw)
  To: meta

mime_from_path is designed to fail gracefully in busy Maildirs
whereas mime_load was made for loading files from a work tree.
---
 t/mda.t        | 4 +---
 t/msg_iter.t   | 9 ++-------
 t/nntpd-tls.t  | 4 +---
 t/search.t     | 4 +---
 t/solver_git.t | 4 +---
 5 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/t/mda.t b/t/mda.t
index 863eaf8f..03cc4bc3 100644
--- a/t/mda.t
+++ b/t/mda.t
@@ -62,9 +62,7 @@ local $ENV{GIT_COMMITTER_NAME} = eval {
 	use PublicInbox::MDA;
 	use PublicInbox::Address;
 	use Encode qw/encode/;
-	my $eml = 't/utf8.eml';
-	my $msg = PublicInbox::InboxWritable::mime_from_path($eml) or
-		die "failed to open $eml: $!";
+	my $msg = mime_load 't/utf8.eml';
 	my $from = $msg->header('From');
 	my ($author) = PublicInbox::Address::names($from);
 	my ($email) = PublicInbox::Address::emails($from);
diff --git a/t/msg_iter.t b/t/msg_iter.t
index 6adbf165..5c57e043 100644
--- a/t/msg_iter.t
+++ b/t/msg_iter.t
@@ -5,7 +5,6 @@ use warnings;
 use Test::More;
 use PublicInbox::TestCommon;
 use PublicInbox::Hval qw(ascii_html);
-use PublicInbox::InboxWritable;
 use_ok('PublicInbox::MsgIter');
 
 {
@@ -34,9 +33,7 @@ use_ok('PublicInbox::MsgIter');
 }
 
 {
-	my $f = 't/iso-2202-jp.eml';
-	my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
-		die "open $f: $!";
+	my $mime = mime_load 't/iso-2202-jp.eml';
 	my $raw = '';
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
@@ -49,9 +46,7 @@ use_ok('PublicInbox::MsgIter');
 }
 
 {
-	my $f = 't/x-unknown-alpine.eml';
-	my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
-		die "open $f: $!";
+	my $mime = mime_load 't/x-unknown-alpine.eml';
 	my $raw = '';
 	msg_iter($mime, sub {
 		my ($part, $level, @ex) = @{$_[0]};
diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t
index a0522e1f..0ad29be0 100644
--- a/t/nntpd-tls.t
+++ b/t/nntpd-tls.t
@@ -63,9 +63,7 @@ EOF
 
 {
 	my $im = $ibx->importer(0);
-	my $eml = 't/data/0001.patch';
-	my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or
-		die "open $eml: $!";
+	my $mime = mime_load 't/data/0001.patch';
 	ok($im->add($mime), 'message added');
 	$im->done;
 	if ($version == 1) {
diff --git a/t/search.t b/t/search.t
index 40264345..83986837 100644
--- a/t/search.t
+++ b/t/search.t
@@ -286,9 +286,7 @@ EOF
 });
 
 $ibx->with_umask(sub {
-	my $eml = 't/utf8.eml';
-	my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or
-		die "open $eml: $!";
+	my $mime = mime_load 't/utf8.eml';
 	my $doc_id = $rw->add_message($mime);
 	ok($doc_id > 0, 'message indexed doc_id with UTF-8');
 	my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0];
diff --git a/t/solver_git.t b/t/solver_git.t
index 7f79ff4c..c483aba1 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -29,9 +29,7 @@ my $im = PublicInbox::V2Writable->new($ibx, 1);
 $im->{parallel} = 0;
 
 my $deliver_patch = sub ($) {
-	my $mime = PublicInbox::InboxWritable::mime_from_path($_[0]) or
-		die "open $_[0]: $!";
-	$im->add($mime);
+	$im->add(mime_load($_[0]));
 	$im->done;
 };
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/3] testcommon: mime_load: drop extra $cb arg
  2020-04-25  5:52 [PATCH 0/3] remove Email::MIME->create use Eric Wong
                   ` (2 preceding siblings ...)
  2020-04-25  5:52 ` [PATCH 3/3] tests: replace mime_from_path with mime_load Eric Wong
@ 2020-04-26  7:35 ` Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-04-26  7:35 UTC (permalink / raw)
  To: meta

We don't need the callback arg, anymore.
---
 Just pushed this trivial fixup out

 lib/PublicInbox/TestCommon.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 27390ab2..cd73b5b6 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -12,7 +12,7 @@ our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
 	run_script start_script key2sub xsys xqx mime_load);
 
 sub mime_load ($) {
-	my ($path, $cb) = @_;
+	my ($path) = @_;
 	open(my $fh, '<', $path) or die "open $path: $!";
 	PublicInbox::MIME->new(\(do { local $/; <$fh> }));
 }

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-26  7:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-25  5:52 [PATCH 0/3] remove Email::MIME->create use Eric Wong
2020-04-25  5:52 ` [PATCH 1/3] testcommon: introduce mime_load sub Eric Wong
2020-04-25  5:52 ` [PATCH 2/3] tests: remove Email::MIME->create use entirely Eric Wong
2020-04-25  5:52 ` [PATCH 3/3] tests: replace mime_from_path with mime_load Eric Wong
2020-04-26  7:35 ` [PATCH 4/3] testcommon: mime_load: drop extra $cb arg Eric Wong

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).