Add a new test and fix for logging statements in child blocks

This commit is contained in:
TSR Berry 2024-01-16 13:48:13 +01:00
parent 40bceebacb
commit 81988c9ed8
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
2 changed files with 32 additions and 2 deletions

View file

@ -146,9 +146,9 @@ namespace Ryujinx.Analyzers
bool exceptionLogged = false;
// Iterate through all expression statements
foreach (var statement in catchClauseSyntax.Block.Statements)
foreach (var blockNode in catchClauseSyntax.Block.DescendantNodes())
{
if (statement is not ExpressionStatementSyntax expressionStatement)
if (blockNode is not ExpressionStatementSyntax expressionStatement)
{
continue;
}

View file

@ -214,6 +214,36 @@ public class MyClass
}
}
}
";
await Verifier.VerifyAnalyzerAsync(text).ConfigureAwait(false);
}
[Fact]
public async Task LogWithIdentifierInSubBlock_NoDiagnostic()
{
string text = _loggerText + @"
public class MyClass
{
public void MyMethod9()
{
try
{
Console.WriteLine(""test"");
}
catch (Exception ex)
{
string testString = ""first time?"";
if (1 == 1)
{
Ryujinx.Common.Logging.Logger.Info?.Print(Ryujinx.Common.Logging.LogClass.Application, $""test: {testString} Error: {ex.Message}"");
}
Console.WriteLine(""Test"");
}
}
}
";
await Verifier.VerifyAnalyzerAsync(text).ConfigureAwait(false);