diff --git a/src/Build.UnitTests/BinaryLogger_Tests.cs b/src/Build.UnitTests/BinaryLogger_Tests.cs index 098d237bd8e..ea4d6cba059 100644 --- a/src/Build.UnitTests/BinaryLogger_Tests.cs +++ b/src/Build.UnitTests/BinaryLogger_Tests.cs @@ -171,9 +171,55 @@ public void TestBinaryLoggerRoundtrip(string projectText, BinlogRoundtripTestRep var parallelExpected = parallelFromBuildText.ToString(); var parallelActual = parallelFromPlaybackText.ToString(); + parallelActual = RemoveNonDeterministicParallelOutput(parallelActual); + parallelExpected = RemoveNonDeterministicParallelOutput(parallelExpected); + parallelActual.ShouldContainWithoutWhitespace(parallelExpected); } + private static string RemoveNonDeterministicParallelOutput(string text) + { + if (string.IsNullOrEmpty(text)) + { + return text; + } + + using StringReader reader = new StringReader(text); + StringBuilder builder = new StringBuilder(text.Length); + string line; + bool skipTargetOutputItems = false; + + while ((line = reader.ReadLine()) is not null) + { + if (line.StartsWith("BinLogFilePath=", StringComparison.Ordinal) + || line.StartsWith("CurrentUICulture=", StringComparison.Ordinal) + || line.StartsWith("CurrentCulture=", StringComparison.Ordinal)) + { + continue; + } + + if (line.StartsWith("Target output items:", StringComparison.Ordinal)) + { + skipTargetOutputItems = true; + continue; + } + + if (skipTargetOutputItems) + { + if (string.IsNullOrWhiteSpace(line) || char.IsWhiteSpace(line[0])) + { + continue; + } + + skipTargetOutputItems = false; + } + + builder.AppendLine(line); + } + + return builder.ToString(); + } + /// /// This test validate that binlog file content is identical upon replaying. /// The identity can be defined via 3 ways: @@ -908,9 +954,9 @@ public void ProcessParameters_DuplicatePaths_CaseInsensitive() [Fact] public void ProcessParameters_MixedConfigsWithDuplicates_HandledCorrectly() { - var result = BinaryLogger.ProcessParameters(new[] { - "1.binlog", - "2.binlog;ProjectImports=None", + var result = BinaryLogger.ProcessParameters(new[] { + "1.binlog", + "2.binlog;ProjectImports=None", "1.binlog;ProjectImports=None" // Different config but same path - filtered as duplicate }); diff --git a/src/Tasks.UnitTests/OutputPathTests.cs b/src/Tasks.UnitTests/OutputPathTests.cs index b1b897c20dc..338c852caa3 100644 --- a/src/Tasks.UnitTests/OutputPathTests.cs +++ b/src/Tasks.UnitTests/OutputPathTests.cs @@ -65,7 +65,7 @@ public void BothBaseOutputPathAndOutputPathWereNotSpecified() project.Build(new MockLogger(_output)).ShouldBeFalse(); // Assert - project.GetPropertyValue("BaseOutputPath").ShouldBe(baseOutputPath + '\\'); + project.GetPropertyValue("BaseOutputPath").ShouldBe(baseOutputPath.WithTrailingSlash()); project.GetPropertyValue("BaseOutputPathWasSpecified").ShouldBe(string.Empty); project.GetPropertyValue("_OutputPathWasMissing").ShouldBe("true"); } diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index 4db3d552c7e..177b84f0a87 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -149,17 +149,17 @@ Copyright (C) Microsoft Corporation. All rights reserved. Debug $(Configuration) - bin\ - $(BaseOutputPath)\ - $(BaseOutputPath)$(Configuration)\ - $(BaseOutputPath)$(PlatformName)\$(Configuration)\ - $(OutputPath)\ - - obj\ - $(BaseIntermediateOutputPath)\ - $(BaseIntermediateOutputPath)$(Configuration)\ - $(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\ - $(IntermediateOutputPath)\ + bin$([System.IO.Path]::DirectorySeparatorChar) + $(BaseOutputPath)$([System.IO.Path]::DirectorySeparatorChar) + $(BaseOutputPath)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar) + $(BaseOutputPath)$(PlatformName)$([System.IO.Path]::DirectorySeparatorChar)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar) + $(OutputPath)$([System.IO.Path]::DirectorySeparatorChar) + + obj$([System.IO.Path]::DirectorySeparatorChar) + $(BaseIntermediateOutputPath)$([System.IO.Path]::DirectorySeparatorChar) + $(BaseIntermediateOutputPath)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar) + $(BaseIntermediateOutputPath)$(PlatformName)$([System.IO.Path]::DirectorySeparatorChar)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar) + $(IntermediateOutputPath)$([System.IO.Path]::DirectorySeparatorChar) diff --git a/src/UnitTests.Shared/ObjectModelHelpers.cs b/src/UnitTests.Shared/ObjectModelHelpers.cs index f7867edce49..3da4e352a23 100644 --- a/src/UnitTests.Shared/ObjectModelHelpers.cs +++ b/src/UnitTests.Shared/ObjectModelHelpers.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -588,7 +589,7 @@ public static void AssertFileExistsInTempProjectDirectory(string fileRelativePat /// public static string CleanupFileContents([StringSyntax(StringSyntaxAttribute.Xml)] string projectFileContents) { - StringBuilder temp = new (projectFileContents); + StringBuilder temp = new(projectFileContents); // Replace reverse-single-quotes with double-quotes. temp.Replace('`', '"'); @@ -2005,11 +2006,14 @@ public static void ClearDirtyFlag(ProjectRootElement project) /// A representing the amount of time to sleep. public static string GetSleepCommand(TimeSpan timeSpan) { + string sleepArgument = NativeMethodsShared.IsWindows + ? timeSpan.TotalMilliseconds.ToString(CultureInfo.InvariantCulture) + : timeSpan.TotalSeconds.ToString(CultureInfo.InvariantCulture); + return string.Format( + CultureInfo.InvariantCulture, GetSleepCommandTemplate(), - NativeMethodsShared.IsWindows - ? timeSpan.TotalMilliseconds // powershell can't handle floating point seconds, so give it milliseconds - : timeSpan.TotalSeconds); + sleepArgument); } /// diff --git a/src/Utilities.UnitTests/ToolTask_Tests.cs b/src/Utilities.UnitTests/ToolTask_Tests.cs index a8c5650ecd9..dd52d057826 100644 --- a/src/Utilities.UnitTests/ToolTask_Tests.cs +++ b/src/Utilities.UnitTests/ToolTask_Tests.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Resources; using System.Text.RegularExpressions; @@ -1064,8 +1065,8 @@ public ToolTaskThatSleeps() /// protected override string GenerateCommandLineCommands() => NativeMethodsShared.IsUnixLike ? - string.Format(_unixSleep, RepeatCount < 2 ? InitialDelay / 1000.0 : FollowupDelay / 1000.0) : - string.Format(_windowsSleep, RepeatCount < 2 ? InitialDelay / 1000.0 : FollowupDelay / 1000.0); + string.Format(CultureInfo.InvariantCulture, _unixSleep, RepeatCount < 2 ? InitialDelay / 1000.0 : FollowupDelay / 1000.0) : + string.Format(CultureInfo.InvariantCulture, _windowsSleep, RepeatCount < 2 ? InitialDelay / 1000.0 : FollowupDelay / 1000.0); /// /// Ensures that test parameters make sense.