Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions src/Build.UnitTests/BinaryLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
/// This test validate that binlog file content is identical upon replaying.
/// The identity can be defined via 3 ways:
Expand Down Expand Up @@ -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
});

Expand Down
2 changes: 1 addition & 1 deletion src/Tasks.UnitTests/OutputPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
22 changes: 11 additions & 11 deletions src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<ConfigurationName Condition="'$(ConfigurationName)' == ''">$(Configuration)</ConfigurationName>

<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">bin\</BaseOutputPath>
<BaseOutputPath Condition="!HasTrailingSlash('$(BaseOutputPath)')">$(BaseOutputPath)\</BaseOutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseOutputPath)$(Configuration)\</OutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseOutputPath)$(PlatformName)\$(Configuration)\</OutputPath>
<OutputPath Condition="!HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>

<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
<BaseIntermediateOutputPath Condition="!HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
<IntermediateOutputPath Condition="!HasTrailingSlash('$(IntermediateOutputPath)')">$(IntermediateOutputPath)\</IntermediateOutputPath>
<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">bin$([System.IO.Path]::DirectorySeparatorChar)</BaseOutputPath>
<BaseOutputPath Condition="!HasTrailingSlash('$(BaseOutputPath)')">$(BaseOutputPath)$([System.IO.Path]::DirectorySeparatorChar)</BaseOutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseOutputPath)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar)</OutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseOutputPath)$(PlatformName)$([System.IO.Path]::DirectorySeparatorChar)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar)</OutputPath>
<OutputPath Condition="!HasTrailingSlash('$(OutputPath)')">$(OutputPath)$([System.IO.Path]::DirectorySeparatorChar)</OutputPath>

<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj$([System.IO.Path]::DirectorySeparatorChar)</BaseIntermediateOutputPath>
<BaseIntermediateOutputPath Condition="!HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)$([System.IO.Path]::DirectorySeparatorChar)</BaseIntermediateOutputPath>
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseIntermediateOutputPath)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar)</IntermediateOutputPath>
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseIntermediateOutputPath)$(PlatformName)$([System.IO.Path]::DirectorySeparatorChar)$(Configuration)$([System.IO.Path]::DirectorySeparatorChar)</IntermediateOutputPath>
<IntermediateOutputPath Condition="!HasTrailingSlash('$(IntermediateOutputPath)')">$(IntermediateOutputPath)$([System.IO.Path]::DirectorySeparatorChar)</IntermediateOutputPath>
</PropertyGroup>

<PropertyGroup>
Expand Down
12 changes: 8 additions & 4 deletions src/UnitTests.Shared/ObjectModelHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -588,7 +589,7 @@ public static void AssertFileExistsInTempProjectDirectory(string fileRelativePat
/// <returns></returns>
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('`', '"');
Expand Down Expand Up @@ -2005,11 +2006,14 @@ public static void ClearDirtyFlag(ProjectRootElement project)
/// <param name="timeSpan">A <see cref="TimeSpan"/> representing the amount of time to sleep.</param>
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);
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/Utilities.UnitTests/ToolTask_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -1064,8 +1065,8 @@ public ToolTaskThatSleeps()
/// </summary>
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);

/// <summary>
/// Ensures that test parameters make sense.
Expand Down
Loading