Skip to content

Commit 393fc93

Browse files
committed
[Paths] Remove lower casing of paths which can cause issues on case sensitive platforms
1 parent ccca5aa commit 393fc93

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

Sharpmake.UnitTests/UtilTest.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,27 @@ public void LeavesEmptyStringsUntouched()
6262
public void LeavesVariablesUntouched()
6363
{
6464
string expectedResult = "$(Console_SdkPackagesRoot)";
65-
if (!Util.IsRunningInMono())
66-
expectedResult = expectedResult.ToLower();
6765
Assert.That(Util.PathMakeStandard("$(Console_SdkPackagesRoot)"), Is.EqualTo(expectedResult));
6866
}
6967

7068
[Test]
7169
public void ProcessesPathWithTrailingBackslash()
7270
{
7371
string expectedResult = Path.Combine("rd", "project", "dev", "projects", "sharpmake", "..", "..", "extern", "Geometrics");
74-
if (!Util.IsRunningInMono())
75-
expectedResult = expectedResult.ToLower();
7672
Assert.That(Util.PathMakeStandard(@"rd\project\dev\projects\sharpmake\..\..\extern\Geometrics\"), Is.EqualTo(expectedResult));
7773
}
7874

7975
[Test]
8076
public void ProcessesPathWithTrailingBackslashAndADot()
8177
{
8278
var expectedResult = Path.Combine("rd", "project", "dev", "projects", "sharpmake", "..", "..", "extern", "Microsoft.CNG", "Lib");
83-
if (!Util.IsRunningInMono())
84-
expectedResult = expectedResult.ToLower();
8579
Assert.That(Util.PathMakeStandard(@"rd\project\dev\projects\sharpmake\..\..\extern\Microsoft.CNG\Lib\"), Is.EqualTo(expectedResult));
8680
}
8781

8882
[Test]
8983
public void ProcessesPathWithMultipleTrailingBackslashes()
9084
{
9185
var expectedResult = Path.Combine("rd", "project", "dev", "projects", "sharpmake", "..", "..", "extern", "Microsoft.CNG", "Lib");
92-
if (!Util.IsRunningInMono())
93-
expectedResult = expectedResult.ToLower();
9486
Assert.That(Util.PathMakeStandard(@"rd\project\dev\projects\sharpmake\..\..\extern\Microsoft.CNG\Lib\\\"), Is.EqualTo(expectedResult));
9587
}
9688

@@ -108,9 +100,6 @@ public void ProcessesWithAListAsArgument()
108100
};
109101
var expectedList = listString;
110102

111-
if (!Util.IsRunningInMono())
112-
expectedList = expectedList.Select((p) => p.ToLower()).ToList();
113-
114103
Util.PathMakeStandard(listString);
115104

116105
Assert.AreEqual(expectedList, listString);
@@ -753,7 +742,7 @@ public void CanBeComputedFromOutputPath()
753742
var referenceFileFullPath = outputFileFullPath.ReplaceHeadPath(outputPath, referencePath);
754743

755744
Assert.That(referenceFileFullPath, Is.EqualTo(
756-
Util.PathMakeStandard(@"F:\OnePath\With\Reference\with\a\file.cs", false)));
745+
Util.PathMakeStandard(@"F:\OnePath\With\Reference\with\a\file.cs")));
757746
}
758747

759748
[Test]
@@ -766,7 +755,7 @@ public void IsCaseInsensitiveButPreservesCase()
766755
var referenceFileFullPath = outputFileFullPath.ReplaceHeadPath(outputPath, referencePath);
767756

768757
Assert.That(referenceFileFullPath, Is.EqualTo(
769-
Util.PathMakeStandard(@"F:\OnePath\with\Reference\with\a\File.cs", false)));
758+
Util.PathMakeStandard(@"F:\OnePath\with\Reference\with\a\File.cs")));
770759
}
771760

772761
[Test]
@@ -779,7 +768,7 @@ public void AcceptsOutputPathWithoutTrailingSlash()
779768
var referenceFileFullPath = outputFileFullPath.ReplaceHeadPath(outputPath, referencePath);
780769

781770
Assert.That(referenceFileFullPath, Is.EqualTo(
782-
Util.PathMakeStandard(@"F:\OnePath\With\Reference\with\a\file.cs", false)));
771+
Util.PathMakeStandard(@"F:\OnePath\With\Reference\with\a\file.cs")));
783772
}
784773
}
785774

@@ -1000,7 +989,7 @@ public void PathGetAbsoluteStringsReturnList()
1000989
string filename = Path.GetFileName(mockPath);
1001990
string stringsSource = Path.GetDirectoryName(mockPath);
1002991

1003-
Assert.AreEqual(Path.Combine(stringsSource.ToLower(), filename), Util.PathGetAbsolute(stringsSource, new Strings(filename))[0]);
992+
Assert.AreEqual(Path.Combine(stringsSource, filename), Util.PathGetAbsolute(stringsSource, new Strings(filename))[0]);
1004993

1005994
File.Delete(mockPath);
1006995
}
@@ -1015,7 +1004,7 @@ public void PathGetAbsoluteStringsReturnString()
10151004
var separator = Path.DirectorySeparatorChar;
10161005
string stringsSource = mockPath.Substring(0, mockPath.IndexOf(separator));
10171006
string stringsDest = mockPath.Substring(mockPath.IndexOf(separator, mockPath.IndexOf(separator) + 1));
1018-
string expectedOutputPath = stringsSource.ToLower() + stringsDest;
1007+
string expectedOutputPath = stringsSource + stringsDest;
10191008
//v
10201009
Assert.AreEqual(expectedOutputPath, Util.PathGetAbsolute(stringsSource, stringsDest));
10211010

