-
Notifications
You must be signed in to change notification settings - Fork 267
Don't allow files and directories with the same name #322
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
Don't allow files and directories with the same name #322
Conversation
| [Test] | ||
| public void CleanPath_DriveRoot_PreserveTrailingSlash() | ||
| { | ||
| Assert.AreEqual(@"c:\", @"c:\".CleanPath()); |
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.
It may seem a little silly / overly verbose, but I think I'd prefer if this was broken up into three lines for AAA (no comments for each section though).
You'll also need XFS.Path for Linux shenanigans.
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.
AAA really only makes sense in situations where you're testing mutable state. Arrange the state. Act on state with impure operation. Assert result.
This is the closest approximation I can make:
// Arrange
var x = @"c:\";
// Act
var y = x.CleanPath();
// Assert
Assert.AreEqual(@"c:\", y);XFS.Path noted.
TestingHelpers/MockFileSystem.cs
Outdated
|
|
||
| private void SetEntry(string path, MockFileData mockFile) | ||
| { | ||
| path = FixPath(path, true); |
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.
I'm personally a fan of pure/functional methods where possible, so I think I'd rather see this be immutable.
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.
You mean overwriting the value of the local variable? I'm not a fan of that either. I've inline-ed those in places and will continue to.
|
Thanks for working on this @rkoeninger. I'm really curious what you come up for this one. In the spirit of rapid feedback, I left a couple comments. |
…'t end with slashes
|
Re: 0c6879a |
MockFileSystem.FileExists trims trailing slashes before checking
…ith the same name
…stem.IO.Abstractions into remove-trailing-slashes
|
Got the tests passing on Windows, but plenty of failures on Linux. How does one normally work on Unix-specific failures? Startup a VM? I'll try that tomorrow. |
I think the test is OK. Given what it's doing, and the name of the test, it's verifying that MoveTo does a replace, which is a valuable test. I do not however see a test that just simply test moving a file to another directory where the file does not already exist.
I have always used a docker container to text Linux tests locally. You can mount the System.IO.Abstractions source folder and run dotnet test. |
Added UnixOnlyAttribute, UnixSpecifics to mirror WindowsOnlyAttribute/Specifics
|
@jpreese About that test (0c6879a): I wasn't questioning the existence of the test, but the way it was written. It started to fail after I made my changes, I believe because it was depending on the ability to have a file and directory with the same name exist at the same time. That commit contains the one-line fix that fixes what may have just been a typo. I get worried when I have to change tests to make them pass, and they're not changes I expected to have to make. |
|
For that test, yeah I was agreeing with the name and how it was written.
So if I'm understanding this right, the fault here is that we're doing .AddDirectory and not adding a File. The test is validating that we can replace a file, and the way its written now (in the PR), does not do that since destinationFolder is empty. The test you've written validates that we can Move a file (which I think we need, because for some reason we don't have it). There should be a test for move to an empty directory, and a test for a move to a source that already exists. |
|
@jpreese Ok, so the original test was split into 3 tests, and added |
|
I think this is pretty much ready. Does anyone have any other comments/concerns? |
…stem.IO.Abstractions into remove-trailing-slashes
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.
Some minor nits – otherwise LGTM
| var fileSystem = new MockFileSystem(); | ||
| var path2 = XFS.Path(path); | ||
| fileSystem.AddDirectory(path2); | ||
| fileSystem.FileExists(path2); |
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.
Assert on return value here?
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.
Whoops, assert added
| using XFS = MockUnixSupport; | ||
|
|
||
| [TestFixture] | ||
| public class StringExtensions |
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.
Add Tests suffix?
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.
Sure
|
|
||
| if (MockUnixSupport.IsUnixPlatform() | ||
| && (path[0] == Path.DirectorySeparatorChar || path[0] == Path.AltDirectorySeparatorChar) | ||
| && trimmed == "") |
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.
string.Empty?
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.
Eh, I prefer "" to string.Empty. 2 chars vs 12.
|
@jpreese for a last pair of eyes 👀 |
Used WindowsOnly on existing tests
|
I had copy/paste/modified the Minor improvement would be to name the files like |
| fileSystem.AddFile(additionalFilePath, new MockFileData(string.Empty)); | ||
| fileSystem.AddFile(XFS.Path(@"c:\a\a\c.gifx.xyz"), new MockFileData(string.Empty)); | ||
| fileSystem.AddFile(XFS.Path(@"c:\a\a\c.gifx\xyz"), new MockFileData(string.Empty)); | ||
| fileSystem.AddFile(XFS.Path(@"c:\a\a\c.gifz\xyz"), new MockFileData(string.Empty)); |
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.
Why did we change the test data for this?
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.
That test depended on the ability to have a file and directory with the same name, perhaps unintentionally (?) But that's no longer allowed, per this PR. Specific commit: 9fad978
| } | ||
|
|
||
| [Test] | ||
| [WindowsOnly(WindowsSpecifics.StrictPathRules + "; Path.GetInvalidChars() does not return anything on Mono")] |
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.
I think the StrictPathRules const is good enough here (and the others)
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.
Ok, I'll cut of the rest.
|
Well, I started a review but then realized this PR is pretty large.. and I'm a little uneasy with how many tests were changing. It's going to take me a bit to look this over. |
…stem.IO.Abstractions into remove-trailing-slashes
|
@jpreese @fgreinacher I understand if the size of this PR is discomforting, but it's been 6 weeks and I've had to back merge 6 times. If we're not going to merge it soon, it will likely never get merged and we might as well close it. Same for #327. I don't want to throw away my work, but there's a point where I'd rather just not be hanging. |
fgreinacher
left a comment
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.
I don’t like that we have to adapt so many tests, but all of the adaptations seem to be OK to me.
|
Sorry @rkoeninger and thanks for the trigger :) @jpreese I’m fine merging this as it simplifies and fixes several things. |
…stem.IO.Abstractions into remove-trailing-slashes
|
@jpreese |
|
@fgreinacher @jpreese 🚢 ? |
|
OK, I’m gonna merge this now - we have no negative feedback except the amount of tests this impacts - but as I mentioned above all the changes look unproblematic to me. Thanks again for working on this @rkoeninger! |
|
@fgreinacher No prob, thanks for getting this merged |
Fixes #208
Fixes #223
Fixes #318
Effects of this PR:
MockFileSystemno longer have trailing slashes unless:Directory.GetFiles()won't have trailing slashes.UnixOnlyAttribute/UnixSpecificswere added to mirrorWindowsOnlyAttribute/WindowsSpecifics.TrimSlasheshelper, increase coverage of existing functionality and confirm that issues MockFileSystem should not require trailing slash for directories #208 and MockFileSystem.File.Exists throws NullReferenceException #233 have been addressed as well.