Re: [PATCH v2 5/9] chainlint.pl: check line numbers in expected output
- From
Jeff King <peff@peff.net>
- Date
- Aug 21, 2024, 12:14 UTC
- Message-ID
- <20240821121454.GA498761@coredump.intra.peff.net>
- In-Reply-To
- <CAPig+cTACjostXvjJMnLEpgbnfat9cjM63pLXwNJm1=2P3gq8g@mail.gmail.com>
On Wed, Aug 21, 2024 at 03:00:05AM -0400, Eric Sunshine wrote:
Show 23 quoted lines
> > +for my $script (@ARGV) {
> > + print $expect "# chainlint: $script\n";
> > +
> > + open(my $expect_in, '<', "chainlint/$script.expect")
> > + or die "unable to open chainlint/$script.expect: $!";
> > + while (<$expect_in>) {
> > + s/^\d+/$& + $offset/e;
> > + print $expect $_;
> > + }
> > +
> > + open(my $test_in, '<', "chainlint/$script.test")
> > + or die "unable to open chainlint/$script.test: $!";
> > + while (<$test_in>) {
> > + /^# LINT: / and next;
> > + print $tests $_;
> > + $offset++;
> > + }
> > +}
>
> I'm surprised that we're not closing the two file handles opened on
> each iteration of this loop. Is that intentional? Or am I forgetting
> my Perl and they are somehow getting closed anyhow (for instance, by
> the <...> operator hitting EOF)?They're scoped to the loop with "my", so they'll both be closed for each iteration of the outer loop when the handles go out of scope.
You can verify with something like:
touch foo bar baz
strace -e openat,write,close \
perl -e '
for my $script (@ARGV) {
syswrite(STDOUT, "opening $script");
open(my $in, "<", $script);
syswrite(STDOUT, "finished $script");
}
' foo bar baz >/dev/nullwhich should show:
write(1, "opening foo", 11) = 11 openat(AT_FDCWD, "foo", O_RDONLY|O_CLOEXEC) = 3 write(1, "finished foo", 12) = 12 close(3) = 0 write(1, "opening bar", 11) = 11 [...etc...]
-Peff