Skip to content

fix(true,false,dirname): coreutils operand-ignore and leading-slash collapse semantics (#1196) - #1198

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1196-true-dirname
Oct 17, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1196-true-dirname

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1196 (the agent that implemented this finished its worktree silently; I verified every claim below before landing it).

What changed

  • src/commands/true.cpp / src/commands/false.cpp: the handlers no longer run getopt on operands — coreutils' true/false ignore anything that is not the sole --help/--version. true -x and true fixed-args exit 0 (installed build returned 1).
  • src/core/dispatcher.cppm: true/false join the existing help_version_only_when_sole_argument behavior class shared with printf/test/[ — so --help as the sole argument still prints help through the shared (i18n-cataloged) path, and it stops being data in any other position. No new user-visible strings; a hardcoded English usage block was removed from true.cpp (AGENTS.md I18N review satisfied: net-zero / net-negative).
  • src/commands/dirname.cpp: GNU separator semantics — trailing slash trimming relative to the root prefix, with one-or-two leading slashes preserved and three-or-more collapsed (dirname // → //, dirname /// → /, dirname ////a → /). basename '' etc. via the shared operand guard.

Verification (this worktree, fresh build)

  • powershell scripts/build-with-vs.ps1 → 803/803 compiled and linked clean.
  • ctest -R "true_cmd|false_cmd" → 10/10 pass (true_basic, true_ignores_nonempty_operand, true_ignores_every_operand_silently, true_help_only_as_sole_argument, false side mirrored).
  • ctest -R "dirname\." → 14/14 pass (incl. new dirname_triple_slash_collapses_to_single, dirname_four_slash_collapses_to_single, dirname_double_slash_root_*, dirname_unc_paths_preserve_double_separator_root).
  • Binary spot checks against D:/Git/usr/bin coreutils: true -x → rc 0 (GNU 0), dirname /// → / (GNU /), dirname // → // (GNU //), dirname /a/b/c → /a/b.
  • One deliberate divergence documented in-code: same-sole-arg --help exit status convention follows WinuxCmd's house rule (0), matching what the shared help mechanism already does for printf/test.

Scope

No other tools touched; command_context.cppm only carries the plumbing for the operand-guard. This closes both halves of #1196; the sibling issue #1195 (checksum text-mode stdin) is being handled separately.

@caomengxuan666
caomengxuan666 merged commit 23ba4a6 into main Oct 17, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1196-true-dirname branch October 21, 2026 08:19
caomengxuan666 added a commit that referenced this pull request Oct 27, 2026
…uite

- dirname: revert the #1337 all-separator collapse. On this platform //
  is the MSYS/UNC root and is deliberately preserved (#1196/#1198 tests
  encode it); the audit compared against Linux GNU where // is not a
  distinct root. Issue #1337 stays open as a platform-intentional
  divergence; regression case 61 and its index row are dropped.
- stat test: GNU keeps an explicit -c format regardless of a later -t
  (probed in #1334); the inherited test asserted the opposite.
- tail test: with -z, GNU keeps headers and section separators
  newline-terminated (probed in #1342); the inherited test encoded the
  pre-fix NUL form.

Verified on the rebased base (beb5655): MSVC Debug build green;
98/98 touched-area tests pass; full ctest retains only the 11
environmental failures that reproduce identically on origin/main
(LongPathsEnabled=0, no CONIN$ console under the test runner).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

true rejects a non-empty operand (rc 1); dirname /// returns //

1 participant