diff --git a/src/app/FakeLib/EnvironmentHelper.fs b/src/app/FakeLib/EnvironmentHelper.fs index 8c5dcee01f6..d52ee3def69 100644 --- a/src/app/FakeLib/EnvironmentHelper.fs +++ b/src/app/FakeLib/EnvironmentHelper.fs @@ -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 = diff --git a/src/test/Test.FAKECore/EnvironmentHelperSpecs.cs b/src/test/Test.FAKECore/EnvironmentHelperSpecs.cs new file mode 100644 index 00000000000..9547876171a --- /dev/null +++ b/src/test/Test.FAKECore/EnvironmentHelperSpecs.cs @@ -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 { + 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 { + 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]); + } + }; + } +} diff --git a/src/test/Test.FAKECore/Test.FAKECore.csproj b/src/test/Test.FAKECore/Test.FAKECore.csproj index 15a94b0f76f..c45fa5f3dc1 100644 --- a/src/test/Test.FAKECore/Test.FAKECore.csproj +++ b/src/test/Test.FAKECore/Test.FAKECore.csproj @@ -108,6 +108,7 @@ +