I need a few examples of non-utf8 OsString/PathBuf for my unit tests

I am writing a program that behaves differently depends on whether the input string is valid UTF-8. I can test the "valid UTF-8" but can't do the "invalid UTF-8" branch for obvious reason.

I tried to googled them, but the results are not helpful at all.

2 Likes

Yeah, that's tricky, because there's no cross-platform way to create a non-utf8 OsString, every unhappy string is unhappy in its own way.

See how this case is tested in Cargo: https://github.com/rust-lang/cargo/pull/9226/files#diff-9977238c61100eb9f319febd88e2434b304ac401f0da3b50d00d7c91de319e2fR2957-R2966

5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.