X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fthread-cycle.t;h=1e5dfb51ab47a2865f9ab7835eda154291a5e65e;hb=9174f534ccc51054895bdb198c8bc1a765abd9e9;hp=78dcb6f9db14892495b661e93b0670accb7c44f9;hpb=c204da04aa24e85236f82ba5a7c6c7e19c8a20d3;p=public-inbox.git
diff --git a/t/thread-cycle.t b/t/thread-cycle.t
index 78dcb6f9..1e5dfb51 100644
--- a/t/thread-cycle.t
+++ b/t/thread-cycle.t
@@ -1,35 +1,36 @@
-# Copyright (C) 2016-2018 all contributors
+# Copyright (C) 2016-2021 all contributors
# License: AGPL-3.0+
-use strict;
-use warnings;
-use Test::More;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
use_ok('PublicInbox::SearchThread');
-use Email::Simple;
my $mt = eval {
require Mail::Thread;
no warnings 'once';
$Mail::Thread::nosubject = 1;
$Mail::Thread::noprune = 1;
+ require Email::Simple; # required by Mail::Thread (via Email::Abstract)
};
-sub make_objs {
+my $make_objs = sub {
my @simples;
my $n = 0;
my @msgs = map {
my $msg = $_;
$msg->{ds} ||= ++$n;
$msg->{references} =~ s/\s+/ /sg if $msg->{references};
- my $simple = Email::Simple->create(header => [
- 'Message-ID' => "<$msg->{mid}>",
- 'References' => $msg->{references},
- ]);
- push @simples, $simple;
- bless $msg, 'PublicInbox::SearchMsg'
+ $msg->{blob} = '0'x40; # any dummy value will do, here
+ if ($mt) {
+ my $simple = Email::Simple->create(header => [
+ 'Message-ID' => "<$msg->{mid}>",
+ 'References' => $msg->{references},
+ ]);
+ push @simples, $simple;
+ }
+ bless $msg, 'PublicInbox::Smsg'
} @_;
(\@simples, \@msgs);
-}
+};
-my ($simples, $smsgs) = make_objs(
+my ($simples, $smsgs) = $make_objs->(
# data from t/testbox-6 in Mail::Thread 2.55:
{ mid => '20021124145312.GA1759@nlin.net' },
{ mid => 'slrnau448m.7l4.markj+0111@cloaked.freeserve.co.uk',
@@ -77,13 +78,13 @@ my @backwards = (
{ mid => 8, references => '' }
);
-($simples, $smsgs) = make_objs(@backwards);
+($simples, $smsgs) = $make_objs->(@backwards);
my $backward = thread_to_s($smsgs);
SKIP: {
skip 'Mail::Thread missing', 1 unless $mt;
check_mt($backward, $simples, 'matches Mail::Thread backwards');
}
-($simples, $smsgs) = make_objs(reverse @backwards);
+($simples, $smsgs) = $make_objs->(reverse @backwards);
my $forward = thread_to_s($smsgs);
unless ('Mail::Thread sorts by Date') {
SKIP: {
@@ -95,18 +96,37 @@ if ('sorting by Date') {
is("\n".$backward, "\n".$forward, 'forward and backward matches');
}
-done_testing();
+SKIP: {
+ require_mods 'Devel::Cycle', 1;
+ Devel::Cycle->import('find_cycle');
+ my @dup = (
+ { mid => 5, references => '<6>' },
+ { mid => 5, references => '<6> <1>' },
+ );
+ open my $fh, '+>', \(my $out = '') or xbail "open: $!";
+ (undef, $smsgs) = $make_objs->(@dup);
+ eval 'package EmptyInbox; sub smsg_by_mid { undef }';
+ my $ctx = { ibx => bless {}, 'EmptyInbox' };
+ my $rootset = PublicInbox::SearchThread::thread($smsgs, sub {
+ @{$_[0]} = sort { $a->{mid} cmp $b->{mid} } @{$_[0]} }, $ctx);
+ my $oldout = select $fh;
+ find_cycle($rootset);
+ select $oldout;
+ is($out, '', 'nothing from find_cycle');
+} # Devel::Cycle check
+
+done_testing;
sub thread_to_s {
my ($msgs) = @_;
my $rootset = PublicInbox::SearchThread::thread($msgs, sub {
- [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] });
+ @{$_[0]} = sort { $a->{mid} cmp $b->{mid} } @{$_[0]} });
my $st = '';
my @q = map { (0, $_) } @$rootset;
while (@q) {
my $level = shift @q;
my $node = shift @q or next;
- $st .= (" "x$level). "$node->{id}\n";
+ $st .= (" "x$level). "$node->{mid}\n";
my $cl = $level + 1;
unshift @q, map { ($cl, $_) } @{$node->{children}};
}