|
10 | 10 | using Microsoft.CodeAnalysis; |
11 | 11 | using Microsoft.CodeAnalysis.CSharp; |
12 | 12 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
13 | | -using Microsoft.CodeAnalysis.Diagnostics; |
14 | 13 | using Microsoft.CodeAnalysis.Text; |
15 | 14 | using Mono.Linker.Tests.Cases.Expectations.Assertions; |
16 | 15 | using Xunit; |
@@ -182,13 +181,15 @@ static ProducedBy GetProducedBy (ExpressionSyntax expression) |
182 | 181 | var producedBy = (ProducedBy) 0x0; |
183 | 182 | switch (expression) { |
184 | 183 | case BinaryExpressionSyntax binaryExpressionSyntax: |
185 | | - Enum.TryParse<ProducedBy> ((binaryExpressionSyntax.Left as MemberAccessExpressionSyntax)!.Name.Identifier.ValueText, out var besProducedBy); |
| 184 | + if (!Enum.TryParse<ProducedBy> ((binaryExpressionSyntax.Left as MemberAccessExpressionSyntax)!.Name.Identifier.ValueText, out var besProducedBy)) |
| 185 | + throw new ArgumentException ("Expression must be a ProducedBy value", nameof (expression)); |
186 | 186 | producedBy |= besProducedBy; |
187 | 187 | producedBy |= GetProducedBy (binaryExpressionSyntax.Right); |
188 | 188 | break; |
189 | 189 |
|
190 | 190 | case MemberAccessExpressionSyntax memberAccessExpressionSyntax: |
191 | | - Enum.TryParse<ProducedBy> (memberAccessExpressionSyntax.Name.Identifier.ValueText, out var maeProducedBy); |
| 191 | + if (!Enum.TryParse<ProducedBy> (memberAccessExpressionSyntax.Name.Identifier.ValueText, out var maeProducedBy)) |
| 192 | + throw new ArgumentException ("Expression must be a ProducedBy value", nameof (expression)); |
192 | 193 | producedBy |= maeProducedBy; |
193 | 194 | break; |
194 | 195 |
|
@@ -282,15 +283,15 @@ private bool TryValidateLogContainsAttribute (AttributeSyntax attribute, List<Di |
282 | 283 | } |
283 | 284 | } |
284 | 285 |
|
285 | | - missingDiagnosticMessage = $"Could not find text:\n{text}\nIn diagnostics:\n{(string.Join (Environment.NewLine, _diagnostics))}"; |
| 286 | + missingDiagnosticMessage = $"Could not find text:\n{text}\nIn diagnostics:\n{string.Join (Environment.NewLine, _diagnostics)}"; |
286 | 287 | return false; |
287 | 288 | } |
288 | 289 |
|
289 | | - private void ValidateLogDoesNotContainAttribute (AttributeSyntax attribute, IReadOnlyList<Diagnostic> diagnosticMessages) |
| 290 | + private static void ValidateLogDoesNotContainAttribute (AttributeSyntax attribute, IReadOnlyList<Diagnostic> diagnosticMessages) |
290 | 291 | { |
291 | 292 | var arg = Assert.Single (LinkerTestBase.GetAttributeArguments (attribute)); |
292 | 293 | var text = LinkerTestBase.GetStringFromExpression (arg.Value); |
293 | | - foreach (var diagnostic in _diagnostics) |
| 294 | + foreach (var diagnostic in diagnosticMessages) |
294 | 295 | Assert.DoesNotContain (text, diagnostic.GetMessage ()); |
295 | 296 | } |
296 | 297 |
|
|
0 commit comments