Repository navigation
find: spell paths with / on Windows when UUTILS_PATH_SEPARATOR=slash #907
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ use std::os::unix::fs::symlink; | |
| #[cfg(windows)] | ||
| use std::os::windows::fs::{symlink_dir, symlink_file}; | ||
|
|
||
| use common::test_helpers::fix_up_slashes; | ||
| use common::test_helpers::{fix_up_slashes, path_to_testing_commandline}; | ||
|
|
||
| mod common; | ||
|
|
||
|
|
@@ -3157,3 +3157,85 @@ fn find_debug_option() { | |
| .stdout_contains("Valid arguments for -D:\n") | ||
| .stdout_does_not_contain("bogus"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn path_separator_slash_prints_slashes() { | ||
| // A no-op where `/` is already the separator; on Windows it replaces `\`. | ||
| ucmd() | ||
| .env("UUTILS_PATH_SEPARATOR", "slash") | ||
| .args(&["test_data/depth/1", "-name", "f2"]) | ||
| .succeeds() | ||
| .stdout_only("test_data/depth/1/2/f2\n"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn path_separator_slash_matches_slash_patterns() { | ||
| ucmd() | ||
| .env("UUTILS_PATH_SEPARATOR", "slash") | ||
| .args(&[ | ||
| "test_data/depth", | ||
| "-sorted", | ||
| "-path", | ||
| "*/2/*", | ||
| "-prune", | ||
| "-o", | ||
| "-type", | ||
| "f", | ||
| "-print", | ||
| ]) | ||
| .succeeds() | ||
| .stdout_only("test_data/depth/1/f1\ntest_data/depth/f0\n"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn path_separator_slash_reaches_printf() { | ||
| ucmd() | ||
| .env("UUTILS_PATH_SEPARATOR", "slash") | ||
| .args(&["test_data/depth", "-name", "f2", "-printf", "%p %h %P\n"]) | ||
| .succeeds() | ||
| .stdout_only("test_data/depth/1/2/f2 test_data/depth/1/2 1/2/f2\n"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn path_separator_slash_reaches_exec() { | ||
| ucmd() | ||
| .env("UUTILS_PATH_SEPARATOR", "slash") | ||
| .args(&[ | ||
| "test_data/depth/1", | ||
| "-name", | ||
| "f2", | ||
| "-exec", | ||
| &path_to_testing_commandline(), | ||
| "-", | ||
| "--no_print_cwd", | ||
| "{}", | ||
| ";", | ||
| ]) | ||
| .succeeds() | ||
| .stdout_only("args=\n--no_print_cwd\ntest_data/depth/1/2/f2\n"); | ||
| } | ||
|
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. the docs mention
Author
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. Added |
||
|
|
||
| #[test] | ||
| fn path_separator_other_values_keep_the_native_separator() { | ||
| let root = fix_up_slashes("test_data/depth/1"); | ||
| ucmd() | ||
| .env("UUTILS_PATH_SEPARATOR", "/") | ||
| .args(&[root.as_str(), "-name", "f2"]) | ||
| .succeeds() | ||
| .stdout_only(fix_up_slashes("test_data/depth/1/2/f2\n")); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn path_separator_slash_leaves_verbatim_paths_alone() { | ||
| // A canonicalized start point comes back as `\\?\C:\...`, where `/` is | ||
| // not a separator, so the walk keeps `\` throughout. | ||
| let root = fs::canonicalize("test_data/depth/1").unwrap(); | ||
| let root = root.to_str().unwrap(); | ||
| assert!(root.starts_with(r"\\?\")); | ||
| ucmd() | ||
| .env("UUTILS_PATH_SEPARATOR", "slash") | ||
| .args(&[root, "-name", "f2"]) | ||
| .succeeds() | ||
| .stdout_only(format!("{root}\\2\\f2\n")); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add a windows-only test for the
\\?\case? e.g. a canonicalized start point, which comes back verbatimThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
path_separator_slash_leaves_verbatim_paths_alone(Windows only): it canonicalizestest_data/depth/1into a\\?\start point, walks it withUUTILS_PATH_SEPARATOR=slash, and checks every printed path keeps\. Passes on both Windows legs. Also rebased onto main to clear the conflict.