From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 80E691F4B8 for ; Sun, 28 Apr 2024 20:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1714335332; bh=1rZelMe5DSdFLEhmcetNAaORr7OJIWa+ksQO7080wQE=; h=From:To:Subject:Date:From; b=1tpSg0M91yZQ7gTY20TOSSYF3VUCWFHPxTrKlub4uUw7uSbqNpyJ3mkAoi3aWnyCW xm83SrKy+309OMnqohNVJtD1/VlbJVSVPbtAfHdjsusz0sia04rD5Zu5NNc5gBJKUZ F7QCCg0mcOqPCoCD6TWUQ+wPVk/EScErdtx5Qjkg= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] t/imap_searchqp: hopefully fix test reliability Date: Sun, 28 Apr 2024 20:08:01 +0000 Message-ID: <20240428200801.42738-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/t/imap_searchqp.t b/t/imap_searchqp.t index ff1b4535..d7840dd0 100644 --- a/t/imap_searchqp.t +++ b/t/imap_searchqp.t @@ -3,6 +3,8 @@ # License: AGPL-3.0+ 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');