-
-
Notifications
You must be signed in to change notification settings - Fork 2k
refactor(dirname): implement pure string manipulation per POSIX #8936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sylvestre
merged 7 commits into
uutils:main
from
naoNao89:test/dirname-additional-coverage
Jan 17, 2026
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58f500d
test(dirname): add coverage for missing operand and multiple paths
naoNao89 676fc03
refactor(dirname): implement pure string manipulation per POSIX
naoNao89 2c72ad3
test(dirname): remove redundant inline comments per review
naoNao89 8f4c88b
Merge branch 'main' into test/dirname-additional-coverage
naoNao89 f862552
Merge branch 'main' into test/dirname-additional-coverage
sylvestre d8287a6
dirname: implement PR #8936 feedback
naoNao89 cdc5eca
Merge branch 'main' into test/dirname-additional-coverage
sylvestre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -9,6 +9,13 @@ fn test_invalid_arg() { | |||
| new_ucmd!().arg("--definitely-invalid").fails_with_code(1); | ||||
| } | ||||
|
|
||||
| #[test] | ||||
| fn test_missing_operand() { | ||||
| // Test calling dirname with no arguments - should fail | ||||
| // This covers the error path at line 80-82 in dirname.rs | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
lines will change |
||||
| new_ucmd!().fails_with_code(1); | ||||
| } | ||||
|
|
||||
| #[test] | ||||
| fn test_path_with_trailing_slashes() { | ||||
| new_ucmd!() | ||||
|
|
@@ -156,7 +163,7 @@ fn test_trailing_dot_edge_cases() { | |||
| new_ucmd!() | ||||
| .arg("/home/dos//.") | ||||
| .succeeds() | ||||
| .stdout_is("/home/dos/\n"); | ||||
| .stdout_is("/home/dos\n"); | ||||
|
|
||||
| // Path with . in middle (should use normal logic) | ||||
| new_ucmd!() | ||||
|
|
@@ -216,3 +223,68 @@ fn test_existing_behavior_preserved() { | |||
| .succeeds() | ||||
| .stdout_is("/home/dos\n"); | ||||
| } | ||||
|
|
||||
| #[test] | ||||
| fn test_multiple_paths_comprehensive() { | ||||
| // Comprehensive test for multiple paths in single invocation | ||||
| // Tests the loop at line 84 with various edge cases mixed | ||||
|
naoNao89 marked this conversation as resolved.
Outdated
|
||||
| new_ucmd!() | ||||
| .args(&[ | ||||
| "/home/dos/.", // trailing dot case | ||||
|
naoNao89 marked this conversation as resolved.
Outdated
|
||||
| "/var/log", // normal path | ||||
| ".", // current directory | ||||
| "/tmp/.", // another trailing dot | ||||
| "", // empty string | ||||
| "/", // root | ||||
| "relative/path", // relative path | ||||
| ]) | ||||
| .succeeds() | ||||
| .stdout_is("/home/dos\n/var\n.\n/tmp\n.\n/\nrelative\n"); | ||||
| } | ||||
|
|
||||
| #[test] | ||||
| fn test_all_dot_slash_variations() { | ||||
| // Tests for all the cases mentioned in issue #8910 comment | ||||
| // https://github.com/uutils/coreutils/issues/8910#issuecomment-3408735720 | ||||
|
|
||||
| // foo//. -> foo | ||||
|
naoNao89 marked this conversation as resolved.
Outdated
|
||||
| new_ucmd!().arg("foo//.").succeeds().stdout_is("foo\n"); | ||||
|
|
||||
| // foo///. -> foo | ||||
| new_ucmd!().arg("foo///.").succeeds().stdout_is("foo\n"); | ||||
|
|
||||
| // foo/./ -> foo | ||||
| new_ucmd!().arg("foo/./").succeeds().stdout_is("foo\n"); | ||||
|
|
||||
| // foo/bar/./ -> foo/bar | ||||
| new_ucmd!() | ||||
| .arg("foo/bar/./") | ||||
| .succeeds() | ||||
| .stdout_is("foo/bar\n"); | ||||
|
|
||||
| // foo/./bar -> foo/. | ||||
| new_ucmd!().arg("foo/./bar").succeeds().stdout_is("foo/.\n"); | ||||
| } | ||||
|
|
||||
| #[test] | ||||
| fn test_dot_slash_component_preservation() { | ||||
| // Ensure that /. components in the middle are preserved | ||||
| // These should NOT be normalized away | ||||
|
|
||||
| new_ucmd!().arg("a/./b").succeeds().stdout_is("a/.\n"); | ||||
|
|
||||
| new_ucmd!() | ||||
| .arg("a/./b/./c") | ||||
| .succeeds() | ||||
| .stdout_is("a/./b/.\n"); | ||||
|
|
||||
| new_ucmd!() | ||||
| .arg("foo/./bar/baz") | ||||
| .succeeds() | ||||
| .stdout_is("foo/./bar\n"); | ||||
|
|
||||
| new_ucmd!() | ||||
| .arg("/path/./to/file") | ||||
| .succeeds() | ||||
| .stdout_is("/path/./to\n"); | ||||
| } | ||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.