-
Notifications
You must be signed in to change notification settings - Fork 266
Description
Describe the bug
Forward and backward slashes are not uniformly handled across operating systems; specifically Linux and Windows.
To Reproduce
Example unit test:
[Test, AutoMockData]
public void Return_app_data_dir_location_if_base_directory_location_not_present(
[Frozen] IAppContext appContext,
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen] IAppPaths paths,
ConfigurationFinder sut)
{
paths.ConfigPath.Returns("app/data/recyclarr.yml");
var path = sut.FindConfigPath();
path.Should().EndWith(@"app/data/recyclarr.yml");
}
Expected behavior
The reproducible example above is not meant to be run directly. It's just to demonstrate how I like to handle paths.
What I expect is that, when hard-coded paths are provided, that any \\
are converted to /
and /
is used on all platforms. The one guarantee we have between all operating systems is that forward-slash works, even on Windows. When MockFileSystem
is used, it should have logic to convert paths for me.
The workaround right now is to use _fs.Path.Combine()
, but this is syntactically tedious. I deal with hard-coded paths rarely, if not never in production code. They're used extremely often and very useful in unit tests. So I think it makes sense to have some special handling for "path normalization" for purposes of testing.
If there is risk of this breaking some use cases, I'd be happy with a method on MockFileSystem
to enable this globally or per-instance.