Commit Graph
4502 Commits
Author SHA1 Message Date
WaterWhispererandSylvestre Ledru 28ac732bed du: fix -l/--count-links option not counting hardlinks separately (#9884)
* du: fix -l/--count-links option not counting hardlinks separately

* du: add test for -l/--count-links counting hardlinks separately

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2025-12-30 23:53:43 +01:00
Sylvestre Ledru 8c10759e2c Merge pull request #9526 from alexandrefresnais/feature/install_unprivileged
install: add FreeBSD's -U (unprivileged) option
2025-12-29 14:44:21 +01:00
Sylvestre Ledru d946dce1a9 * mac: increase tail test delays to fix intermittent failure 2025-12-28 20:35:26 +01:00
Rostyslav Toch 5b70ed40f1 Merge pull request #9682 from CrazyRoka/ptx-implement-sentence-regexp
ptx: implement -S/--sentence-regexp
2025-12-28 11:35:49 +01:00
Sylvestre Ledru 51d6efdf4c Merge pull request #9337 from blyxxyz/lossy-string-cleanup
Remove lossy OS string conversions
2025-12-27 11:16:05 +01:00
Chris Dryden e6467b1a19 mv: Adding fixes for i-3 GNU tests related to tty output when file is not writeable (#9599)
* Adding fixes for i-3 GNU tests related to tty output when file is not writeable

* Removed translation zero stripping hack and fixed clippy and spelling errors

* Removed unused windows import

* Addressing comments and cleaning up tests

* Spellcheck fixes

* Replacing helper function in other places too

* mv: address review comments - reorder enum, cache mode, safer defaults
2025-12-27 01:14:11 +01:00
mattsuandDorian Péron da543cb76e fix(wc):GNU wc-cpu.sh (#9144)
* wc: align SIMD policy integration

- use SimdPolicy::detect with hardware feature labeling
- keep SIMD behavior respecting GLIBC_TUNABLES
- consolidate wc SIMD debug output and tests

* refactor(wc): simplify SIMD feature collection in debug output

- Changed multi-line SIMD feature vector creation to a single-line expression for improved readability and consistency with surrounding code.
- No functional changes; only stylistic refactoring in the wc debug logic.

* feat(wc): enhance debug output for SIMD hardware support limitations

Add new localization strings and logic to provide detailed debug information when SIMD support is limited by GLIBC_TUNABLES, including lists of disabled and enabled features. Refactor SIMD allowance check for better accuracy in detecting runtime support.

* refactor: consolidate SIMD feature handling in wc command

Refactor SIMD feature detection and reporting in the wc utility by introducing a WcSimdFeatures struct to group enabled, disabled, and runtime-disabled features. This replaces multiple separate functions with a single function, improving code organization and efficiency by reducing redundant iterations over feature lists. Also rename helper functions for clarity and update debug output logic accordingly.

* Update src/uu/wc/src/wc.rs

Co-authored-by: Dorian Péron <72708393+RenjiSann@users.noreply.github.com>

* Update src/uu/wc/locales/en-US.ftl

Co-authored-by: Dorian Péron <72708393+RenjiSann@users.noreply.github.com>

* Update src/uu/wc/locales/fr-FR.ftl

Co-authored-by: Dorian Péron <72708393+RenjiSann@users.noreply.github.com>

* feat(wc): import show_error for enhanced error reporting

Add the show_error import from uucore to enable better error handling in the wc utility, allowing for consistent error messages in line with the project's style.

---------

Co-authored-by: Dorian Péron <72708393+RenjiSann@users.noreply.github.com>
2025-12-27 01:06:08 +01:00
Cả thế giới là RustandSylvestre Ledru ec063a7c37 Added unit tests for stty.rs to improve test coverage (#9094)
* stty: Add 101 unit tests and 16 integration tests to improve coverage

Add comprehensive test coverage for stty:

Unit tests (src/uu/stty/src/stty.rs):
- Flag struct methods and builder pattern (7 tests)
- Control character parsing and formatting (19 tests)
- All combination settings expansion (26 tests)
- Termios modification functions (13 tests)
- String-to-flag/combo/baud parsing (19 tests)
- TermiosFlag trait implementations (5 tests)
- Helper and utility functions (10 tests)
- Trait implementations (2 tests)

Integration tests (tests/by-util/test_stty.rs):
- Help and version output validation (2 tests)
- Invalid argument handling (3 tests)
- Control character overflow validation (2 tests)
- Grouped flag removal validation (1 test)
- File argument error handling (1 test)
- Conflicting print modes (1 test)
- Additional TTY-dependent tests (6 tests, ignored in CI)

Unit test coverage improved from 0% to 43.76% (207/473 lines).
Integration tests validate argument parsing and error handling.

Addresses #9061

* stty: Add essential unit tests and integration tests to improve coverage

- Added 11 essential unit tests for complex internal functions:
  * Control character parsing (string_to_control_char)
  * Control character formatting (control_char_to_string)
  * Combination settings expansion (combo_to_flags)
  * Terminal size parsing with overflow handling (parse_rows_cols)
  * Sane control character defaults (get_sane_control_char)

- Added 16 integration tests for command behavior:
  * Help/version output validation
  * Invalid argument handling
  * Control character overflow validation
  * Grouped flag removal validation
  * File argument error handling
  * Conflicting print modes
  * TTY-dependent tests (marked as ignored for CI)

Unit tests focus on complex parsing logic that's difficult to test via
integration tests. Integration tests validate actual command behavior.

Coverage improved from 0% to 43.76% (207/473 lines).

Fixes #9061

* stty: Add comprehensive unit and integration tests for error handling

- Add unit tests for parse_rows_cols() with edge cases and wraparound
- Add unit tests for string_to_baud() with platform-specific handling
- Add unit tests for string_to_combo() with all combo modes
- Add 17 integration tests for missing arguments and invalid inputs
- Enhance test_invalid_arg() with better error message assertions
- Update coverage script for improved reporting

Coverage improved from 22.26% to 23.14% regions.

* stty: Add Debug and PartialEq derives for test assertions

- Add #[derive(Debug, PartialEq)] to AllFlags enum
- Add PartialEq to Flag struct derives
- Enables assert_eq! macro usage in unit tests

* stty: Fix formatting and clippy warnings in tests

- Replace assert_eq! with assert! for boolean comparisons
- Fix line wrapping for long logical expressions
- Use inline format string syntax (e.g., {err} instead of {})
- All 25 unit tests pass
- No clippy warnings

* stty: Add inline spell-checker ignores for test strings

- Add spell-checker:ignore comments for test data (notachar, notabaud, susp)
- Add spell-checker:ignore comments for French error strings (Valeur, entier, invalide)
- Fixes cspell validation without modifying global config

* perf: gate PartialEq derive to test builds only

The PartialEq derive was being compiled into release builds even though
it's only used in test code. This caused a 3.33% performance regression
in the du_human_balanced_tree benchmark due to increased binary size
affecting CPU cache efficiency.

Changes:
- stty.rs: Gate PartialEq derive on Flag<T> with #[cfg_attr(test, derive(PartialEq))]
- flags.rs: Gate PartialEq derive on AllFlags enum with #[cfg_attr(test, derive(PartialEq))]

This eliminates the performance regression while keeping all test code
functional and unchanged.

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2025-12-27 00:48:07 +01:00
mattsu c0b96841d7 env:Improve GNU coreutils Compatibility & Fix env-signal-handler.sh Test (#9465)
* feat(env): add signal handling options and logging

- Add default-signal, block-signal, and list-signal-handling options
- Support specifying, tracking, and reporting signal handling changes
- Update en-US and fr-FR locales to document new signal options

* feat: Add `__ALL__` signal option, improve signal argument parsing, and prevent ignoring uncatchable signals.

* fix: Preserve inherited SIGPIPE behavior using `RUST_SIGPIPE` environment variable and `uucore`'s new handler.

* style: reformat code, reorder imports, and remove trailing blank lines

* chore: update spell-checker ignore lists for technical terms

Added 'Sigmask' to ignore list in env.rs and 'sighandler' in test_env.rs to suppress false positives from spell-checker on legitimate specialized words.

* fix(env): Skip invalid signals instead of failing

Previously, the signal handling functions (`apply_default_signal`, `apply_ignore_signal`, and `apply_block_signal`) would return an error if `signal_from_value` got an invalid signal. This change modifies the code to skip invalid signals and continue processing, aligning with GNU env's behavior of ignoring undefined signals on certain platforms where `ALL_SIGNALS` may include invalid values. This improves compatibility and robustness.
2025-12-27 00:16:36 +01:00
Chris DrydenandMarco Trevisan dbfe7c56ab stty: columns env support and integration testing (#9490)
* stty: Wrap parameters when using --all

Do the same as GNU stty when it has to prints the parameter, doing
proper text wrapping

* Adding integration tests for the COLUMNS env variable support in stty

* Adding integration tests for the COLUMNS env variable support in stty

---------

Co-authored-by: Marco Trevisan (Treviño) <mail@3v1n0.net>
2025-12-27 00:13:33 +01:00
Chris Dryden 7cce907c0e Stty: implemented hex and octal parsing for rows and columns (#9516)
* Implemented hex and octal parsing for row columns for stty

* Adding more test cases with different upper and lowercase values

* stty: use ExtendedParser for hex/octal row/col parsing
2025-12-27 00:11:45 +01:00
mattsu 57d3fce29e chroot: use execvp directly instead of process::Command (#9013)
* chroot: exec command with Command::exec and map errors

* test(chroot): add error handling and UID/GID retention tests

* chore(cspell): add noexec to jargon wordlist
2025-12-26 23:59:06 +01:00
naoNao89 31b5cc10dc fix(shred): stop immediately on write errors (fixes #7947)
Replace show_if_err!() with ? operator in wipe_file() to properly
propagate errors and stop pass loop on first write failure.

This matches GNU shred behavior where any write error (disk quota,
I/O error, etc.) stops execution immediately instead of continuing
with remaining passes.

Changes:
- src/uu/shred/src/shred.rs: Use ? operator for error propagation
- tests/by-util/test_shred.rs: Enable previously ignored test
2025-12-26 23:55:40 +01:00
Teemu PätsiandSylvestre Ledru 18a50ff513 id: Fix incorrect human-readable output (#7814)
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2025-12-26 23:46:10 +01:00
Sylvestre Ledru 1c358695ec Merge branch 'main' into lossy-string-cleanup 2025-12-26 23:17:23 +01:00
Cả thế giới là Rust 3e71f638bc Fix uptime on macOS using sysctl kern.boottime fallback (#8908)
* fix(uucore): use sysctl kern.boottime on macOS as fallback for uptime

If utmpx BOOT_TIME is unavailable, derive boot time via sysctl CTL_KERN.KERN_BOOTTIME to reduce intermittent macOS failures (e.g., #3621).

Context (blame/history):

- 2774274cc2 ("uptime: Support files in uptime (#6400)"): added macOS utmpxname validation and non-fatal 'unknown uptime' fallback with tests (tests/by-util/test_uptime.rs).

- 920d29f703 ("uptime: add support for OpenBSD using utmp"): reorganized uptime.rs and solidified utmp/utmpx-driven paths.

* test: add comprehensive macOS tests for sysctl kern.boottime fallback

Add unit tests for sysctl boottime availability and get_uptime reliability on macOS, verifying the fallback mechanism works correctly when utmpx BOOT_TIME is unavailable.

Add integration tests to ensure uptime command consistently succeeds on macOS with various flags (default, --since) and produces properly formatted output.

Enhance documentation of the sysctl fallback code with detailed comments explaining why it exists, the issue it addresses (#3621), and comprehensive SAFETY comments for the unsafe sysctl call.

All tests are properly gated with #[cfg(target_os = "macos")] to ensure they only run on macOS and don't interfere with other platforms.

* refactor(uucore): replace unsafe sysctl with safe command-line approach for macOS boot time

- Remove unsafe libc::sysctl() system call entirely
- Replace with safe std::process::Command executing 'sysctl -n kern.boottime'
- Parse sysctl output format to extract boot time seconds
- Maintains same API and functionality while eliminating unsafe blocks
- Addresses reviewer feedback to completely remove unsafe code
2025-12-26 01:11:37 +01:00
Sylvestre Ledru 103777b766 Merge pull request #8798 from naoNao89/test/cat-stdbuf-broken-pipe
tests(cat,stdbuf): Add broken-pipe robustness tests (#4627)
2025-12-26 00:25:52 +01:00
Daniel Hofstetter 5d2ac30084 Merge pull request #9841 from sylvestre/env-dedup
env/printenv: dedup the code
2025-12-25 17:21:34 +01:00
Sylvestre Ledru 50085d7a0e printenv: add a test for non-utf-8 var
Like in : 5d4abd88e9
2025-12-25 16:31:25 +01:00
Daniel Hofstetter 398b9c1b00 clippy: enable needless_raw_string_hashes lint (#9840) 2025-12-25 16:05:45 +01:00
mattsu 502f3b17bf sort:Align sort debug key annotations with GNU coreutils (#9468)
* fix: ignore NUL bytes in sort debug output alignment calculations

Replaced direct length checks with filtered counts excluding b'\0' in debug underline
and indentation output to prevent misalignment from embedded NUL characters, which
are often stripped during inspection. Added comprehensive tests for various sort
modes and inputs, including NUL byte scenarios, to verify correct debug annotations.

* feat: add locale-aware tests for sort debug key annotations

Split the existing `test_debug_key_annotations` into two tests: one for basic functionality and another for locale-specific behavior to handle conditional execution based on environment variables. Extracted a new helper function `debug_key_annotation_output` to generate debug output, improving test modularity and reducing code duplication. This enhances test coverage for debug key annotations in different numeric locales.

* refactor(test): optimize string building in debug_key_annotation_output for efficiency

Rework the `number` helper function to use a mutable String buffer with `writeln!` macro
instead of collecting intermediary vectors with `map` and `collect`. This reduces allocations
and improves performance in test output generation, building the numbered output directly
without extra string concatenations.

* refactor(tests): improve formatting and readability in sort test helpers

- Reformatted command-line arguments in test_debug_key_annotations_locale to fit on fewer lines
- Wrapped run_sort calls in debug_key_annotation_output for better code structure
- Minor reordering of output.push_str blocks for consistency and clarity

* refactor(test): embed expected debug key annotation outputs as constants

Replace fixture file reads with inline constants in test functions for
debug key annotations and locale variants. This makes the tests more
self-contained by removing dependencies on external fixture files.

* feat(sort): extract count_non_null_bytes for debug alignment

Add a helper function `count_non_null_bytes` to count bytes in a slice while ignoring embedded NULs. This improves code reusability and is used in debug underline output to ensure proper alignment by filtering NUL characters that may be present in selection strings. Replaces inline counting logic in two locations within the `Line` implementation.
2025-12-24 18:28:24 +01:00
oech3 76063511cb is_a_tty.sh: Reduce lines 2025-12-24 20:14:19 +09:00
naoNao89 585f46ae25 date(locale): use actual locale format strings, add comprehensive tests
Replace hardcoded format string selection with direct nl_langinfo(D_T_FMT)
usage. This ensures locale-specific formatting details (leading zeros,
component ordering, hour formats) are properly respected from system
locale data instead of detecting 12/24-hour preference and returning
hardcoded alternatives.

Changes to locale.rs:
- Remove detect_12_hour_format() and uses_12_hour_format()
- Simplify get_locale_default_format() to use D_T_FMT directly
- Add timezone injection if %Z missing from locale format
- Add use nix::libc import

Add test coverage (tests/by-util/test_date.rs):
- 4 new unit tests for locale format structure validation
- 7 new integration tests verifying locale-specific behavior
- Tests prevent regression to hardcoded format strings

Addresses feedback from PR #9654 comment #3676971020
2025-12-23 23:39:51 +01:00
CrazyRoka 6f696b907e ptx: fix incorrect column width calculation and padding logic 2025-12-23 23:38:09 +01:00
Dmitry Shemetov 949f038b3b test: symlink differently on windows/not 2025-12-23 23:30:47 +01:00