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
28 changes: 28 additions & 0 deletions src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ public void TaskReturnsFailureButDoesNotLogError_ShouldCauseBuildFailure()
}
}

/// <summary>
/// Test that a task that returns false without logging anything reports MSB4181 as a warning.
/// </summary>
[Fact]
public void TaskReturnsFailureButDoesNotLogError_ContinueOnError_WarnAndContinue()
{
Expand All @@ -439,6 +442,31 @@ public void TaskReturnsFailureButDoesNotLogError_ContinueOnError_WarnAndContinue
}
}

/// <summary>
/// Test that a task that returns false after logging an error->warning does NOT also log MSB4181
/// </summary>
[Fact]
public void TaskReturnsFailureAndLogsError_ContinueOnError_WarnAndContinue()
{
using (TestEnvironment env = TestEnvironment.Create(_output))
{
TransientTestProjectWithFiles proj = env.CreateTestProjectWithFiles($@"
<Project>
<UsingTask TaskName = ""CustomLogAndReturnTask"" AssemblyName=""Microsoft.Build.Engine.UnitTests""/>
<UsingTask TaskName = ""ReturnFailureWithoutLoggingErrorTask"" AssemblyName=""Microsoft.Build.Engine.UnitTests""/>
<Target Name='Build'>
<CustomLogAndReturnTask Return=""false"" ErrorCode=""MSB1234"" ContinueOnError=""WarnAndContinue""/>
</Target>
</Project>");

MockLogger logger = proj.BuildProjectExpectSuccess();

// The only warning should be the error->warning logged by the task.
logger.WarningCount.ShouldBe(1);
logger.AssertLogContains("MSB1234");
}
}

[Fact]
public void TaskReturnsFailureButDoesNotLogError_ContinueOnError_True()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,9 @@ public void LogErrorEvent(Microsoft.Build.Framework.BuildErrorEventArgs e)
{
e.BuildEventContext = _taskLoggingContext.BuildEventContext;
_taskLoggingContext.LoggingService.LogBuildEvent(e);
_taskLoggingContext.HasLoggedErrors = true;
}

_taskLoggingContext.HasLoggedErrors = true;
}
}

Expand Down