Skip to content
Merged
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
176 changes: 176 additions & 0 deletions src/Build.UnitTests/BinaryLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,182 @@ public void ParseParameters_InvalidParameter_ThrowsLoggerException(string parame
File.Create(_logFile).Dispose();
}

#region ExtractFilePathFromParameters Tests

[Theory]
[InlineData(null, "msbuild.binlog")]
[InlineData("", "msbuild.binlog")]
[InlineData("output.binlog", "output.binlog")]
[InlineData("LogFile=output.binlog", "output.binlog")]
[InlineData("output.binlog;ProjectImports=None", "output.binlog")]
[InlineData("ProjectImports=None;output.binlog", "output.binlog")]
[InlineData("ProjectImports=None;LogFile=output.binlog;OmitInitialInfo", "output.binlog")]
[InlineData("ProjectImports=None", "msbuild.binlog")] // No path specified
[InlineData("OmitInitialInfo", "msbuild.binlog")] // No path specified
public void ExtractFilePathFromParameters_ReturnsExpectedPath(string parameters, string expectedFileName)
{
string result = BinaryLogger.ExtractFilePathFromParameters(parameters);

// The method returns full paths, so check just the filename
Path.GetFileName(result).ShouldBe(expectedFileName);

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ExtractFilePathFromParameters_ReturnsFullPath()
{
string result = BinaryLogger.ExtractFilePathFromParameters("mylog.binlog");

// Should be a full path, not relative
Path.IsPathRooted(result).ShouldBeTrue();

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

#endregion

#region ExtractNonPathParameters Tests

[Theory]
[InlineData(null, "")]
[InlineData("", "")]
[InlineData("output.binlog", "")] // Path only, no config
[InlineData("LogFile=output.binlog", "")] // Path only, no config
[InlineData("ProjectImports=None", "ProjectImports=None")]
[InlineData("OmitInitialInfo", "OmitInitialInfo")]
[InlineData("output.binlog;ProjectImports=None", "ProjectImports=None")]
[InlineData("output.binlog;ProjectImports=None;OmitInitialInfo", "OmitInitialInfo;ProjectImports=None")] // Sorted
[InlineData("OmitInitialInfo;output.binlog;ProjectImports=None", "OmitInitialInfo;ProjectImports=None")] // Sorted
public void ExtractNonPathParameters_ReturnsExpectedConfig(string parameters, string expectedConfig)
{
string result = BinaryLogger.ExtractNonPathParameters(parameters);
result.ShouldBe(expectedConfig);

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

#endregion

#region ProcessParameters Tests

[Fact]
public void ProcessParameters_NullArray_ReturnsEmptyResult()
{
var result = BinaryLogger.ProcessParameters(null);

result.DistinctParameterSets.ShouldBeEmpty();
result.AdditionalFilePaths.ShouldBeEmpty();
result.DuplicateFilePaths.ShouldBeEmpty();
result.AllConfigurationsIdentical.ShouldBeTrue();

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ProcessParameters_EmptyArray_ReturnsEmptyResult()
{
var result = BinaryLogger.ProcessParameters(Array.Empty<string>());

result.DistinctParameterSets.ShouldBeEmpty();
result.AdditionalFilePaths.ShouldBeEmpty();
result.DuplicateFilePaths.ShouldBeEmpty();
result.AllConfigurationsIdentical.ShouldBeTrue();

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ProcessParameters_SingleParameter_ReturnsOneParameterSet()
{
var result = BinaryLogger.ProcessParameters(new[] { "output.binlog" });

result.DistinctParameterSets.Count.ShouldBe(1);
result.DistinctParameterSets[0].ShouldBe("output.binlog");
result.AdditionalFilePaths.ShouldBeEmpty();
result.DuplicateFilePaths.ShouldBeEmpty();
result.AllConfigurationsIdentical.ShouldBeTrue();

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ProcessParameters_MultipleIdenticalConfigs_OptimizesWithAdditionalPaths()
{
var result = BinaryLogger.ProcessParameters(new[] { "1.binlog", "2.binlog", "3.binlog" });

result.DistinctParameterSets.Count.ShouldBe(3);
result.AllConfigurationsIdentical.ShouldBeTrue();
result.AdditionalFilePaths.Count.ShouldBe(2); // 2.binlog and 3.binlog
result.DuplicateFilePaths.ShouldBeEmpty();

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ProcessParameters_DifferentConfigs_NoOptimization()
{
var result = BinaryLogger.ProcessParameters(new[] { "1.binlog", "2.binlog;ProjectImports=None" });

result.DistinctParameterSets.Count.ShouldBe(2);
result.AllConfigurationsIdentical.ShouldBeFalse();
result.AdditionalFilePaths.ShouldBeEmpty();
result.DuplicateFilePaths.ShouldBeEmpty();

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ProcessParameters_DuplicatePaths_FilteredOut()
{
var result = BinaryLogger.ProcessParameters(new[] { "1.binlog", "1.binlog", "2.binlog" });

result.DistinctParameterSets.Count.ShouldBe(2); // 1.binlog and 2.binlog
result.DuplicateFilePaths.Count.ShouldBe(1); // One duplicate of 1.binlog

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ProcessParameters_DuplicatePaths_CaseInsensitive()
{
var result = BinaryLogger.ProcessParameters(new[] { "Output.binlog", "output.BINLOG", "other.binlog" });

result.DistinctParameterSets.Count.ShouldBe(2); // Output.binlog and other.binlog
result.DuplicateFilePaths.Count.ShouldBe(1); // One duplicate

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

[Fact]
public void ProcessParameters_MixedConfigsWithDuplicates_HandledCorrectly()
{
var result = BinaryLogger.ProcessParameters(new[] {
"1.binlog",
"2.binlog;ProjectImports=None",
"1.binlog;ProjectImports=None" // Different config but same path - filtered as duplicate
});

result.DistinctParameterSets.Count.ShouldBe(2);
result.AllConfigurationsIdentical.ShouldBeFalse();
result.DuplicateFilePaths.Count.ShouldBe(1);

// Create the expected log file to satisfy test environment expectations
File.Create(_logFile).Dispose();
}

#endregion

public void Dispose()
{
_env.Dispose();
Expand Down
Loading