Skip to content

Commit

Permalink
excluding the TreatWarningsAsErrors from the original PR, see #10871
Browse files Browse the repository at this point in the history
  • Loading branch information
SimaTian committed Jan 27, 2025
1 parent c435161 commit d3ef892
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/Build.UnitTests/WarningsAsMessagesAndErrors_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Shouldly;
using Xunit;
using Xunit.Abstractions;
using static System.Net.WebRequestMethods;

#nullable disable

Expand All @@ -35,7 +36,7 @@ public void TreatAllWarningsAsErrors()
ObjectModelHelpers.BuildProjectExpectSuccess(GetTestProject(treatAllWarningsAsErrors: false));
}

[Fact]
[Fact (Skip = "TreatWarningAsErrors is excluded in the first wave of the unification. See https://github.com/dotnet/msbuild/issues/10871")]
public void TreatAllWarningsAsErrorsNoPrefix()
{
MockLogger logger = ObjectModelHelpers.BuildProjectExpectFailure(GetTestProject(customProperties: new Dictionary<string, string>
Expand Down Expand Up @@ -354,9 +355,10 @@ private string GetTestProject(bool? treatAllWarningsAsErrors = null, string warn
[InlineData("MSB1235", "MSB1234", "MSB1234", "MSB1234", false)] // Log MSB1234, treat as error via MSBuildWarningsAsErrors
[InlineData("MSB1235", "", "MSB1234", "MSB1234", true)] // Log MSB1234, expect MSB1234 as error via MSBuildTreatWarningsAsErrors
[InlineData("MSB1234", "MSB1234", "MSB1234", "MSB4181", true)]// Log MSB1234, MSBuildWarningsAsMessages takes priority
[InlineData("MSB1235", "MSB1234", "MSB1234", "MSB1234", false, false)] // Log MSB1234, treat as error via BuildWarningsAsErrors
[InlineData("MSB1235", "", "MSB1234", "MSB1234", true, false)] // Log MSB1234, expect MSB1234 as error via BuildTreatWarningsAsErrors
[InlineData("MSB1234", "MSB1234", "MSB1234", "MSB4181", true, false)]// Log MSB1234, BuildWarningsAsMessages takes priority
// TreatWarningAsErrors is excluded in the first wave of the unification.See https://github.com/dotnet/msbuild/issues/10871
// [InlineData("MSB1235", "MSB1234", "MSB1234", "MSB1234", false, false)] // Log MSB1234, treat as error via BuildWarningsAsErrors
// [InlineData("MSB1235", "", "MSB1234", "MSB1234", true, false)] // Log MSB1234, expect MSB1234 as error via BuildTreatWarningsAsErrors
// [InlineData("MSB1234", "MSB1234", "MSB1234", "MSB4181", true, false)]// Log MSB1234, BuildWarningsAsMessages takes priority
public void WarningsAsErrorsAndMessages_Tests(string WarningsAsMessages,
string WarningsAsErrors,
string WarningToLog,
Expand Down Expand Up @@ -529,8 +531,9 @@ public void TaskLogsWarningAsError_BatchedBuild()
[Theory]
[InlineData("MSB1234", false, 1, 1)]
[InlineData("MSB0000", true, 0, 2)]
[InlineData("MSB1234", false, 1, 1, false)]
[InlineData("MSB0000", true, 0, 2, false)]
// TreatWarningAsErrors is excluded in the first wave of the unification.See https://github.com/dotnet/msbuild/issues/10871
// [InlineData("MSB1234", false, 1, 1, false)
// [InlineData("MSB0000", true, 0, 2, false)
public void TaskReturnsTrue_Tests(string warningsAsErrors, bool treatAllWarningsAsErrors, int warningCountShouldBe, int errorCountShouldBe, bool useMSPrefix = true)
{
string prefix = useMSPrefix ? "MSBuild" : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1390,9 +1390,7 @@ private void ConfigureWarningsAsErrorsAndMessages()
// Ensure everything that is required is available at this time
if (project != null && buildEventContext != null && loggingService != null && buildEventContext.ProjectInstanceId != BuildEventContext.InvalidProjectInstanceId)
{
if (String.Equals(project.GetEngineRequiredPropertyValue(MSBuildConstants.MSBuildPrefix + MSBuildConstants.TreatWarningsAsErrors)?.Trim(), "true", StringComparison.OrdinalIgnoreCase) ||
(String.Equals(project.GetEngineRequiredPropertyValue(MSBuildConstants.TreatWarningsAsErrors)?.Trim(), "true", StringComparison.OrdinalIgnoreCase) &&
ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_14)))
if (String.Equals(project.GetEngineRequiredPropertyValue(MSBuildConstants.MSBuildPrefix + MSBuildConstants.TreatWarningsAsErrors)?.Trim(), "true", StringComparison.OrdinalIgnoreCase))
{
// If <MSBuildTreatWarningsAsErrors was specified then an empty ISet<string> signals the IEventSourceSink to treat all warnings as errors
loggingService.AddWarningsAsErrors(buildEventContext, new HashSet<string>());
Expand Down
7 changes: 6 additions & 1 deletion src/UnitTests.Shared/ObjectModelHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,13 @@ public static void BuildProjectExpectSuccess(
/// expected to fail.
/// </summary>
/// <param name="projectContents">The project file content in string format.</param>
/// <param name="testOutputHelper"><see cref="ITestOutputHelper"/> to log to.</param>
/// <param name="loggerVerbosity">The required logging verbosity.</param>
/// <returns>The <see cref="MockLogger"/> that was used during evaluation and build.</returns>
public static MockLogger BuildProjectExpectFailure([StringSyntax(StringSyntaxAttribute.Xml)] string projectContents)
public static MockLogger BuildProjectExpectFailure(
[StringSyntax(StringSyntaxAttribute.Xml)] string projectContents,
ITestOutputHelper testOutputHelper = null,
LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal)
{
MockLogger logger = new MockLogger(testOutputHelper);
BuildProjectExpectFailure(projectContents, logger);
Expand Down

0 comments on commit d3ef892

Please sign in to comment.