Skip to content

Commit

Permalink
Merge pull request #695 from sillyotter/NewPathCombineOperator
Browse files Browse the repository at this point in the history
combinePaths with no trimming operations
  • Loading branch information
forki committed Mar 12, 2015
2 parents 225d1c3 + d72a785 commit 3cb76f9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
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

0 comments on commit 3cb76f9

Please sign in to comment.