Replace (stat(<file>))[7] in TAP tests with -s

Started by Bertrand Drouvotover 2 years ago3 messageshackers
Jump to latest
#1Bertrand Drouvot
bertranddrouvot.pg@gmail.com

Hi hackers,

Please find attached a tiny patch to $SUBJECT.

It:

- provides more consistency to the way we get files size in TAP tests
- seems more elegant that relying on a hardcoded result position

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachments:

v1-0001-Be-consistent-in-TAP-tests-for-the-way-we-get-fil.patchtext/plain; charset=UTF-8; name=v1-0001-Be-consistent-in-TAP-tests-for-the-way-we-get-fil.patchDownload+5-14
In reply to: Bertrand Drouvot (#1)
Re: Replace (stat(<file>))[7] in TAP tests with -s

"Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com> writes:

Hi hackers,

Please find attached a tiny patch to $SUBJECT.

It:

- provides more consistency to the way we get files size in TAP tests
- seems more elegant that relying on a hardcoded result position

I approve of removing use of the list form of stat, it's a horrible API.

If we weren't already using -s everywhere else, I would prefer
File::stat, which makes stat (in scalar context) return an object with
methods for the fields, so you'd do stat($file)->size. It's included in
Perl core since 5.4, and we're already using it in several places for
other fields (mode and ino at least).

I see another use of stat array positions (for mtime) in
src/tools/msvc/Solution.pm, but that's on the chopping block, so not
much point in fixing.

- ilmari

#3Michael Paquier
michael@paquier.xyz
In reply to: Dagfinn Ilmari Mannsåker (#2)
Re: Replace (stat(<file>))[7] in TAP tests with -s

On Mon, Oct 02, 2023 at 12:44:59PM +0100, Dagfinn Ilmari Mannsåker wrote:

I approve of removing use of the list form of stat, it's a horrible API.

Agreed, I've appied the suggestion to use -s, like we do anywhere
else.

If we weren't already using -s everywhere else, I would prefer
File::stat, which makes stat (in scalar context) return an object with
methods for the fields, so you'd do stat($file)->size. It's included in
Perl core since 5.4, and we're already using it in several places for
other fields (mode and ino at least).

Right, like in 017_shm.pl. I didn't notice that.

I see another use of stat array positions (for mtime) in
src/tools/msvc/Solution.pm, but that's on the chopping block, so not
much point in fixing.

The removal of this code depends on a few more things, hopefully it
will be able to get rid of it during this release cycle.
--
Michael