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

combinePaths with no trimming operations #695

Merged
merged 1 commit into from
Mar 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/FakeLib/EnvironmentHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ let environVar name = Environment.GetEnvironmentVariable name

/// Combines two path strings using Path.Combine
let inline combinePaths path1 (path2 : string) = Path.Combine(path1, path2.TrimStart [| '\\'; '/' |])
let inline combinePathsNoTrim path1 path2 = Path.Combine(path1, path2)

/// Combines two path strings using Path.Combine
let inline (@@) path1 path2 = combinePaths path1 path2
let inline (</>) path1 path2 = combinePathsNoTrim path1 path2

/// Retrieves all environment variables from the given target
let environVars target =
Expand Down
51 changes: 51 additions & 0 deletions src/test/Test.FAKECore/EnvironmentHelperSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Fake;
using Machine.Specifications;

namespace Test.FAKECore
{
public class when_combining_paths
{
It should_strip_leading_slashes_when_using_combinePaths =
() =>
{
var testValues = new List<string[]> {
new[]{"/test/path", "/of/the/thing", "/test/path" + Path.DirectorySeparatorChar + "of/the/thing"},
new[]{"/test/path", "of/the/thing", "/test/path" + Path.DirectorySeparatorChar + "of/the/thing"},
};

if (Path.VolumeSeparatorChar != Path.DirectorySeparatorChar)
{
var path2 = "X" + Path.VolumeSeparatorChar + "/test";
testValues.Add(new[]{"/test/path", path2, path2});
}

foreach (var item in testValues)
{
EnvironmentHelper.combinePaths(item[0], item[1]).ShouldEqual(item[2]);
}
};

It should_work_like_path_dot_combine_when_using_combinePathsNoTrim =
() =>
{
var testValues = new List<string[]> {
new[]{"/test/path", "/of/the/thing", "/of/the/thing"},
new[]{"/test/path", "of/the/thing", "/test/path" + Path.DirectorySeparatorChar + "of/the/thing"},
};

if (Path.VolumeSeparatorChar != Path.DirectorySeparatorChar)
{
var path2 = "X" + Path.VolumeSeparatorChar + "/test";
testValues.Add(new[]{"/test/path", path2, path2});
}

foreach (var item in testValues)
{
EnvironmentHelper.combinePathsNoTrim(item[0], item[1]).ShouldEqual(item[2]);
}
};
}
}
1 change: 1 addition & 0 deletions src/test/Test.FAKECore/Test.FAKECore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="SideBySideSpecification\ReferencesScanningSpecs.cs" />
<Compile Include="SideBySideSpecification\SpecsRemovementSpecs.cs" />
<Compile Include="StringHelperSpecs.cs" />
<Compile Include="EnvironmentHelperSpecs.cs" />
<Compile Include="MessageFiles\MessageFileSpecs.cs" />
<Compile Include="ConfigFiles\ConfigSpecs.cs" />
<Compile Include="AssemblyInfoSpecs.cs" />
Expand Down