]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
t/imap_searchqp: hopefully fix test reliability
authorEric Wong <e@80x24.org>
Sun, 28 Apr 2024 20:08:01 +0000 (20:08 +0000)
committerEric Wong <e@80x24.org>
Mon, 29 Apr 2024 17:10:01 +0000 (17:10 +0000)
Localizing assignments to *STDERR doesn't seem to always work
with scalar (String) IO objects.  Fortunately, doing actual dup2
redirects always seems reliable, so do that instead of
attempting to understand why PerlIO sometimes fails with the
assignment.

t/imap_searchqp.t

index ff1b4535058b6a371fb798ce18b64f6fe98fb7e0..d7840dd0c02d29b32fb795650d87fb07c0fd3481 100644 (file)
@@ -3,6 +3,8 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
+use autodie qw(open seek read);
+use Fcntl qw(SEEK_SET);
 use Time::Local qw(timegm);
 use PublicInbox::TestCommon;
 require_mods(qw(-imapd));
@@ -29,12 +31,15 @@ is($q->{xap}, 'f:"b"', 'charset handled');
 $q = $parse->(qq{CHARSET WTF-8 From b});
 like($q, qr/\ANO \[/, 'bad charset rejected');
 
-for my $x ('', ' (try #2)') {
-       open my $fh, '>:scalar', \(my $buf = '') or die;
-       local *STDERR = $fh;
+{
+       open my $tmperr, '+>', undef;
+       open my $olderr, '>&', \*STDERR;
+       open STDERR, '>&', $tmperr;
        $q = $parse->(qq{CHARSET});
-       last if is($buf, '', "nothing spewed to STDERR on bad query$x");
-       diag 'FIXME: above fails mysteriously sometimes, so we try again...';
+       open STDERR, '>&', $olderr;
+       seek $tmperr, 0, SEEK_SET;
+       read($tmperr, my $buf, -s $tmperr);
+       is($buf, '', 'nothing spewed to STDERR on bad query');
 }
 
 like($q, qr/\ABAD /, 'bad charset rejected');