-
Notifications
You must be signed in to change notification settings - Fork 585
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
Modified combinePaths to work like Path.Combine to fix fsharp/FAKE#670 #692
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Linq; | ||
using Fake; | ||
using Machine.Specifications; | ||
|
||
namespace Test.FAKECore | ||
{ | ||
public class when_combining_paths | ||
{ | ||
It should_act_as_path_combine = | ||
() => { | ||
var testValues = new []{ | ||
new []{"c:\\test", "dir\\asdf"}, | ||
new []{"\\test", "dir\\asdf"}, | ||
new []{"test", "dir\\asdf"}, | ||
new []{"/test", "dir/asdf"}, | ||
new []{"/test", "/dir/asdf"}, | ||
new []{"c:\\test", "d:\\dir\\asdf"}, | ||
new []{"/asdf/asdf/asdf/", "/asdf/asdf"}, | ||
new []{"c:\\test", "\\\\dir\\asdf"}, | ||
new []{"c:\\test", "/dir\\asdf"}, | ||
}; | ||
|
||
foreach(var item in testValues) | ||
{ | ||
EnvironmentHelper.combinePaths(item[0], item[1]) | ||
.ShouldEqual(System.IO.Path.Combine(item[0], item[1])); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is this change needed?
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.
Without that change several of the DeploymentHelper tests failed. With the new combinePath using just a straight call to Path.Combine, app @@ "/active/.nupkg" just returns "/active/.nupkg". And the tests will fail as there isn't anything on the filesystem at /active/whatever. The leading forward slash implies its a root directory, and Path.Combine says if path2 is a root, just return path2.
In effect, saying Path.Combine("something", "/active/_.nupkg") is the same as saying Path.Combine("something", "C:\active_.nupkg") and right or not, that is supposed to return C:\active*.nupkg. There is no need to add the separator character to the beginning of path2 (the whole point of Path.Combine is to add that for you), and on linux and very likely osx, its also true that that separator can also be interpreted as a root directory indicator. Its true that its a bit confusing when thinking of @@ as +, but the original stripping of the leading / caused things to work differently on windows and linux.
The original issue I raised was presented as a question because I was unsure about fixing it as I expected that such a change as this would break more than it did. I'm guessing most everyone uses @@ as if it were a + operator, and don't fully realize its a Path.Combine under the hood and what that means, but it did cause different behavior cross platforms.
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.
mhm yeah. I assume this is a correct fix, but will break tons of stuff.
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.
Well, it didn't break any of the unit tests, but I certainly admit it is a big change as its used quite a lot and will possibly break scripts in the wild. The issue originally raised is still present though. Passing in a full path as path2 on windows just returns the full path, doing so on Linux results in a really long nested wrong path. It is of course your decision to make. Accepting the change would at least require some important wording in the next release notes. On windows, it shouldn't make any difference, but it might break some things on linux that are working around the current behavior, or that expected this behavior.
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.
how about introducing the
(/)
operator with correct behaviour and slowly making the @@ obsolete?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's a comment isn't it?
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.
damn it. I remember I saw an operator somewhere which did the same as @@. I'd like to use the same. But can't remember where.
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 thought I saw one in a previous issue thread, but I couldn't find it either. From when I was first searching for why @@ behaved the way it did.
I was thinking @@+ as it implies its like the old @@ but with more, but its ugly. Or something more like ++ but that smells of plain concatenation. <+> smells of haskell monad combinators but isn't bad. :: isn't overrideable. Nor is anything \ related. |+ might work. In any event, ive got it set to @@+ in my code, but if you come up with something better, let me know and I'll swap it out. I'm still working on a unit test that takes into consideration the different behaviors of Path.Combine under different platforms.
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.
@mausch found it: http://stackoverflow.com/questions/2812084/overload-operator-in-f
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.
there strange implementations of
(/)
and also(</>)