diff --git a/src/Compatibility/Microsoft.DotNet.ApiCompatibility/ErrorSuppression/SuppressionEngine.cs b/src/Compatibility/Microsoft.DotNet.ApiCompatibility/ErrorSuppression/SuppressionEngine.cs index b92fb3662c33..36064e6abb88 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiCompatibility/ErrorSuppression/SuppressionEngine.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiCompatibility/ErrorSuppression/SuppressionEngine.cs @@ -68,13 +68,14 @@ public bool IsErrorSuppressed(Suppression error) { return true; } - else + else if (error.DiagnosticId == null || error.DiagnosticId.StartsWith("cp", StringComparison.InvariantCultureIgnoreCase)) { - // See if the error is globally suppressed by checking if the same diagnosticid and target are entered - // without any left and right. - return (error.DiagnosticId == null || error.DiagnosticId.StartsWith("cp", StringComparison.InvariantCultureIgnoreCase)) && - _validationSuppressions.Contains(new Suppression { DiagnosticId = error.DiagnosticId, Target = error.Target }); + // See if the error is globally suppressed by checking if the same diagnosticid and target or with the same left and right + return _validationSuppressions.Contains(new Suppression { DiagnosticId = error.DiagnosticId, Target = error.Target, IsBaselineSuppression = error.IsBaselineSuppression}) || + _validationSuppressions.Contains(new Suppression { DiagnosticId = error.DiagnosticId, Left = error.Left, Right = error.Right, IsBaselineSuppression = error.IsBaselineSuppression }); } + + return false; } finally { diff --git a/src/Tests/Microsoft.DotNet.ApiCompatibility.Tests/SuppressionTests/SuppressionEngineTests.cs b/src/Tests/Microsoft.DotNet.ApiCompatibility.Tests/SuppressionTests/SuppressionEngineTests.cs index 5f22089ba7d5..6ffcedc3b7bd 100644 --- a/src/Tests/Microsoft.DotNet.ApiCompatibility.Tests/SuppressionTests/SuppressionEngineTests.cs +++ b/src/Tests/Microsoft.DotNet.ApiCompatibility.Tests/SuppressionTests/SuppressionEngineTests.cs @@ -84,11 +84,21 @@ public void SuppressionEngineSupportsGlobalCompare() { SuppressionEngine engine = SuppressionEngine.Create(); // Engine has a suppression with no left and no right. This should be treated global for any left and any right. - engine.AddSuppression("CP0001", "T:A.B"); + engine.AddSuppression("CP0001", "T:A.B", isBaselineSuppression: true); + engine.AddSuppression("CP0001", "T:A.C"); + // Engine has a suppression with no target. Should be treated globally for any target with that left and right. + engine.AddSuppression("CP0003", null, left: "ref/net6.0/myleft.dll", right: "lib/net6.0/myright.dll", isBaselineSuppression: false); - Assert.True(engine.IsErrorSuppressed("CP0001", "T:A.B", "ref/net6.0/myLib.dll", "lib/net6.0/myLib.dll")); - Assert.True(engine.IsErrorSuppressed("CP0001", "T:A.B", "ref/net6.0/myLib.dll", "lib/net6.0/myLib.dll", false)); - Assert.True(engine.IsErrorSuppressed("CP0001", "T:A.B", "ref/net6.0/myLib.dll", "lib/net6.0/myLib.dll", true)); + Assert.True(engine.IsErrorSuppressed("CP0001", "T:A.B", "ref/net6.0/myLib.dll", "lib/net6.0/myLib.dll", isBaselineSuppression: true)); + Assert.False(engine.IsErrorSuppressed("CP0001", "T:A.B", "ref/net6.0/myLib.dll", "lib/net6.0/myLib.dll", isBaselineSuppression: false)); + + Assert.True(engine.IsErrorSuppressed("CP0001", "T:A.C", "ref/net6.0/myLib.dll", "lib/net6.0/myLib.dll", isBaselineSuppression: false)); + Assert.False(engine.IsErrorSuppressed("CP0001", "T:A.C", "ref/net6.0/myLib.dll", "lib/net6.0/myLib.dll", isBaselineSuppression: true)); + + Assert.True(engine.IsErrorSuppressed("CP0003", "T:A.B", "ref/net6.0/myLeft.dll", "lib/net6.0/myRight.dll")); + Assert.True(engine.IsErrorSuppressed("CP0003", "T:A.C", "ref/net6.0/myLeft.dll", "lib/net6.0/myRight.dll")); + Assert.True(engine.IsErrorSuppressed("CP0003", "T:A.D", "ref/net6.0/myLeft.dll", "lib/net6.0/myRight.dll")); + Assert.False(engine.IsErrorSuppressed("CP0003", "T:A.D", "ref/net6.0/myLeft.dll", "lib/net6.0/myRight.dll", isBaselineSuppression: true)); } [Fact]