fix: accept bare (non-st_) keys in hash stat mocks#70
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: accept bare (non-st_) keys in hash stat mocks#70Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
`_normalize_stat_result` previously required `st_`-prefixed keys
when a mock returned a HASH ref (e.g. `{ st_size => 100 }`), while
the `stat_as_*` helpers via `_stat_for` already accepted bare keys
like `size`. A user writing `{ size => 100, mode => 0100644 }` got a
fatal "Unknown index for stat_t struct key size" with no hint about
the `st_` requirement.
Apply the same normalization that `_stat_for` uses: lowercase the
key and strip a leading `st_` prefix before the map lookup, then
re-add `st_` when querying `%MAP_STAT_T_IX`. This makes the two
code paths consistent and accepts both `dev` and `st_dev` (and
mixed hashes) transparently.
Adds t/mock-stat-hash-bare-keys.t with six cases covering: single
bare key, multiple bare keys, mixed prefixed/bare keys, existing
`st_`-prefixed keys (regression), and uppercase variants of both
forms.
Fixes cpan-authors#63
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_normalize_stat_result(used when a stat mock returns a HASH ref) only acceptedst_-prefixed keys, while thestat_as_*helpers already accepted bare keys likesizeormode. This caused a fatal error for any user who modelled their mock hash on the helper API. The fix applies the same key normalization (lc+ stripst_prefix) that_stat_foruses, making both code paths consistent.Fixes #63
Changes
lib/Overload/FileCheck.pm: normalize hash keys in_normalize_stat_result— lowercase and strip leadingst_before lookup, so bothdevandst_dev(and uppercase variants) are acceptedt/mock-stat-hash-bare-keys.t: new regression test with six cases (single bare key, multiple bare keys, mixed prefixed/bare, existingst_-prefix regression, uppercase variants of both forms)Test plan
prove -lv t/mock-stat-hash-bare-keys.t— all 6 tests passprove -l t/— all pre-existing tests unchanged; only pre-existingmock-stat.tfailure (unrelated string-coercion issue) remainsGenerated by Kōan /fix
Quality Report
Changes: 2 files changed, 96 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (0 Tests)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline