summaryrefslogtreecommitdiff
path: root/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-06 22:46:19 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-06 22:46:19 -0400
commitb4e979cc991a0c2a45ad986210108edd2d43e43d (patch)
tree6894e1f3e965680b5feb6516457e898647d7e9aa /src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework
parent2e7c233f6c9bf6430672b39f970a3324deba79dd (diff)
downloadSMAPI-b4e979cc991a0c2a45ad986210108edd2d43e43d.tar.gz
SMAPI-b4e979cc991a0c2a45ad986210108edd2d43e43d.tar.bz2
SMAPI-b4e979cc991a0c2a45ad986210108edd2d43e43d.zip
fix all warnings to simplify migration to nullable annotations (#837)
Diffstat (limited to 'src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework')
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs24
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.cs30
2 files changed, 27 insertions, 27 deletions
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs
index 8d72fea1..68a892a9 100644
--- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs
@@ -53,17 +53,17 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer analyzer, Document[] documents)
{
var projects = new HashSet<Project>();
- foreach (var document in documents)
+ foreach (Document document in documents)
{
projects.Add(document.Project);
}
var diagnostics = new List<Diagnostic>();
- foreach (var project in projects)
+ foreach (Project project in projects)
{
- var compilationWithAnalyzers = project.GetCompilationAsync().Result.WithAnalyzers(ImmutableArray.Create(analyzer));
+ CompilationWithAnalyzers compilationWithAnalyzers = project.GetCompilationAsync().Result.WithAnalyzers(ImmutableArray.Create(analyzer));
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
- foreach (var diag in diags)
+ foreach (Diagnostic diag in diags)
{
if (diag.Location == Location.None || diag.Location.IsInMetadata)
{
@@ -73,8 +73,8 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
{
for (int i = 0; i < documents.Length; i++)
{
- var document = documents[i];
- var tree = document.GetSyntaxTreeAsync().Result;
+ Document document = documents[i];
+ SyntaxTree tree = document.GetSyntaxTreeAsync().Result;
if (tree == diag.Location.SourceTree)
{
diagnostics.Add(diag);
@@ -115,7 +115,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
throw new ArgumentException("Unsupported Language");
}
- var project = CreateProject(sources, language);
+ Project project = CreateProject(sources, language);
var documents = project.Documents.ToArray();
if (sources.Length != documents.Length)
@@ -148,9 +148,9 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
string fileNamePrefix = DefaultFilePathPrefix;
string fileExt = language == LanguageNames.CSharp ? CSharpDefaultFileExt : VisualBasicDefaultExt;
- var projectId = ProjectId.CreateNewId(debugName: TestProjectName);
+ ProjectId projectId = ProjectId.CreateNewId(debugName: TestProjectName);
- var solution = new AdhocWorkspace()
+ Solution solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.AddMetadataReference(projectId, DiagnosticVerifier.SelfReference)
@@ -160,10 +160,10 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
.AddMetadataReference(projectId, CodeAnalysisReference);
int count = 0;
- foreach (var source in sources)
+ foreach (string source in sources)
{
- var newFileName = fileNamePrefix + count + "." + fileExt;
- var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName);
+ string newFileName = fileNamePrefix + count + "." + fileExt;
+ DocumentId documentId = DocumentId.CreateNewId(projectId, debugName: newFileName);
solution = solution.AddDocument(documentId, newFileName, SourceText.From(source));
count++;
}
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.cs
index 09d3a3f8..4170042d 100644
--- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.cs
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.cs
@@ -43,7 +43,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
/// <param name="expected"> DiagnosticResults that should appear after the analyzer is run on the source</param>
protected void VerifyCSharpDiagnostic(string source, params DiagnosticResult[] expected)
{
- VerifyDiagnostics(new[] { source }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
+ this.VerifyDiagnostics(new[] { source }, LanguageNames.CSharp, this.GetCSharpDiagnosticAnalyzer(), expected);
}
/// <summary>
@@ -54,7 +54,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
/// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the sources</param>
protected void VerifyCSharpDiagnostic(string[] sources, params DiagnosticResult[] expected)
{
- VerifyDiagnostics(sources, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
+ this.VerifyDiagnostics(sources, LanguageNames.CSharp, this.GetCSharpDiagnosticAnalyzer(), expected);
}
/// <summary>
@@ -67,8 +67,8 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
/// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the sources</param>
private void VerifyDiagnostics(string[] sources, string language, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expected)
{
- var diagnostics = GetSortedDiagnostics(sources, language, analyzer);
- VerifyDiagnosticResults(diagnostics, analyzer, expected);
+ var diagnostics = DiagnosticVerifier.GetSortedDiagnostics(sources, language, analyzer);
+ DiagnosticVerifier.VerifyDiagnosticResults(diagnostics, analyzer, expected);
}
#endregion
@@ -88,7 +88,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
if (expectedCount != actualCount)
{
- string diagnosticsOutput = actualResults.Any() ? FormatDiagnostics(analyzer, actualResults.ToArray()) : " NONE.";
+ string diagnosticsOutput = actualResults.Any() ? DiagnosticVerifier.FormatDiagnostics(analyzer, actualResults.ToArray()) : " NONE.";
Assert.IsTrue(false,
string.Format("Mismatch between number of diagnostics returned, expected \"{0}\" actual \"{1}\"\r\n\r\nDiagnostics:\r\n{2}\r\n", expectedCount, actualCount, diagnosticsOutput));
@@ -105,12 +105,12 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
{
Assert.IsTrue(false,
string.Format("Expected:\nA project diagnostic with No location\nActual:\n{0}",
- FormatDiagnostics(analyzer, actual)));
+ DiagnosticVerifier.FormatDiagnostics(analyzer, actual)));
}
}
else
{
- VerifyDiagnosticLocation(analyzer, actual, actual.Location, expected.Locations.First());
+ DiagnosticVerifier.VerifyDiagnosticLocation(analyzer, actual, actual.Location, expected.Locations.First());
var additionalLocations = actual.AdditionalLocations.ToArray();
if (additionalLocations.Length != expected.Locations.Length - 1)
@@ -118,12 +118,12 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
Assert.IsTrue(false,
string.Format("Expected {0} additional locations but got {1} for Diagnostic:\r\n {2}\r\n",
expected.Locations.Length - 1, additionalLocations.Length,
- FormatDiagnostics(analyzer, actual)));
+ DiagnosticVerifier.FormatDiagnostics(analyzer, actual)));
}
for (int j = 0; j < additionalLocations.Length; ++j)
{
- VerifyDiagnosticLocation(analyzer, actual, additionalLocations[j], expected.Locations[j + 1]);
+ DiagnosticVerifier.VerifyDiagnosticLocation(analyzer, actual, additionalLocations[j], expected.Locations[j + 1]);
}
}
@@ -131,21 +131,21 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
{
Assert.IsTrue(false,
string.Format("Expected diagnostic id to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Id, actual.Id, FormatDiagnostics(analyzer, actual)));
+ expected.Id, actual.Id, DiagnosticVerifier.FormatDiagnostics(analyzer, actual)));
}
if (actual.Severity != expected.Severity)
{
Assert.IsTrue(false,
string.Format("Expected diagnostic severity to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Severity, actual.Severity, FormatDiagnostics(analyzer, actual)));
+ expected.Severity, actual.Severity, DiagnosticVerifier.FormatDiagnostics(analyzer, actual)));
}
if (actual.GetMessage() != expected.Message)
{
Assert.IsTrue(false,
string.Format("Expected diagnostic message to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Message, actual.GetMessage(), FormatDiagnostics(analyzer, actual)));
+ expected.Message, actual.GetMessage(), DiagnosticVerifier.FormatDiagnostics(analyzer, actual)));
}
}
}
@@ -163,7 +163,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
Assert.IsTrue(actualSpan.Path == expected.Path || (actualSpan.Path != null && actualSpan.Path.Contains("Test0.") && expected.Path.Contains("Test.")),
string.Format("Expected diagnostic to be in file \"{0}\" was actually in file \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Path, actualSpan.Path, FormatDiagnostics(analyzer, diagnostic)));
+ expected.Path, actualSpan.Path, DiagnosticVerifier.FormatDiagnostics(analyzer, diagnostic)));
var actualLinePosition = actualSpan.StartLinePosition;
@@ -174,7 +174,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
{
Assert.IsTrue(false,
string.Format("Expected diagnostic to be on line \"{0}\" was actually on line \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Line, actualLinePosition.Line + 1, FormatDiagnostics(analyzer, diagnostic)));
+ expected.Line, actualLinePosition.Line + 1, DiagnosticVerifier.FormatDiagnostics(analyzer, diagnostic)));
}
}
@@ -185,7 +185,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
{
Assert.IsTrue(false,
string.Format("Expected diagnostic to start at column \"{0}\" was actually at column \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Column, actualLinePosition.Character + 1, FormatDiagnostics(analyzer, diagnostic)));
+ expected.Column, actualLinePosition.Character + 1, DiagnosticVerifier.FormatDiagnostics(analyzer, diagnostic)));
}
}
}