]> Sergey Matveev's repositories - public-inbox.git/commitdiff
tests: favor 3 argument `open' with interopolation
authorEric Wong <e@80x24.org>
Fri, 30 Sep 2022 09:21:37 +0000 (09:21 +0000)
committerEric Wong <e@80x24.org>
Fri, 30 Sep 2022 16:25:03 +0000 (16:25 +0000)
It makes code easier to review, and is more robust in case some
weirdos actually start their path names with '<' or '>' :P

t/hl_mod.t
t/lei-up.t
t/lei_to_mail.t

index a88f6c0372bd2d1fcbbc0cd5bba482b3c22b37c5..6ddbb7781cda0ea767e1860e798ccfb86433a704 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon; use IO::Handle; # ->autoflush
 use Fcntl qw(:seek);
@@ -11,7 +11,7 @@ is($hls->_shebang2lang(\"#!/usr/bin/perl -w\n"), 'perl', 'perl shebang OK');
 is($hls->{-ext2lang}->{'pm'}, 'perl', '.pm suffix OK');
 is($hls->{-ext2lang}->{'pl'}, 'perl', '.pl suffix OK');
 like($hls->_path2lang('Makefile'), qr/\Amake/, 'Makefile OK');
-my $str = do { local $/; open(my $fh, __FILE__); <$fh> };
+my $str = do { local $/; open(my $fh, '<', __FILE__); <$fh> };
 my $orig = $str;
 
 {
index fc3691562ceac95d0d478b09a5a43aaddf0d0458..022ebc0554abf0a51f8223eb60a05a74441149fb 100644 (file)
@@ -15,23 +15,23 @@ test_lei(sub {
        $s = eml_load('t/utf8.eml')->as_string;
        lei_ok [qw(import -q -F eml -)], undef, { 0 => \$s, %$lei_opt };
        lei_ok qw(up --all=local);
-       open my $fh, "$ENV{HOME}/a.mbox.gz" or xbail "open: $!";
+       open my $fh, '<', "$ENV{HOME}/a.mbox.gz" or xbail "open: $!";
        my $gz = do { local $/; <$fh> };
        my $uc;
        gunzip(\$gz => \$uc, MultiStream => 1) or xbail "gunzip $GunzipError";
-       open $fh, "$ENV{HOME}/a" or xbail "open: $!";
+       open $fh, '<', "$ENV{HOME}/a" or xbail "open: $!";
 
        my $exp = do { local $/; <$fh> };
        is($uc, $exp, 'compressed and uncompressed match (a.gz)');
        like($exp, qr/testmessage\@example.com/, '2nd message added');
-       open $fh, "$ENV{HOME}/b.mbox.gz" or xbail "open: $!";
+       open $fh, '<', "$ENV{HOME}/b.mbox.gz" or xbail "open: $!";
 
        $gz = do { local $/; <$fh> };
        undef $uc;
        gunzip(\$gz => \$uc, MultiStream => 1) or xbail "gunzip $GunzipError";
        is($uc, $exp, 'compressed and uncompressed match (b.gz)');
 
-       open $fh, "$ENV{HOME}/b" or xbail "open: $!";
+       open $fh, '<', "$ENV{HOME}/b" or xbail "open: $!";
        $uc = do { local $/; <$fh> };
        is($uc, $exp, 'uncompressed both match');
 
index e8958c64c46c73b6ae38feeef8718c2b7bd9e2f3..d692751c69acd4f8b2e5f8e7833e32a59978a436 100644 (file)
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
@@ -260,7 +260,7 @@ SKIP: { # FIFO support
 
        my @f;
        $mdr->maildir_each_file($md, sub { push @f, shift });
-       open my $fh, $f[0] or BAIL_OUT $!;
+       open my $fh, '<', $f[0] or BAIL_OUT $!;
        is(do { local $/; <$fh> }, $buf, 'wrote to Maildir');
 
        $wcb = $wcb_get->('maildir', $md);
@@ -271,7 +271,7 @@ SKIP: { # FIFO support
        $mdr->maildir_each_file($md, sub { push @x, shift });
        is(scalar(@x), 1, 'wrote one new file');
        ok(!-f $f[0], 'old file clobbered');
-       open $fh, $x[0] or BAIL_OUT $!;
+       open $fh, '<', $x[0] or BAIL_OUT $!;
        is(do { local $/; <$fh> }, $buf."\nx\n", 'wrote new file to Maildir');
 
        local $lei->{opt}->{augment} = 1;
@@ -283,9 +283,9 @@ SKIP: { # FIFO support
        is(scalar grep(/\A\Q$x[0]\E\z/, @f), 1, 'old file still there');
        my @new = grep(!/\A\Q$x[0]\E\z/, @f);
        is(scalar @new, 1, '1 new file written (b4dc0ffee skipped)');
-       open $fh, $x[0] or BAIL_OUT $!;
+       open $fh, '<', $x[0] or BAIL_OUT $!;
        is(do { local $/; <$fh> }, $buf."\nx\n", 'old file untouched');
-       open $fh, $new[0] or BAIL_OUT $!;
+       open $fh, '<', $new[0] or BAIL_OUT $!;
        is(do { local $/; <$fh> }, $buf."\ny\n", 'new file written');
 }