Skip to content

Conversation

naoNao89
Copy link
Contributor

@naoNao89 naoNao89 commented Oct 5, 2025

Summary

Adds the -f flag to ls, matching GNU behavior:

  • Enables -a (shows all files including . and ..)
  • Disables sorting (shows files in directory order)
  • Disables implicit --color (explicit --color still works)

Partially addresses #1872.

Implementation

Used index-based last-flag-wins logic (same pattern as --zero flag):

  • ls -f -t sorts by time (last flag wins)
  • ls -t -f no sorting (last flag wins)
  • ls -f --color=always shows color (explicit overrides implicit disable)

Copy link

github-actions bot commented Oct 5, 2025

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)

Copy link

github-actions bot commented Oct 5, 2025

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)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

…ation

Fix the -f flag implementation to properly enable all files display,
disable sorting, and handle color output correctly.

Changes:
- Correct UNSORTED_ALL constant from 'unsorted-all' to 'f'
- Fix color logic to honor explicit --color flag regardless of -f position
- Add French localization for ls-help-unsorted-all
- Add comprehensive integration tests for -f flag behavior

The explicit --color flag now always takes precedence over -f implicit
color disabling, matching expected CLI behavior.
Copy link

github-actions bot commented Oct 7, 2025

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)

Copy link

codspeed-hq bot commented Oct 7, 2025

CodSpeed Performance Report

Merging #8824 will improve performances by 2.98%

Comparing naoNao89:feat/ls-f-option (87db5e9) with main (47f8722)1

Summary

⚡ 1 improvement
✅ 78 untouched
⏩ 73 skipped2

Benchmarks breakdown

Benchmark BASE HEAD Change
ls_recursive_long_all_wide_tree[(15000, 1500)] 149.8 ms 145.4 ms +2.98%

Footnotes

  1. No successful run was found on main (2598607) during the generation of this report, so 47f8722 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 73 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.

naoNao89 added a commit to naoNao89/coreutils that referenced this pull request Oct 7, 2025
Address maintainer feedback from PR uutils#8824 review:

1. test_f_flag_disables_sorting: Compare -f output with -a (sorted) and -U (unsorted)
   to prove sorting is actually disabled, not just that files appear in output

2. test_f_overrides_big_a: Rename from test_f_overrides_a_and_big_a and fix assertions
   to check for .. presence (distinguishes -f from -A) instead of .hidden (shown in both)

3. test_f_overrides_sort_flags: Use size-based files and explicit output comparisons
   to verify last-flag-wins behavior with deterministic ordering

4. test_big_u_overrides_f_sort: Use size-based files and verify -U participates
   in last-flag-wins by checking actual output order

All tests now properly validate flag interactions instead of just checking file presence.
naoNao89 added a commit to naoNao89/coreutils that referenced this pull request Oct 7, 2025
Replace if/else chain with match expression for improved readability
and more idiomatic Rust code. Uses match guards for index comparisons.

Addresses maintainer feedback from PR uutils#8824 review.

No functional changes - behavior remains identical.
@naoNao89
Copy link
Contributor Author

naoNao89 commented Oct 7, 2025

  • test_f_flag_disables_sorting:
    • before: only checked files exist
    • after: compares -f vs -a (proves different) and -f vs -U (proves same)
  • test_f_overrides_big_a (renamed):
    • before: called test_f_overrides_a_and_big_a, checked .hidden (not useful)
    • after: checks .. presence (distinguishes -f from -A)
  • test_f_overrides_sort_flags:
    • before: only checked file presence
    • after: uses size-based files, verifies actual ordering changes
  • test_big_u_overrides_f_sort:
    • before: only checked file presence
    • after: verifies -U last-flag-wins with deterministic ordering
  • extract_sort(): clean match expression with guards

naoNao89 added a commit to naoNao89/coreutils that referenced this pull request Oct 7, 2025
Address maintainer feedback from PR uutils#8824 review:

Tests improvements:
1. test_f_flag_disables_sorting: Compare -f output with -a (sorted) and -U (unsorted)
   to prove sorting is disabled, not just that files appear in output
2. test_f_overrides_big_a: Rename from test_f_overrides_a_and_big_a and check .. presence
   (distinguishes -f from -A) instead of .hidden (shown in both)
3. test_f_overrides_sort_flags: Use size-based files with explicit output comparisons
   to verify last-flag-wins with deterministic ordering
4. test_big_u_overrides_f_sort: Use size-based files and verify -U participates
   in last-flag-wins by checking actual output order

Code refactoring:
5. extract_sort(): Replace if/else chain with match expression for improved readability

All variable names now follow snake_case convention to fix lint warnings.
@naoNao89 naoNao89 closed this Oct 7, 2025
@naoNao89 naoNao89 reopened this Oct 7, 2025
Address maintainer feedback from PR uutils#8824 review:

1. test_f_flag_disables_sorting: Compare -f output with -a (sorted) and -U (unsorted)
   to prove sorting is actually disabled, not just that files appear in output

2. test_f_overrides_big_a: Rename from test_f_overrides_a_and_big_a and fix assertions
   to check for .. presence (distinguishes -f from -A) instead of .hidden (shown in both)

3. test_f_overrides_sort_flags: Use size-based files and explicit output comparisons
   to verify last-flag-wins behavior with deterministic ordering

4. test_big_u_overrides_f_sort: Use size-based files and verify -U participates
   in last-flag-wins by checking actual output order

All tests now properly validate flag interactions instead of just checking file presence.
Replace if/else chain with match expression for improved readability
and more idiomatic Rust code. Uses match guards for index comparisons.

Addresses maintainer feedback from PR uutils#8824 review.

No functional changes - behavior remains identical.
Follow Rust naming conventions by converting variable names in -f flag
tests from mixed case (out_Af, out_fS, etc.) to snake_case (out_a_f,
out_f_s, etc.). This eliminates clippy warnings about non_snake_case
identifiers.
The tests test_f_flag_disables_sorting, test_big_u_overrides_f_sort, and
test_f_overrides_sort_flags made incorrect assumptions that unsorted
directory order would always differ from sorted order. However,
fs::read_dir() returns entries in filesystem-dependent order which may
accidentally match sorted order on some filesystems.

Changes:
- Removed assertions comparing unsorted vs sorted outputs
- Added deterministic checks (e.g., verifying --sort after -f works)
- Added explicit order verification for size-sorted outputs
- Tests now verify flag precedence without relying on directory order

Fixes CI failures on Windows and SELinux platforms.

Quality checks passed:
- cargo fmt --check: ✓
- cargo clippy --test tests: ✓
- all 3 modified tests pass: ✓
Copy link

github-actions bot commented Oct 7, 2025

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)

Renamed test_big_u_overrides_f_sort to test_big_u_participates_in_sort_flag_wins
to accurately reflect that it tests -U with -S interactions, not -f.
Copy link

github-actions bot commented Oct 9, 2025

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)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

Copy link

github-actions bot commented Oct 9, 2025

GNU testsuite comparison:

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

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