Skip to content

Allow warnings to be ignored (set-wise) #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2022
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
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 `G` methods 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 `I` methods 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