about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-05-06 02:22:39 +0000
committerEric Wong <e@80x24.org>2021-05-06 16:56:43 +0000
commit473b069c61b3d4936e2c5ed46fd7d348c9f6d1b7 (patch)
tree221ef389b49059d4f82e5257fb4acf38dd397097 /t
parentaa6ad348fea8a7affb1ecf025c297983d0e061cd (diff)
downloadpublic-inbox-473b069c61b3d4936e2c5ed46fd7d348c9f6d1b7.tar.gz
We use trailing slashes internally, but should not increase
visual noise for users by exposing them in config files or
DB storage (and shell completion/listings).

This fixes a long-standing bug in $lei->rel2abs that prevented
absolute paths from being canonicalized.
Diffstat (limited to 't')
-rw-r--r--t/lei-import-maildir.t5
-rw-r--r--t/lei-q-save.t9
-rw-r--r--t/lei_mail_sync.t12
3 files changed, 22 insertions, 4 deletions
diff --git a/t/lei-import-maildir.t b/t/lei-import-maildir.t
index b85d3026..f813440a 100644
--- a/t/lei-import-maildir.t
+++ b/t/lei-import-maildir.t
@@ -10,12 +10,15 @@ test_lei(sub {
         }
         symlink(abs_path('t/data/0001.patch'), "$md/cur/x:2,S") or
                 BAIL_OUT "symlink $md $!";
-        lei_ok(qw(import), $md, \'import Maildir');
+        lei_ok(qw(import), "$md/", \'import Maildir');
         my $imp_err = $lei_err;
 
         my %i;
         lei_ok('inspect', $md); $i{no_type} = $lei_out;
+        lei_ok('inspect', "$md/"); $i{no_type_tslash} = $lei_out;
         lei_ok('inspect', "maildir:$md"), $i{with_type} = $lei_out;
+        lei_ok('inspect', "maildir:$md/"), $i{with_type_tslash} = $lei_out;
+        lei_ok('inspect', "MAILDIR:$md"), $i{ALLCAPS} = $lei_out;
         lei_ok(['inspect', $md], undef, { -C => $ENV{HOME}, %$lei_opt });
         $i{rel_no_type} = $lei_out;
         lei_ok(['inspect', "maildir:$md"], undef,
diff --git a/t/lei-q-save.t b/t/lei-q-save.t
index 9f65e4a2..753d5b20 100644
--- a/t/lei-q-save.t
+++ b/t/lei-q-save.t
@@ -23,13 +23,16 @@ test_lei(sub {
         my $home = $ENV{HOME};
         my $in = $doc1->as_string;
         lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
-        lei_ok qw(q -q --save z:0.. d:last.week..), '-o', "$home/md/";
+        lei_ok qw(q -q --save z:0.. d:last.week..), '-o', "MAILDIR:$home/md/";
         my %before = map { $_ => 1 } glob("$home/md/cur/*");
         is_deeply(eml_load((keys %before)[0]), $doc1, 'doc1 matches');
+        lei_ok qw(ls-mail-sync);
+        is($lei_out, "maildir:$home/md\n", 'canonicalized mail sync name');
 
         my @s = glob("$home/.local/share/lei/saved-searches/md-*");
         is(scalar(@s), 1, 'got one saved search');
         my $cfg = PublicInbox::Config->new("$s[0]/lei.saved-search");
+        is($cfg->{'lei.q.output'}, "maildir:$home/md", 'canonicalized output');
         is_deeply($cfg->{'lei.q'}, ['z:0..', 'd:last.week..'],
                 'store relative time, not parsed (absolute) timestamp');
 
@@ -66,14 +69,14 @@ test_lei(sub {
         lei_ok qw(ls-search); my @d = split(/\n/, $lei_out);
         lei_ok qw(ls-search -z); my @z = split(/\0/, $lei_out);
         is_deeply(\@d, \@z, '-z output matches non-z');
-        is_deeply(\@d, [ "$home/mbcl2", "$home/md/" ],
+        is_deeply(\@d, [ "$home/mbcl2", "$home/md" ],
                 'ls-search output alphabetically sorted');
         lei_ok qw(ls-search -l);
         my $json = PublicInbox::Config->json->decode($lei_out);
         ok($json && $json->[0]->{output}, 'JSON has output');
         lei_ok qw(_complete lei up);
         like($lei_out, qr!^\Q$home/mbcl2\E$!sm, 'complete got mbcl2 output');
-        like($lei_out, qr!^\Q$home/md/\E$!sm, 'complete got maildir output');
+        like($lei_out, qr!^\Q$home/md\E$!sm, 'complete got maildir output');
 
         unlink("$home/mbcl2") or xbail "unlink $!";
         lei_ok qw(_complete lei up);
diff --git a/t/lei_mail_sync.t b/t/lei_mail_sync.t
index 864d6e48..f0605092 100644
--- a/t/lei_mail_sync.t
+++ b/t/lei_mail_sync.t
@@ -37,6 +37,18 @@ is_deeply($ro->locations_for('deadbeef'),
         { $imap => [ 1 ], $maildir => [ $fname ] },
         'locations_for w/ maildir + imap');
 
+if ('mess things up pretend old bug') {
+        $lms->lms_begin;
+        $lms->{dbh}->do('UPDATE folders SET loc = ? WHERE loc = ?', undef,
+                        "$maildir/", $maildir);
+        ok(delete $lms->{fmap}, 'clear folder map');
+        $lms->lms_commit;
+
+        $lms->lms_begin;
+        ok($lms->set_src('deadbeef', $maildir, \$fname), 'set Maildir once');
+        $lms->lms_commit;
+};
+
 is_deeply([sort($ro->folders)], [$imap, $maildir], 'both folders shown');
 my @res;
 $ro->each_src($maildir, sub {