Skip to content
Open
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
82 changes: 47 additions & 35 deletions src/Build.UnitTests/FileLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using Microsoft.Build.Shared;
using Shouldly;
using Xunit;
using EventSourceSink = Microsoft.Build.BackEnd.Logging.EventSourceSink;
using Project = Microsoft.Build.Evaluation.Project;
Expand All @@ -18,6 +19,13 @@ namespace Microsoft.Build.UnitTests
{
public class FileLogger_Tests
{
private readonly ITestOutputHelper _output;

public FileLogger_Tests(ITestOutputHelper output)
{
_output = output;
}
Comment thread
rainersigwald marked this conversation as resolved.

/// <summary>
/// Basic test of the file logger. Writes to a log file in the temp directory.
/// </summary>
Expand Down Expand Up @@ -482,44 +490,48 @@ private void VerifyFileContent(string file, string expectedContent)
[Fact]
public void DistributedFileLoggerParameters()
{
DistributedFileLogger fileLogger = new DistributedFileLogger();
try
{
fileLogger.NodeId = 0;
fileLogger.Initialize(new EventSourceSink());
Assert.Equal(0, string.Compare(fileLogger.InternalFilelogger.Parameters, "ForceNoAlign;ShowEventId;ShowCommandLine;logfile=msbuild0.log;", StringComparison.OrdinalIgnoreCase));
fileLogger.Shutdown();
using TestEnvironment env = TestEnvironment.Create(_output);

fileLogger.NodeId = 3;
fileLogger.Parameters = "logfile=" + Path.Combine(Directory.GetCurrentDirectory(), "mylogfile.log");
fileLogger.Initialize(new EventSourceSink());
Assert.Equal(0, string.Compare(fileLogger.InternalFilelogger.Parameters, "ForceNoAlign;ShowEventId;ShowCommandLine;logfile=" + Path.Combine(Directory.GetCurrentDirectory(), "mylogfile3.log") + ";", StringComparison.OrdinalIgnoreCase));
fileLogger.Shutdown();
// Use a transient folder under TEMP as the current directory so log files (notably the
// default "msbuild0.log" produced when no logfile parameter is specified) don't leak into
// the test bin directory, where another process (e.g. an antivirus scanner or a parallel
// test) may transiently lock them and cause this test to fail.
TransientTestFolder folder = env.CreateFolder();
env.SetCurrentDirectory(folder.Path);

fileLogger.NodeId = 4;
fileLogger.Parameters = "logfile=" + Path.Combine(Directory.GetCurrentDirectory(), "mylogfile.log");
fileLogger.Initialize(new EventSourceSink());
Assert.Equal(0, string.Compare(fileLogger.InternalFilelogger.Parameters, "ForceNoAlign;ShowEventId;ShowCommandLine;logfile=" + Path.Combine(Directory.GetCurrentDirectory(), "mylogfile4.log") + ";", StringComparison.OrdinalIgnoreCase));
fileLogger.Shutdown();
DistributedFileLogger fileLogger = new DistributedFileLogger();

Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "tempura"));
fileLogger.NodeId = 1;
fileLogger.Parameters = "logfile=" + Path.Combine(Directory.GetCurrentDirectory(), "tempura", "mylogfile.log");
fileLogger.Initialize(new EventSourceSink());
Assert.Equal(0, string.Compare(fileLogger.InternalFilelogger.Parameters, "ForceNoAlign;ShowEventId;ShowCommandLine;logfile=" + Path.Combine(Directory.GetCurrentDirectory(), "tempura", "mylogfile1.log") + ";", StringComparison.OrdinalIgnoreCase));
fileLogger.Shutdown();
}
finally
{
if (Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "tempura")))
{
File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "tempura", "mylogfile1.log"));
FileUtilities.DeleteWithoutTrailingBackslash(Path.Combine(Directory.GetCurrentDirectory(), "tempura"));
}
File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "mylogfile0.log"));
File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "mylogfile3.log"));
File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "mylogfile4.log"));
}
fileLogger.NodeId = 0;
fileLogger.Initialize(new EventSourceSink());
fileLogger.InternalFilelogger.Parameters.ShouldBe(
"ForceNoAlign;ShowEventId;ShowCommandLine;logfile=msbuild0.log;",
StringCompareShould.IgnoreCase);
fileLogger.Shutdown();

fileLogger.NodeId = 3;
fileLogger.Parameters = "logfile=" + Path.Combine(folder.Path, "mylogfile.log");
fileLogger.Initialize(new EventSourceSink());
fileLogger.InternalFilelogger.Parameters.ShouldBe(
"ForceNoAlign;ShowEventId;ShowCommandLine;logfile=" + Path.Combine(folder.Path, "mylogfile3.log") + ";",
StringCompareShould.IgnoreCase);
fileLogger.Shutdown();

fileLogger.NodeId = 4;
fileLogger.Parameters = "logfile=" + Path.Combine(folder.Path, "mylogfile.log");
fileLogger.Initialize(new EventSourceSink());
fileLogger.InternalFilelogger.Parameters.ShouldBe(
"ForceNoAlign;ShowEventId;ShowCommandLine;logfile=" + Path.Combine(folder.Path, "mylogfile4.log") + ";",
StringCompareShould.IgnoreCase);
fileLogger.Shutdown();

TransientTestFolder subfolder = folder.CreateDirectory("tempura");
fileLogger.NodeId = 1;
fileLogger.Parameters = "logfile=" + Path.Combine(subfolder.Path, "mylogfile.log");
fileLogger.Initialize(new EventSourceSink());
fileLogger.InternalFilelogger.Parameters.ShouldBe(
"ForceNoAlign;ShowEventId;ShowCommandLine;logfile=" + Path.Combine(subfolder.Path, "mylogfile1.log") + ";",
StringCompareShould.IgnoreCase);
fileLogger.Shutdown();
}

[Fact]
Expand Down
Loading