Skip to content

Commit 528bf80

Browse files
authored
Allow warnings to be ignored (set-wise) (#651)
Towards #646
1 parent e3cab89 commit 528bf80

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

standard/basic-concepts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The textual order in which names are declared is generally of no significance. I
103103
<!-- markdownlint-enable MD028 -->
104104
> *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.
105105
>
106+
> <!-- Example: {template:"standalone-lib", name:"Declarations2", expectedErrors:["CS0136","CS0136"], ignoredWarnings:["CS0219"] } -->
106107
> ```csharp
107108
> class A
108109
> {

tools/ExampleExtractor/ExampleMetadata.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ExampleMetadata
2222
public bool ReplaceEllipsis { get; set; }
2323
public List<string> ExpectedErrors { get; set; }
2424
public List<string> ExpectedWarnings { get; set; }
25+
public List<string> IgnoredWarnings { get; set; }
2526
public List<string> ExpectedOutput { get; set; }
2627
public string ExpectedException { get; set; }
2728

tools/ExampleTester/GeneratedExample.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,20 @@ internal async Task<bool> Test()
5050

5151
bool ret = true;
5252
ret &= ValidateDiagnostics("errors", DiagnosticSeverity.Error, Metadata.ExpectedErrors);
53-
ret &= ValidateDiagnostics("warnings", DiagnosticSeverity.Warning, Metadata.ExpectedWarnings);
53+
ret &= ValidateDiagnostics("warnings", DiagnosticSeverity.Warning, Metadata.ExpectedWarnings, Metadata.IgnoredWarnings);
5454
ret &= ValidateOutput();
5555

5656
return ret;
5757

58-
bool ValidateDiagnostics(string type, DiagnosticSeverity severity, List<string> expected)
58+
bool ValidateDiagnostics(string type, DiagnosticSeverity severity, List<string> expected, List<string>? ignored = null)
5959
{
6060
expected ??= new List<string>();
61-
var actual = compilation.GetDiagnostics().Where(d => d.Severity == severity).Select(d => d.Id).ToList();
61+
ignored ??= new List<string>();
62+
var actual = compilation.GetDiagnostics()
63+
.Where(d => d.Severity == severity)
64+
.Select(d => d.Id)
65+
.Where(id => !ignored.Contains(id))
66+
.ToList();
6267
return ValidateExpectedAgainstActual(type, expected, actual);
6368
}
6469

0 commit comments

Comments
 (0)