]> Sergey Matveev's repositories - public-inbox.git/blob - t/reindex-time-range.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / reindex-time-range.t
1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict; use v5.10.1; use PublicInbox::TestCommon;
4 require_mods qw(DBD::SQLite);
5 my $tmp = tmpdir();
6 my $eml;
7 my $cb = sub {
8         my ($im, $ibx) = @_;
9         $eml //= eml_load 't/utf8.eml';
10         for my $i (1..3) {
11                 $eml->header_set('Message-ID', "<$i\@example.com>");
12                 my $d = "Thu, 01 Jan 1970 0$i:30:00 +0000";
13                 $eml->header_set('Date', $d);
14                 $im->add($eml);
15         }
16 };
17 my %ibx = map {;
18         "v$_" => create_inbox("v$_", version => $_,
19                         indexlevel => 'basic', tmpdir => "$tmp/v$_", $cb);
20 } (1, 2);
21
22 my $env = { TZ => 'UTC' };
23 my ($out, $err);
24 for my $v (sort keys %ibx) {
25         my $opt = { -C => $ibx{$v}->{inboxdir}, 1 => \$out, 2 => \$err };
26
27         ($out, $err) = ('', '');
28         run_script([ qw(-index -vv) ], $env, $opt);
29         is($?, 0, 'no error on initial index');
30
31         for my $x (qw(until before)) {
32                 ($out, $err) = ('', '');
33                 run_script([ qw(-index --reindex -vv),
34                                 "--$x=1970-01-01T02:00:00Z" ], $env, $opt);
35                 is($?, 0, "no error with --$x");
36                 like($err, qr! 1/1\b!, "$x only indexed one message");
37         }
38         for my $x (qw(after since)) {
39                 ($out, $err) = ('', '');
40                 run_script([ qw(-index --reindex -vv),
41                                 "--$x=1970-01-01T02:00:00Z" ], $env, $opt);
42                 is($?, 0, "no error with --$x");
43                 like($err, qr! 2/2\b!, "$x only indexed one message");
44         }
45
46         ($out, $err) = ('', '');
47         run_script([ qw(-index --reindex -vv) ], $env, $opt);
48         is($?, 0, 'no error on initial index');
49
50         for my $x (qw(since before after until)) {
51                 ($out, $err) = ('', '');
52                 run_script([ qw(-index -v), "--$x=1970-01-01T02:00:00Z" ],
53                         $env, $opt);
54                 isnt($?, 0, "--$x fails on --reindex");
55         }
56 }
57
58 done_testing;