@@ -1032,7 +1021,6 @@ public void ResolvePathString()
10321021
Strings paths = new Strings(Path.GetDirectoryName(mockPath));
10331022
string root = mockPath.Substring(0, mockPath.IndexOf(Path.DirectorySeparatorChar));
10341023
Strings expectedOutputPath = new Strings(paths.Select((p) => Path.Combine(root, p)));
1035-
expectedOutputPath.ToLower();
10361024

10371025
Util.ResolvePath(root, ref paths);
10381026

@@ -1057,7 +1045,7 @@ public void ResolvePathOrderableString()
10571045
mockPath3.Substring(mockPath3.IndexOf(Path.DirectorySeparatorChar)),
10581046
};
10591047
string root = mockPath1.Substring(0, mockPath1.IndexOf(Path.DirectorySeparatorChar));
1060-
OrderableStrings expectedOutputPath = new OrderableStrings(paths.Select((p) => (root + p).ToLower()));
1048+
OrderableStrings expectedOutputPath = new OrderableStrings(paths.Select((p) => (root + p)));
10611049

10621050
Util.ResolvePath(root, ref paths);
10631051
expectedOutputPath.Sort();
@@ -1114,8 +1102,8 @@ public void PathGetRelativeOrderableStrings()
11141102
Util.PathMakeStandard(stringsDest);
11151103
OrderableStrings listResult = Util.PathGetRelative(stringsSource, stringsDest, false);
11161104

1117-
Assert.AreEqual(Util.PathMakeStandard(@"..\Sharpmake.Generators\Generic", !Util.IsRunningInMono()), listResult[0]);
1118-
Assert.AreEqual(Util.PathMakeStandard(@"subdir\test.txt", !Util.IsRunningInMono()), listResult[1]);
1105+
Assert.AreEqual(Util.PathMakeStandard(@"..\Sharpmake.Generators\Generic"), listResult[0]);
1106+
Assert.AreEqual(Util.PathMakeStandard(@"subdir\test.txt"), listResult[1]);
11191107
Assert.AreEqual("test2.txt", listResult[2]);
11201108
}
11211109

@@ -1192,11 +1180,11 @@ public void GetConvertedRelativePathRoot()
11921180
var root = @"C:\SharpMake\sharpmake\Sharpmake.Application\Properties";
11931181

11941182
var newRelativeToFullPath = "";
1195-
Assert.AreEqual(Path.Combine(absolutePath.ToLower(), fileName), Util.GetConvertedRelativePath(absolutePath, fileName, newRelativeToFullPath, false, null));
1183+
Assert.AreEqual(Path.Combine(absolutePath, fileName), Util.GetConvertedRelativePath(absolutePath, fileName, newRelativeToFullPath, false, null));
11961184
Assert.AreEqual(mockPath, Util.GetConvertedRelativePath(absolutePath, mockPath, newRelativeToFullPath, false, root));
1197-
Assert.AreEqual(Path.Combine(absolutePath.ToLower(), fileName), Util.GetConvertedRelativePath(absolutePath, fileName, newRelativeToFullPath, false, ""));
1185+
Assert.AreEqual(Path.Combine(absolutePath, fileName), Util.GetConvertedRelativePath(absolutePath, fileName, newRelativeToFullPath, false, ""));
11981186
Assert.AreEqual(absolutePath, Util.GetConvertedRelativePath(absolutePath, null, newRelativeToFullPath, false, null));
1199-
Assert.AreEqual(Path.Combine(root.ToLower(), Path.GetTempPath()), Util.GetConvertedRelativePath(root, Path.GetTempPath(), newRelativeToFullPath, false, null));
1187+
Assert.AreEqual(Path.Combine(root, Path.GetTempPath()), Util.GetConvertedRelativePath(root, Path.GetTempPath(), newRelativeToFullPath, false, null));
12001188

12011189
File.Delete(mockPath);
12021190
}

Sharpmake/PathUtil.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,10 @@ public static void PathMakeStandard(IList<string> paths)
4040
}
4141

4242
public static string PathMakeStandard(string path)
43-
{
44-
return PathMakeStandard(path, !Util.IsRunningOnUnix());
45-
}
46-
47-
public static string PathMakeStandard(string path, bool forceToLower)
4843
{
4944
// cleanup the path by replacing the other separator by the correct one for this OS
5045
// then trim every trailing separators
51-
var standardPath = path.Replace(OtherSeparator, Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
52-
return forceToLower ? standardPath.ToLower() : standardPath;
46+
return path.Replace(OtherSeparator, Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
5347
}
5448

5549
public static string EnsureTrailingSeparator(string path)
@@ -797,9 +791,9 @@ internal static string ConvertToMountedUnixPath(string path)
797791
public static string ReplaceHeadPath(this string fullInputPath, string inputHeadPath, string replacementHeadPath)
798792
{
799793
// Normalize paths before comparing and combining them, to prevent false mismatch between '\\' and '/'.
800-
fullInputPath = Util.PathMakeStandard(fullInputPath, false);
801-
inputHeadPath = Util.PathMakeStandard(inputHeadPath, false);
802-
replacementHeadPath = Util.PathMakeStandard(replacementHeadPath, false);
794+
fullInputPath = PathMakeStandard(fullInputPath);
795+
inputHeadPath = PathMakeStandard(inputHeadPath);
796+
replacementHeadPath = PathMakeStandard(replacementHeadPath);
803797

804798
inputHeadPath = EnsureTrailingSeparator(inputHeadPath);
805799

0 commit comments

Comments
 (0)