diff options
Diffstat (limited to 't/search.t')
-rw-r--r-- | t/search.t | 53 |
1 files changed, 31 insertions, 22 deletions
@@ -1,10 +1,10 @@ -# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org> +#!perl -w +# Copyright (C) all contributors <meta@public-inbox.org> # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> use strict; -use warnings; -use Test::More; +use v5.10; use PublicInbox::TestCommon; -require_mods(qw(DBD::SQLite Search::Xapian)); +require_mods(qw(DBD::SQLite Xapian)); require PublicInbox::SearchIdx; require PublicInbox::Inbox; require PublicInbox::InboxWritable; @@ -34,15 +34,11 @@ my $rw_commit = sub { $ibx->search->reopen; }; -sub oct_is ($$$) { - my ($got, $exp, $msg) = @_; - is(sprintf('0%03o', $got), sprintf('0%03o', $exp), $msg); -} - { # git repository perms + use_ok 'PublicInbox::Umask'; oct_is($ibx->_git_config_perm(), - &PublicInbox::InboxWritable::PERM_GROUP, + PublicInbox::Umask::PERM_GROUP(), 'undefined permission is group'); my @t = ( [ '0644', 0022, '644 => umask(0022)' ], @@ -54,8 +50,8 @@ sub oct_is ($$$) { ); for (@t) { my ($perm, $exp, $msg) = @$_; - my $got = PublicInbox::InboxWritable::_umask_for( - PublicInbox::InboxWritable->_git_config_perm($perm)); + my $got = PublicInbox::Umask::_umask_for( + PublicInbox::Umask->_git_config_perm($perm)); oct_is($got, $exp, $msg); } } @@ -436,9 +432,10 @@ $ibx->with_umask(sub { my $all_mask = 07777; my $dir_mask = 02770; -# FreeBSD and apparently OpenBSD does not allow non-root users to set S_ISGID, +# FreeBSD, OpenBSD and NetBSD do not allow non-root users to set S_ISGID, # so git doesn't set it, either (see DIR_HAS_BSD_GROUP_SEMANTICS in git.git) -if ($^O =~ /(?:free|open)bsd/i) { +# Presumably all *BSDs behave the same way. +if (require_bsd) { $all_mask = 0777; $dir_mask = 0770; } @@ -534,7 +531,15 @@ $ibx->with_umask(sub { '20200418222508.GA13918@dcvr', 'Subject search reaches inside message/rfc822'); - $doc_id = $rw->add_message(eml_load('t/data/binary.patch')); + my $eml = eml_load('t/data/binary.patch'); + my $body = $eml->body; + $rw->add_message($eml); + + $body =~ s/^/> /gsm; + $eml = PublicInbox::Eml->new($eml->header_obj->as_string."\n".$body); + $eml->header_set('Message-ID', '<binary-patch-reply@example>'); + $rw->add_message($eml); + $rw->commit_txn_lazy; $ibx->search->reopen; my $res = $query->('HcmV'); @@ -542,8 +547,9 @@ $ibx->with_umask(sub { $res = $query->('IcmZPo000310RR91'); is_deeply($res, [], 'no results against 1-byte binary patch'); $res = $query->('"GIT binary patch"'); - is(scalar(@$res), 1, 'got binary result from "GIT binary patch"'); + is(scalar(@$res), 2, 'got binary results from "GIT binary patch"'); is($res->[0]->{mid}, 'binary-patch-test@example', 'msgid for binary'); + is($res->[1]->{mid}, 'binary-patch-reply@example', 'msgid for reply'); my $s = $query->('"literal 1"'); is_deeply($s, $res, 'got binary result from exact literal size'); $s = $query->('"literal 2"'); @@ -565,10 +571,13 @@ SKIP: { skip 'too close to midnight, time is tricky', 6; } $q = $s->query_argv_to_string($g, [qw(d:20101002 blah)]); - is($q, 'd:20101002..20101003 blah', 'YYYYMMDD expanded to range'); + is($q, 'dt:20101002000000..20101003000000 blah', + 'YYYYMMDD expanded to range'); $q = $s->query_argv_to_string($g, [qw(d:2010-10-02)]); - is($q, 'd:20101002..20101003', 'YYYY-MM-DD expanded to range'); + is($q, 'dt:20101002000000..20101003000000', + 'YYYY-MM-DD expanded to range'); $q = $s->query_argv_to_string($g, [qw(rt:2010-10-02.. yy)]); + diag "q=$q"; $q =~ /\Art:(\d+)\.\. yy/ or fail("rt: expansion failed: $q"); is(strftime('%Y-%m-%d', gmtime($1//0)), '2010-10-02', 'rt: beg expand'); $q = $s->query_argv_to_string($g, [qw(rt:..2010-10-02 zz)]); @@ -615,7 +624,7 @@ SKIP: { $orig = $qs = qq[f:bob "hello world" d:1993-10-02..2010-10-02]; $s->query_approxidate($g, $qs); - is($qs, qq[f:bob "hello world" d:19931002..20101002], + is($qs, qq[f:bob "hello world" dt:19931002000000..20101002000000], 'post-phrase date corrected'); # Xapian uses "" to escape " inside phrases, we don't explictly @@ -627,7 +636,7 @@ SKIP: { is($qs, $orig, 'phrases unchanged \x'.ord($x).'-\x'.ord($y)); $s->query_approxidate($g, my $tmp = "$qs d:..2010-10-02"); - is($tmp, "$orig d:..20101002", + is($tmp, "$orig dt:..20101002000000", 'two phrases did not throw off date parsing'); $orig = $qs = qq[${x}hello d:1993-10-02..$y$x world$y]; @@ -635,7 +644,7 @@ SKIP: { is($qs, $orig, 'phrases unchanged \x'.ord($x).'-\x'.ord($y)); $s->query_approxidate($g, $tmp = "$qs d:..2010-10-02"); - is($tmp, "$orig d:..20101002", + is($tmp, "$orig dt:..20101002000000", 'two phrases did not throw off date parsing'); } @@ -654,7 +663,7 @@ SKIP: { skip 'TEST_EXPENSIVE not set for argv overflow check', 1; my @w; local $SIG{__WARN__} = sub { push @w, @_ }; # for pure Perl version - my @fail = map { 'd:1993-10-02..2010-10-02' } (1..(4096 * 32)); + my @fail = map { 'dt:1993-10-02..2010-10-02' } (1..(4096 * 32)); eval { $s->query_argv_to_string($g, \@fail) }; ok($@, 'exception raised'); } |