Skip to content

fold:fix gnu test fold-zero-width.sh#9274

Merged
sylvestre merged 37 commits intouutils:mainfrom
mattsu2020:fold_compatibility
Jan 22, 2026
Merged

fold:fix gnu test fold-zero-width.sh#9274
sylvestre merged 37 commits intouutils:mainfrom
mattsu2020:fold_compatibility

Conversation

@mattsu2020
Copy link
Contributor

@mattsu2020 mattsu2020 commented Nov 14, 2025

Implement logic to increment column count in WidthMode::Characters, emitting output when width is reached. This ensures accurate line folding for multi-byte characters, enhancing Unicode support.

related
#9127

…scii_line

Implement logic to increment column count in WidthMode::Characters, emitting output when width is reached. This ensures accurate line folding for multi-byte characters, enhancing Unicode support.
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

- Added conditional check in fold_file function to call emit_output when col_count >= width
- Ensures lines are properly wrapped based on byte or character width before final output flush
- Improves handling of incomplete lines that need early breaking to respect the specified width
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 14, 2025

CodSpeed Performance Report

Merging this PR will improve performance by 50.06%

Comparing mattsu2020:fold_compatibility (47fb94e) with main (cbbff30)

Summary

⚡ 2 improved benchmarks
✅ 140 untouched benchmarks
⏩ 180 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation fold_custom_width[50000] 33.1 ms 22 ms +50.06%
Simulation fold_many_lines[100000] 80.4 ms 55.8 ms +44.08%

Footnotes

  1. 180 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

In character width mode, emit output immediately after segments are added if column count exceeds width, preventing redundant flushes. Simplify the file folding logic by removing unnecessary conditional checks at the end, ensuring clean output writing. This fixes potential issues with extra line breaks or incorrect folding behavior.
…ability

Refactor code in fold.rs to break lengthy if-condition statements across multiple lines in push_ascii_segment, process_utf8_line, and process_non_utf8_line functions. This improves code readability without changing functionality.
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/fold/fold-characters. tests/fold/fold-characters is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

…ory usage

Introduce a STREAMING_FLUSH_THRESHOLD constant and helper functions (maybe_flush_unbroken_output, push_byte, push_bytes) to periodically flush the output buffer when it exceeds 8KB and no spaces are being tracked, preventing excessive memory consumption when processing large files. This refactor replaces direct buffer pushes with checks for threshold-based flushing.
@sylvestre
Copy link
Contributor

Could you please add tests?
thanks

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/fold/fold-characters. tests/fold/fold-characters is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@sylvestre
Copy link
Contributor

and please fix this regression:
GNU test failed: tests/fold/fold-characters. tests/fold/fold-characters is passing on 'main'. Maybe you have to rebase?

mattsu2020 and others added 5 commits November 15, 2025 08:55
…d tests

Remove conditional checks that incorrectly emitted output when column count reached width in character mode, ensuring proper folding of wide characters and handling of edge cases. Add comprehensive tests for wide characters, invalid UTF-8, zero-width spaces, and buffer boundaries to verify correct behavior. This prevents issues with multi-byte character folding where output was prematurely flushed, improving accuracy for Unicode input.
- Remove trailing empty lines in fold.rs
- Compact multiline variable assignments in test_fold.rs for readability
…racters

Add unicode-width crate to handle zero-width Unicode characters in fold utility. Introduced new test 'test_zero_width_data_line_counts' to verify correct wrapping in --characters mode for zero-width bytes and spaces, ensuring fold behaves consistently with character counts rather than visual width.
- Add bytecount dependency to Cargo.toml and Cargo.lock
- Refactor newline_count function in test_fold.rs to use bytecount::count instead of manual iteration for better performance
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

Modify the fold implementation to process input in buffered chunks rather than line-by-line reading, ensuring correct handling of multi-byte characters split across buffer boundaries. Add process_pending_chunk function and new streaming logic to fold_file for better performance on large files. Update tests accordingly.
Replace loop with early empty check by a while loop conditional on !pending.is_empty()
for clarity. Restructure invalid UTF-8 error handling to first check if valid_up_to == 0,
then process the valid prefix, improving code readability and flow without changing behavior.
Consolidate the assignment of the `valid` variable from multiple lines to a single line for improved code readability and adherence to style guidelines favoring concise declarations.
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@mattsu2020
Copy link
Contributor Author

この回帰を修正してください: GNU test failed: tests/fold/fold-characters. tests/fold/fold-characters is passing on 'main'. Maybe you have to rebase?

done

@ChrisDryden
Copy link
Collaborator

#9328 just saw that this was succeeding, with both of these together the all of the fold tests will pass

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@sylvestre
Copy link
Contributor

are you sure fold-zero-width.sh is fixed for real ? :)

@mattsu2020 mattsu2020 marked this pull request as draft January 9, 2026 23:15
Previously, the push_byte function only appended the byte to the buffer and returned Ok(()), potentially leaving output unflushed. This change adds a call to maybe_flush_unbroken_output to ensure proper flushing after each byte push, improving output reliability in the fold utility.
- Updated multiple crates including aho-corasick (1.1.3 -> 1.1.4), anstream (0.6.19 -> 0.6.21), and toml (0.22.27 -> 0.23.10+spec-1.0.0)
- Added toml_parser dependency as required by updated toml crate
- Ensures compatibility, security patches, and performance improvements across the project
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

GNU testsuite comparison:

Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/shuf/shuf-reservoir (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/sort/sort-stale-thread-mem (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@mattsu2020 mattsu2020 marked this pull request as ready for review January 10, 2026 05:23
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/sort/sort-debug-warn. tests/sort/sort-debug-warn is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

- Updated chrono from 0.4.42 to 0.4.43
- Updated clap_lex from 0.7.6 to 0.7.7
- Updated getrandom from 0.2.16 to 0.2.17
- Updated flate2 from 1.1.5 to 1.1.8 with dependency changes
- Updated icu_locale_data from 2.1.1 to 2.1.2
- Updated js-sys from 0.3.83 to 0.3.85
- Updated wasm-bindgen from 0.2.106 to 0.2.108
- Removed unused arbitrary and derive_arbitrary packages
- Ensured compatibility and security fixes in dependencies
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/fold/fold-zero-width is no longer failing!

@sylvestre sylvestre merged commit 6db319e into uutils:main Jan 22, 2026
132 checks passed
@mattsu2020 mattsu2020 deleted the fold_compatibility branch January 22, 2026 23:26
mattsu2020 added a commit to mattsu2020/coreutils that referenced this pull request Jan 23, 2026
---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
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.

3 participants