Skip to content

Commit

Permalink
[API Compat] Support suppressing an error globally for the same left …
Browse files Browse the repository at this point in the history
…and right with no target (#19123)

* [API Compat] Support suppressing an error globally for the same left and right with no target
  • Loading branch information
safern authored Jul 22, 2021
1 parent bdfffbe commit 698ab94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 698ab94

Please sign in to comment.