diff options
author | Vitek Karas <vitek.karas@microsoft.com> | 2021-05-31 21:28:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 21:28:55 +0300 |
commit | 493a448586c1fad68efc2126836f5bb9b5f9ad20 (patch) | |
tree | 6043095317001e2a40ca8eb23cf5cbd3a1bd8007 /test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs | |
parent | 6c33faaf912c3161f75d205da54b93847d647fe4 (diff) |
Use full MessageOrigin when reporting data flow warnings (#2070)
Recent chaneg introduced a scope stack to marking which carries `MessageOrigin` around so that warnings can be reported with precise origin. The one exception to this was the `ReflectionMethodBodyScanner`.
This change integrates the scope stack with `ReflectionMethodBodyScanner`. The visible result is more precise reporting of some warnings. This change will be needed for the work around compiler generated code (since then MessageOrigin will carry even more information than it does currently).
The main API change is addition of the `MessageOrigin` parameter to the `IReflectionPatternRecorder.UnrecognizedReflectionAccessPattern`. There are plans to remove this interface completely, so there' not much need to clean it up right now (so I left the potentially duplicated `origin` and `source` arguments as is).
The rest of the change is just correctly flowing the information around.
I also improved the test infra to be able to correctly handle `ExpectedWarning` with source/line info on all warnings.
There are visible changes in the `SourceLines` test where some warnings changed location (more precise now).
Diffstat (limited to 'test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs')
-rw-r--r-- | test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index 2a2c04e31..b4508e15e 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Text.RegularExpressions; using Mono.Cecil; using Mono.Cecil.Cil; @@ -709,6 +710,7 @@ namespace Mono.Linker.Tests.TestCasesRunner int expectedWarningCodeNumber = int.Parse (expectedWarningCode.Substring (2)); var actualMethod = attrProvider as MethodDefinition; + string expectedOrigin = null; var matchedMessages = loggedMessages.Where (mc => { if (mc.Category != MessageCategory.Warning || mc.Code != expectedWarningCodeNumber) @@ -719,15 +721,36 @@ namespace Mono.Linker.Tests.TestCasesRunner return false; if (fileName != null) { - // Note: string.Compare(string, StringComparison) doesn't exist in .NET Framework API set - if (mc.Origin?.FileName?.IndexOf (fileName, StringComparison.OrdinalIgnoreCase) < 0) + if (mc.Origin == null) return false; - if (sourceLine != null && mc.Origin?.SourceLine != sourceLine.Value) - return false; - - if (sourceColumn != null && mc.Origin?.SourceColumn != sourceColumn.Value) - return false; + var actualOrigin = mc.Origin.Value; + if (actualOrigin.FileName != null) { + // Note: string.Compare(string, StringComparison) doesn't exist in .NET Framework API set + if (actualOrigin.FileName.IndexOf (fileName, StringComparison.OrdinalIgnoreCase) < 0) + return false; + + if (sourceLine != null && mc.Origin?.SourceLine != sourceLine.Value) + return false; + + if (sourceColumn != null && mc.Origin?.SourceColumn != sourceColumn.Value) + return false; + } else { + // The warning was logged with member/ILoffset, so it didn't have line/column info filled + // but it will be computed from PDBs, so instead compare it in a string representation + if (expectedOrigin == null) { + expectedOrigin = fileName; + if (sourceLine.HasValue) { + expectedOrigin += "(" + sourceLine.Value; + if (sourceColumn.HasValue) + expectedOrigin += "," + sourceColumn.Value; + expectedOrigin += ")"; + } + } + + if (!actualOrigin.ToString ().EndsWith (expectedOrigin, StringComparison.OrdinalIgnoreCase)) + return false; + } } else { if (mc.Origin?.MemberDefinition?.FullName == attrProvider.FullName) return true; |