Skip to content

Commit 612e3df

Browse files
committed
Use DotnetBuildCommand instead of BuildCommand for It_does_not_download_desktop_targeting_packs_on_unix. Change test folder name hashing for TestAssetsManager as the previous one didn't hash it well enough including the identifier (even with different identifiers, the values were the same).
1 parent 8f2199b commit 612e3df

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

test/EndToEnd.Tests/GivenWeWantToRequireWindowsForDesktopApps.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void It_does_not_download_desktop_targeting_packs_on_unix()
2020

2121
var testInstance = testProjectCreator.Create(_testAssetsManager);
2222

23-
new BuildCommand(testInstance)
23+
new DotnetBuildCommand(testInstance)
2424
.Execute().Should().Pass();
2525

2626
string packagesPath = Path.Combine(testInstance.TestRoot, "packages");

test/EndToEnd.Tests/ProjectBuildTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,8 @@ private void TestTemplateCreateAndBuild(string templateName, bool build = true,
459459

460460
private TestDirectory InstantiateProjectTemplate(string templateName, string language = "", bool withNoRestore = true)
461461
{
462-
var directory = _testAssetsManager.CreateTestDirectory(
463-
identifier: string.IsNullOrWhiteSpace(language)
464-
? templateName
465-
: $"{templateName}[{language}]");
462+
var identifier = string.IsNullOrWhiteSpace(language) ? templateName : $"{templateName}[{language}]";
463+
var directory = _testAssetsManager.CreateTestDirectory(identifier: identifier);
466464
string projectDirectory = directory.Path;
467465

468466
string[] newArgs = [

test/Microsoft.NET.TestFramework/TestAssetsManager.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,15 @@ public static string GetTestDestinationDirectoryPath(
187187
// We need to ensure the directory name isn't over 24 characters in length
188188
if (directoryName.Length > 24)
189189
{
190-
using (var sha256 = SHA256.Create())
191-
{
192-
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(directoryName.ToString()));
190+
var hash = GetTruncatedHash(directoryName.ToString(), HashAlgorithmName.SHA256);
193191

194-
directoryName = directoryName.Remove(13, directoryName.Length - 13)
195-
.Append("---");
192+
directoryName = directoryName.Remove(13, directoryName.Length - 13)
193+
.Append("---");
196194

197-
directoryName = directoryName.AppendFormat("{0:X2}", hash[0])
198-
.AppendFormat("{0:X2}", hash[1])
199-
.AppendFormat("{0:X2}", hash[2])
200-
.AppendFormat("{0:X2}", hash[3]);
201-
}
195+
directoryName = directoryName.AppendFormat("{0:X2}", hash[0])
196+
.AppendFormat("{0:X2}", hash[1])
197+
.AppendFormat("{0:X2}", hash[2])
198+
.AppendFormat("{0:X2}", hash[3]);
202199
}
203200

204201
var directoryPath = Path.Combine(baseDirectory, directoryName.ToString());
@@ -215,6 +212,25 @@ public static string GetTestDestinationDirectoryPath(
215212
#endif
216213

217214
return directoryPath;
215+
216+
// From: https://github.com/dotnet/arcade/blob/3b7e3a1a6d626eb51c5528987c1af484a98e4b5c/src/Microsoft.DotNet.Build.Tasks.Workloads/src/Utils.cs#L22
217+
static string GetTruncatedHash(string value, HashAlgorithmName hashName)
218+
{
219+
byte[] bytes = Encoding.UTF8.GetBytes(value);
220+
#pragma warning disable SYSLIB0045 // Cryptographic factory methods accepting an algorithm name are obsolete. Use the parameterless Create factory method on the algorithm type instead.
221+
HashAlgorithm algorithm = HashAlgorithm.Create(hashName.Name);
222+
#pragma warning restore SYSLIB0045
223+
StringBuilder sb = new();
224+
225+
foreach (byte b in algorithm.ComputeHash(bytes))
226+
{
227+
sb.Append(b.ToString("x2"));
228+
}
229+
230+
string result = sb.ToString();
231+
232+
return result.Substring(0, 32);
233+
}
218234
}
219235
}
220236
}

0 commit comments

Comments
 (0)