Skip to content

fix: fix IO::Util test failures - select() with tied handles, syswrite, and more#507

Merged
fglock merged 1 commit intomasterfrom
fix/io-util-test-failures
Apr 14, 2026
Merged

fix: fix IO::Util test failures - select() with tied handles, syswrite, and more#507
fglock merged 1 commit intomasterfrom
fix/io-util-test-failures

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 13, 2026

Summary

Fix 6 bugs causing IO::Util CPAN module test failures. Results improved from 5/9 test files failing to only 1/9 (the remaining test_pod.t fails due to POD encoding, not our code).

Bugs Fixed

  • select() returns wrong value for tied handles: select() was returning "TIED_HANDLE(test_tie)" instead of "main::STDOUT" when STDOUT was tied. This broke IO::Util::capture which relies on select() to get the current handle name and uses *{$name} to tie/untie it. Fixed by propagating globName from the previous IO handle to the TieHandle, and updating TieHandle.toString() to return globName when available.

  • qr/./=> token splitting: Lexer greedily tokenized /= from qr/./=> as divide-assign. After regex parser consumed /, the remaining = wasn't merged with next > to form => fat comma. Added merge logic in StringParser.java.

  • 1-argument open not implemented: open HANDLE (1-arg form) was throwing PerlJavaUnimplementedException. Implemented by reading filename from $_.

  • syswrite on tied handles: TieHandle check was after ClosedIOHandle check; since TieHandle's ioHandle is always ClosedIOHandle, tied handles were caught early and returned undef. Moved TieHandle check before closed-handle check.

  • gethostbyname aliases field flattening: Empty RuntimeArray for aliases field was flattening to zero elements in list context, shifting subsequent fields. Changed to empty string scalar in all 8 network functions.

  • sprintf zero-pad flag for missing args: %03d with missing argument produced " 0" instead of "000". Added check for 0 flag to choose pad character.

Files Changed

  • TieOperators.java - propagate globName to TieHandle
  • TieHandle.java - use globName in toString()
  • StringParser.java - qr//=> token merge
  • IOOperator.java - 1-arg open, syswrite tie order
  • ExtendedNativeUtils.java - network aliases flattening
  • SprintfOperator.java - sprintf zero-pad
  • RuntimeScalar.java - globDeref RuntimeIO lookup

Test plan

  • make passes (all unit tests)
  • IO::Util 01_capture.t passes 10/10 tests (was 7/10)
  • IO::Util full suite: 8/9 files pass, 99/100 tests pass
  • tie_handle.t unit test passes

Generated with Devin

…e, and more

Fix 6 bugs causing IO::Util CPAN module test failures (improved from
5/9 failing to 1/9, with only test_pod.t remaining due to POD encoding):

- Propagate globName to TieHandle so select() returns "main::STDOUT"
  instead of "TIED_HANDLE(class)" when the handle is tied. This fixes
  IO::Util::capture's syswrite test which relies on select() returning
  the correct glob name for tie/untie round-trips.

- Fix qr/./=> token splitting: after regex parser consumes /, merge
  remaining = with next > to form => fat comma operator.

- Implement 1-argument open (open HANDLE) by reading filename from $_.

- Fix syswrite on tied handles: move TieHandle check before
  ClosedIOHandle check since TieHandle's ioHandle is always closed.

- Fix gethostbyname/getservbyname/etc. aliases field flattening:
  use empty string scalar instead of empty array to prevent field
  shifting in list context.

- Fix sprintf zero-pad flag for missing arguments: %03d with no
  argument now produces "000" instead of "  0".

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock merged commit 8e0c961 into master Apr 14, 2026
2 checks passed
@fglock fglock deleted the fix/io-util-test-failures branch April 14, 2026 06:41
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.

1 participant