]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
test_common: extract oct_is from search.t
authorEric Wong <e@80x24.org>
Wed, 13 Dec 2023 00:50:15 +0000 (00:50 +0000)
committerEric Wong <e@80x24.org>
Wed, 13 Dec 2023 09:01:52 +0000 (09:01 +0000)
And use it in convert-compact.t  This gives us nicer errors for
debugging a problem I noticed on Alpine Linux (tested 3.19.0)

lib/PublicInbox/TestCommon.pm
t/convert-compact.t
t/search.t

index 9c413f43f5c7b4c41861c0139ed47404ba51c7c5..22c506752df167989ef20daaecb01ec832a18ef7 100644 (file)
@@ -29,7 +29,7 @@ BEGIN {
                tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
                test_httpd xbail require_cmd is_xdeeply tail_f
                ignore_inline_c_missing no_pollerfd no_coredump cfg_new
-               strace strace_inject lsof_pid);
+               strace strace_inject lsof_pid oct_is);
        require Test::More;
        my @methods = grep(!/\W/, @Test::More::EXPORT);
        eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
@@ -1033,6 +1033,12 @@ sub strace_inject (;$) {
        $cmd
 }
 
+sub oct_is ($$$) {
+       my ($got, $exp, $msg) = @_;
+       @_ = (sprintf('0%03o', $got), sprintf('0%03o', $exp), $msg);
+       goto &is; # tail recursion to get lineno from callers on failure
+}
+
 package PublicInbox::TestCommon::InboxWakeup;
 use strict;
 sub on_inbox_unlock { ${$_[0]}->($_[1]) }
index 1ac3517df2d242131e8e0e7be096a32f90f9baea..c7b7f77e2524b8571bd075729bc10dd1046bfaa7 100644 (file)
@@ -35,14 +35,14 @@ EOF
        $im->add($eml) or BAIL_OUT '->add';
 };
 umask(077) or BAIL_OUT "umask: $!";
-is(((stat("$ibx->{inboxdir}/public-inbox"))[2]) & 07777, 0755,
+oct_is(((stat("$ibx->{inboxdir}/public-inbox"))[2]) & 07777, 0755,
        'sharedRepository respected for v1');
-is(((stat("$ibx->{inboxdir}/public-inbox/msgmap.sqlite3"))[2]) & 07777, 0644,
-       'sharedRepository respected for v1 msgmap');
+oct_is(((stat("$ibx->{inboxdir}/public-inbox/msgmap.sqlite3"))[2]) & 07777,
+       0644, 'sharedRepository respected for v1 msgmap');
 my @xdir = glob("$ibx->{inboxdir}/public-inbox/xap*/*");
 foreach (@xdir) {
        my @st = stat($_);
-       is($st[2] & 07777, -f _ ? 0644 : 0755,
+       oct_is($st[2] & 07777, -f _ ? 0644 : 0755,
                'sharedRepository respected on file after convert');
 }
 
@@ -55,7 +55,7 @@ ok(run_script($cmd, undef, $rdr), 'v1 compact works');
 
 @xdir = glob("$ibx->{inboxdir}/public-inbox/xap*");
 is(scalar(@xdir), 1, 'got one xapian directory after compact');
-is(((stat($xdir[0]))[2]) & 07777, 0755,
+oct_is(((stat($xdir[0]))[2]) & 07777, 0755,
        'sharedRepository respected on v1 compact');
 
 my $hwm = do {
@@ -73,7 +73,7 @@ ok(run_script($cmd, undef, $rdr), 'convert works');
 @xdir = glob("$tmpdir/x/v2/xap*/*");
 foreach (@xdir) {
        my @st = stat($_);
-       is($st[2] & 07777, -f _ ? 0644 : 0755,
+       oct_is($st[2] & 07777, -f _ ? 0644 : 0755,
                'sharedRepository respected after convert');
 }
 
@@ -87,17 +87,17 @@ is($ibx->mm->num_highwater, $hwm, 'highwater mark unchanged in v2 inbox');
 @xdir = glob("$tmpdir/x/v2/xap*/*");
 foreach (@xdir) {
        my @st = stat($_);
-       is($st[2] & 07777, -f _ ? 0644 : 0755,
+       oct_is($st[2] & 07777, -f _ ? 0644 : 0755,
                'sharedRepository respected after v2 compact');
 }
-is(((stat("$tmpdir/x/v2/msgmap.sqlite3"))[2]) & 07777, 0644,
+oct_is(((stat("$tmpdir/x/v2/msgmap.sqlite3"))[2]) & 07777, 0644,
        'sharedRepository respected for v2 msgmap');
 
 @xdir = (glob("$tmpdir/x/v2/git/*.git/objects/*/*"),
         glob("$tmpdir/x/v2/git/*.git/objects/pack/*"));
 foreach (@xdir) {
        my @st = stat($_);
-       is($st[2] & 07777, -f _ ? 0444 : 0755,
+       oct_is($st[2] & 07777, -f _ ? 0444 : 0755,
                'sharedRepository respected after v2 compact');
 }
 my $msgs = $ibx->over->recent({limit => 1000});
index 282ae5868d25c917f3d6974633557d0e66638e84..9fda66944d9ddec757a4abc49d5994213b16c08a 100644 (file)
@@ -34,11 +34,6 @@ 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';