🧪 Add unit tests for path_to_string_lossy utility#55
🧪 Add unit tests for path_to_string_lossy utility#55bashandbone wants to merge 1 commit intomainfrom
Conversation
- Added `test_path_to_string_lossy_valid` to verify standard UTF-8 path conversion. - Added `test_path_to_string_lossy_invalid` (Unix-only) to verify replacement character insertion for invalid UTF-8 paths. - Verified test logic with a standalone script using `rustc --test`. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR adds unit test coverage for the path_to_string_lossy utility in src/utilities.rs, validating behavior for both UTF-8-clean paths and (Unix-only) paths containing invalid bytes.
Changes:
- Add a unit test verifying lossy conversion returns the same string for valid UTF-8 paths.
- Add a Unix-only unit test verifying invalid path bytes are converted with the Unicode replacement character.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let os_str = std::ffi::OsString::from_vec(bytes); | ||
| let path = std::path::Path::new(&os_str); |
There was a problem hiding this comment.
os_str is an OsString here, not an OsStr. Renaming this local to something like os_string would better reflect the type and avoid confusion with OsStr.
| let os_str = std::ffi::OsString::from_vec(bytes); | |
| let path = std::path::Path::new(&os_str); | |
| let os_string = std::ffi::OsString::from_vec(bytes); | |
| let path = std::path::Path::new(&os_string); |
| let path = std::path::Path::new(&os_str); | ||
|
|
||
| let result = path_to_string_lossy(path); | ||
| assert_eq!(result, format!("a{}b", std::char::REPLACEMENT_CHARACTER)); |
There was a problem hiding this comment.
This assertion builds the expected string with format!, which allocates unnecessarily in a tight unit test. Prefer comparing against a literal like "a\u{FFFD}b" (or otherwise constructing the expected String without formatting) to keep the test simpler and allocation-free.
| assert_eq!(result, format!("a{}b", std::char::REPLACEMENT_CHARACTER)); | |
| assert_eq!(result, "a\u{FFFD}b"); |
| fn test_path_to_string_lossy_valid() { | ||
| let path = std::path::Path::new("valid_utf8"); | ||
| assert_eq!(path_to_string_lossy(path), "valid_utf8"); | ||
| } |
There was a problem hiding this comment.
path_to_string_lossy() currently always prints the "non-UTF-8" warning via eprintln! even when the input path is valid UTF-8. This new test will therefore emit a misleading warning (and adds noise when running tests with --nocapture). Consider changing path_to_string_lossy to only warn when the conversion is actually lossy (e.g., when to_string_lossy() returns an owned Cow, or when path.to_str() is None).
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
🎯 What: The testing gap addressed for
path_to_string_lossyutility function.📊 Coverage: Added tests for both valid UTF-8 paths and invalid UTF-8 paths (verifying replacement character insertion).
✨ Result: Increased test coverage for path utility functions in
src/utilities.rs.PR created automatically by Jules for task 16782817780805708676 started by @bashandbone