From b18e37595e03d77a0d6059ab7b0c35ae03198365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C5=8Dan?= Date: Mon, 20 Apr 2026 05:21:22 -0600 Subject: [PATCH] feat: add stat_as_fifo helper for named pipe mocking Every file type with a -X check had a corresponding stat_as_* helper except FIFO (named pipe). This completes the helper family so users of mock_all_from_stat can create FIFO stat arrays as easily as directories, files, or sockets. Also fixes CLAUDE.md referencing a non-existent mock_lstat function. Co-Authored-By: Claude Opus 4.6 --- CLAUDE.md | 2 +- lib/Overload/FileCheck.pm | 15 ++++++++++++++- t/mock-all-from-stat_basic.t | 9 +++++++++ t/stat-helpers.t | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 7a81b91..e9a13da 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,7 +31,7 @@ Makefile.PL is auto-generated from dist.ini — edit dist.ini for build configur ### Two-layer design -**Perl layer** (`lib/Overload/FileCheck.pm`): Public API — `mock_file_check`, `mock_stat`, `mock_lstat`, `mock_all_file_checks`, `mock_all_from_stat`, and their `unmock_*` counterparts. Manages the mapping from operator names (e.g., '-e') to Perl OP types (e.g., `OP_FTIS`). Provides export groups `:check` (return value constants), `:stat` (stat index constants and helpers like `stat_as_file()`), and `:all`. +**Perl layer** (`lib/Overload/FileCheck.pm`): Public API — `mock_file_check`, `mock_stat`, `mock_all_file_checks`, `mock_all_from_stat`, and their `unmock_*` counterparts. `mock_stat` handles both stat and lstat (there is no separate `mock_lstat`). Manages the mapping from operator names (e.g., '-e') to Perl OP types (e.g., `OP_FTIS`). Provides export groups `:check` (return value constants), `:stat` (stat index constants and helpers like `stat_as_file()`), and `:all`. **XS layer** (`FileCheck.xs` + `FileCheck.h`): Replaces Perl's default `pp_*` OP handlers with custom ones that call back into Perl. Three handler types: `pp_overload_ft_yes_no` (boolean ops like -e, -f), `pp_overload_ft_int`/`pp_overload_ft_nv` (numeric ops like -s, -M), and `pp_overload_stat` (stat/lstat). `FileCheck.h` contains compatibility macros for Perl 5.14 vs 5.15+ internal API differences. diff --git a/lib/Overload/FileCheck.pm b/lib/Overload/FileCheck.pm index 9945a63..99be6ec 100644 --- a/lib/Overload/FileCheck.pm +++ b/lib/Overload/FileCheck.pm @@ -58,7 +58,7 @@ my @STAT_T_IX = qw{ my @CHECK_STATUS = qw{CHECK_IS_FALSE CHECK_IS_TRUE CHECK_IS_NULL FALLBACK_TO_REAL_OP}; my @STAT_HELPERS = qw{ stat_as_directory stat_as_file stat_as_symlink - stat_as_socket stat_as_chr stat_as_block}; + stat_as_socket stat_as_chr stat_as_block stat_as_fifo}; our @EXPORT_OK = ( qw{ @@ -600,6 +600,12 @@ sub stat_as_block { return _stat_for( S_IFBLK, \%opts ); } +sub stat_as_fifo { + my (%opts) = @_; + + return _stat_for( S_IFIFO, \%opts ); +} + sub _stat_for { my ( $type, $opts ) = @_; @@ -921,6 +927,8 @@ Available functions are: =item stat_as_block +=item stat_as_fifo + =back @@ -1048,6 +1056,11 @@ view stat_as_directory and L for some sample usages Create a stat array ref for an empty block device view stat_as_directory and L for some sample usages +=head2 stat_as_fifo( %OPTS ) + +Create a stat array ref for a named pipe (FIFO) +view stat_as_directory and L for some sample usages + =head1 Notice This is a very early development stage and some behavior might change before the release of a more stable build. diff --git a/t/mock-all-from-stat_basic.t b/t/mock-all-from-stat_basic.t index 18577a7..94f4d65 100644 --- a/t/mock-all-from-stat_basic.t +++ b/t/mock-all-from-stat_basic.t @@ -27,6 +27,7 @@ my $fake_files = { 'regular.file' => stat_as_file( size => 666 ), 'empty.file' => stat_as_file(), 'my.socket' => stat_as_socket(), + 'my.fifo' => stat_as_fifo(), }; # move to DATA @@ -134,6 +135,14 @@ __DATA__ -S 'my.socket' !-s 'my.socket' +# a FIFO (named pipe) +-e 'my.fifo' +!-d 'my.fifo' +!-f 'my.fifo' +-p 'my.fifo' +!-S 'my.fifo' +!-s 'my.fifo' + # a zero stat (stat succeeded with all-zero fields — file exists but has no type) -e 'zero' !-f 'zero' diff --git a/t/stat-helpers.t b/t/stat-helpers.t index b91bb1d..8bd4127 100644 --- a/t/stat-helpers.t +++ b/t/stat-helpers.t @@ -34,6 +34,7 @@ is stat_as_symlink(), [ 0, 0, S_IFLNK, (0) x 10 ], 'stat_as_symlink'; is stat_as_socket(), [ 0, 0, S_IFSOCK, (0) x 10 ], 'stat_as_socket'; is stat_as_chr(), [ 0, 0, S_IFCHR, (0) x 10 ], 'stat_as_chr'; is stat_as_block(), [ 0, 0, S_IFBLK, (0) x 10 ], 'stat_as_block'; +is stat_as_fifo(), [ 0, 0, S_IFIFO, (0) x 10 ], 'stat_as_fifo'; if ( $> == 0 ) { my ($username, $gid) = (getpwuid $>)[0, 3];