Skip to content

test: add Expat.pm input validation and state guard tests#266

Merged
toddr merged 1 commit into
mainfrom
koan.toddr.bot/test-expat-guards
Apr 23, 2026
Merged

test: add Expat.pm input validation and state guard tests#266
toddr merged 1 commit into
mainfrom
koan.toddr.bot/test-expat-guards

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

What

Add 22 tests covering previously untested defensive code paths in Expat.pm.

Why

Several core validation and state management paths had zero test coverage:

  • setHandlers() input validation (non-CODE ref rejection, odd argument count, unknown types)
  • Parse state guards (_State_ checks preventing concurrent/reuse scenarios)
  • Reference exception preservation through the parse error handling path
  • State-dependent method behavior outside active parsing

How

New test file t/expat_guards.t exercises each path directly:

  • Tests 1-9: setHandlers validation — rejects strings, hashrefs, arrayrefs, numbers, scalar refs; accepts undef/0; detects odd args and unknown types
  • Tests 10-12: Parse state guards — concurrent parse, reuse via parse(), reuse via parsefile()
  • Tests 13-16: Reference exceptions — blessed object dies propagate correctly, with and without ErrorContext
  • Tests 17-22: State methods return false outside parse context

Testing

Full test suite passes: 700 tests across 60 files.

🤖 Generated with Claude Code

Cover previously untested defensive code paths:
- setHandlers rejects non-CODE references (string, hash, array, number)
- setHandlers accepts undef/0 to clear handlers
- Odd argument count and unknown handler type detection
- "Parse already in progress" guard against concurrent parse
- "Parser has already been used" guard against Expat reuse
- Reference exceptions (blessed objects) preserved through parse
- Reference exceptions preserved even with ErrorContext set
- State-dependent methods return false outside active parse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.73%. Comparing base (45216a7) to head (6e7eba8).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #266   +/-   ##
=======================================
  Coverage   75.73%   75.73%           
=======================================
  Files           1        1           
  Lines        1092     1092           
  Branches      342      342           
=======================================
  Hits          827      827           
  Misses         59       59           
  Partials      206      206           
Flag Coverage Δ
perl 75.73% <ø> (ø)
xs 75.73% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@toddr toddr marked this pull request as ready for review April 23, 2026 10:04
@toddr toddr merged commit 74e698a into main Apr 23, 2026
36 checks passed
@toddr toddr deleted the koan.toddr.bot/test-expat-guards branch April 23, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants