Skip to content

Commit

Permalink
Allow warnings to be ignored (set-wise)
Browse files Browse the repository at this point in the history
Towards dotnet#646
  • Loading branch information
jskeet committed Oct 27, 2022
1 parent e3cab89 commit cf31aac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions standard/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The textual order in which names are declared is generally of no significance. I
<!-- markdownlint-enable MD028 -->
> *Note*: As specified above, the declaration space of a block includes any nested blocks. Thus, in the following example, the `F` and `Gmethods result in a compile-time error because the name `i` is declared in the outer block and cannot be redeclared in the inner block. However, the `H` and `Imethods are valid since the two `i`’s are declared in separate non-nested blocks.
>
> <!-- Example: {template:"standalone-lib", name:"Declarations2", expectedErrors:["CS0136","CS0136"], ignoredWarnings:["CS0219"] } -->
> ```csharp
> class A
> {
Expand Down
1 change: 1 addition & 0 deletions tools/ExampleExtractor/ExampleMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ExampleMetadata
public bool ReplaceEllipsis { get; set; }
public List<string> ExpectedErrors { get; set; }
public List<string> ExpectedWarnings { get; set; }
public List<string> IgnoredWarnings { get; set; }
public List<string> ExpectedOutput { get; set; }
public string ExpectedException { get; set; }

Expand Down
11 changes: 8 additions & 3 deletions tools/ExampleTester/GeneratedExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ internal async Task<bool> Test()

bool ret = true;
ret &= ValidateDiagnostics("errors", DiagnosticSeverity.Error, Metadata.ExpectedErrors);
ret &= ValidateDiagnostics("warnings", DiagnosticSeverity.Warning, Metadata.ExpectedWarnings);
ret &= ValidateDiagnostics("warnings", DiagnosticSeverity.Warning, Metadata.ExpectedWarnings, Metadata.IgnoredWarnings);
ret &= ValidateOutput();

return ret;

bool ValidateDiagnostics(string type, DiagnosticSeverity severity, List<string> expected)
bool ValidateDiagnostics(string type, DiagnosticSeverity severity, List<string> expected, List<string>? ignored = null)
{
expected ??= new List<string>();
var actual = compilation.GetDiagnostics().Where(d => d.Severity == severity).Select(d => d.Id).ToList();
ignored ??= new List<string>();
var actual = compilation.GetDiagnostics()
.Where(d => d.Severity == severity)
.Select(d => d.Id)
.Where(id => !ignored.Contains(id))
.ToList();
return ValidateExpectedAgainstActual(type, expected, actual);
}

Expand Down

0 comments on commit cf31aac

Please sign in to comment.