Skip to content
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

Fix file operations that fail when used with relative paths #407

Merged
merged 4 commits into from
Nov 28, 2018
Merged

Fix file operations that fail when used with relative paths #407

merged 4 commits into from
Nov 28, 2018

Conversation

fgreinacher
Copy link
Contributor

@fgreinacher fgreinacher commented Nov 27, 2018

Root cause for the problems is wleader@95ead3a#diff-e76db4b13ed41e41943b80f8f1075287 where we started using Path.GetDirectoryName to get the parent directory, but unfortunately this method returns an empty string when the path does not contain directory information (e.g. a plain file name).

The changes here make the paths absolute before passing them on to Path.GetDirectoryName.

Fixes #404 and #401

@fgreinacher fgreinacher changed the title WIP: Add tests for file operations failing when used with relative paths WIP: Fix file operations that fail when used with relative paths Nov 27, 2018
@fgreinacher fgreinacher changed the title WIP: Fix file operations that fail when used with relative paths Fix file operations that fail when used with relative paths Nov 27, 2018
@fgreinacher
Copy link
Contributor Author

@rkoeninger @jpreese @robkeim 👀❓

@@ -155,12 +155,12 @@ public void MockFile_Create_ShouldThrowDirectoryNotFoundExceptionIfCreatingAndPa
{
// Arrange
var fileSystem = new MockFileSystem();
var file = XFS.Path("C:\\path\\NotFound.ext");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was not normalizing the path which caused test failures on Unix, so I fixed this.


// Assert
Assert.IsFalse(fileSystem.Directory.Exists("C:\\path"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't belong in this test case so I decided to remove it.

@@ -249,14 +249,25 @@ public void MockFile_Open_ShouldThrowDirectoryNotFoundExceptionIfFileModeCreateA
{
// Arrange
var fileSystem = new MockFileSystem();
var file = XFS.Path("C:\\path\\NotFound.ext");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above


// Assert
Assert.IsFalse(fileSystem.Directory.Exists("C:\\path"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

@rkoeninger
Copy link
Contributor

@fgreinacher Looks good to me!

Copy link
Contributor

@robkeim robkeim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, thanks @fgreinacher!

@fgreinacher fgreinacher merged commit ec1b673 into TestableIO:master Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants