Skip to content

Commit

Permalink
NET-878 Rename Helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mikula-sonarsource authored and sonartech committed Dec 18, 2024
1 parent af3f528 commit 831d94f
Show file tree
Hide file tree
Showing 81 changed files with 341 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void Function3() {}
#endif
public void ParameterList_ReturnsList(string type)
{
var tree = TestHelper.CompileCS($$"""{{type}} Test(int i) { }""").Tree;
var tree = TestCompiler.CompileCS($$"""{{type}} Test(int i) { }""").Tree;
var typeDeclaration = tree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<TypeDeclarationSyntax>().Single();
var parameterList = typeDeclaration.ParameterList();
parameterList.Should().NotBeNull();
Expand All @@ -108,7 +108,7 @@ public void ParameterList_ReturnsList(string type)
[TestMethod]
public void ParameterList_Interface()
{
var tree = TestHelper.CompileCS("interface Test { }").Tree;
var tree = TestCompiler.CompileCS("interface Test { }").Tree;
var typeDeclaration = tree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<TypeDeclarationSyntax>().Single();
var parameterList = typeDeclaration.ParameterList();
parameterList.Should().BeNull();
Expand Down Expand Up @@ -167,7 +167,7 @@ public void PrimaryConstructor_PrimaryConstructorRecord(LanguageVersion language
#endif
public void PrimaryConstructor_PrimaryConstructorOnClass(string type)
{
var (tree, model) = TestHelper.CompileCS($$"""{{type}} Test(int i) { }""");
var (tree, model) = TestCompiler.CompileCS($$"""{{type}} Test(int i) { }""");
var typeDeclaration = tree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<TypeDeclarationSyntax>().Single();
var methodSymbol = typeDeclaration.PrimaryConstructor(model);
methodSymbol.Should().NotBeNull();
Expand All @@ -180,7 +180,7 @@ public void PrimaryConstructor_PrimaryConstructorOnClass(string type)
[TestMethod]
public void PrimaryConstructor_EmptyPrimaryConstructor()
{
var (tree, model) = TestHelper.CompileCS("public class Test() { }");
var (tree, model) = TestCompiler.CompileCS("public class Test() { }");
var typeDeclaration = tree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<TypeDeclarationSyntax>().Single();
var methodSymbol = typeDeclaration.PrimaryConstructor(model);
methodSymbol.Should().NotBeNull();
Expand All @@ -191,7 +191,7 @@ public void PrimaryConstructor_EmptyPrimaryConstructor()
[TestMethod]
public void PrimaryConstructor_EmptyPrimaryConstructor_SecondConstructor()
{
var (tree, model) = TestHelper.CompileCS("""
var (tree, model) = TestCompiler.CompileCS("""
public class Test()
{
public Test(int i) : this() { }
Expand All @@ -207,7 +207,7 @@ public Test(int i) : this() { }
[TestMethod]
public void PrimaryConstructor_EmptyPrimaryConstructorAndStaticConstructor()
{
var (tree, model) = TestHelper.CompileCS("""
var (tree, model) = TestCompiler.CompileCS("""
public class Test()
{
static Test() { }
Expand All @@ -227,7 +227,7 @@ static Test() { }
[DataRow("int i, int j, __arglist", 2)]
public void PrimaryConstructor_ArglistPrimaryConstructor(string parameterList, int expectedNumberOfParameters)
{
var (tree, model) = TestHelper.CompileCS($$"""public class Test({{parameterList}}) { }""");
var (tree, model) = TestCompiler.CompileCS($$"""public class Test({{parameterList}}) { }""");
var typeDeclaration = tree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<TypeDeclarationSyntax>().Single();
var methodSymbol = typeDeclaration.PrimaryConstructor(model);
methodSymbol.Should().NotBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public int M(int arg) =>
M(1);
}
""";
var (tree, model) = TestHelper.CompileCS(code);
var (tree, model) = TestCompiler.CompileCS(code);
var root = tree.GetRoot();
var invocation = root.DescendantNodes().OfType<InvocationExpressionSyntax>().First();
var method = model.GetDeclaredSymbol(root.DescendantNodes().OfType<MethodDeclarationSyntax>().First());
Expand All @@ -48,7 +48,7 @@ public int M(int arg) =>
M(1);
}
""";
var (tree, model) = TestHelper.CompileCS(code);
var (tree, model) = TestCompiler.CompileCS(code);
var lookup = CSharpFacade.Instance.MethodParameterLookup(tree.GetRoot().DescendantNodes().OfType<InvocationExpressionSyntax>().First(), model);
lookup.Should().NotBeNull().And.BeOfType<CSharpMethodParameterLookup>();
}
Expand All @@ -66,7 +66,7 @@ public C M() =>
new C(1);
}
""";
var (tree, model) = TestHelper.CompileCS(code);
var (tree, model) = TestCompiler.CompileCS(code);
var root = tree.GetRoot();
var creation = root.DescendantNodes().OfType<ObjectCreationExpressionSyntax>().First();
var constructor = model.GetDeclaredSymbol(root.DescendantNodes().OfType<ConstructorDeclarationSyntax>().First());
Expand All @@ -87,7 +87,7 @@ public C M() =>
new(1);
}
""";
var (tree, model) = TestHelper.CompileCS(code);
var (tree, model) = TestCompiler.CompileCS(code);
var root = tree.GetRoot();
var creation = root.DescendantNodes().First(x => x.IsKind(SyntaxKindEx.ImplicitObjectCreationExpression));
var constructor = model.GetDeclaredSymbol(root.DescendantNodes().OfType<ConstructorDeclarationSyntax>().First());
Expand All @@ -106,7 +106,7 @@ public int M(int arg) =>
M(1);
}
""";
var (tree, model) = TestHelper.CompileCS(code);
var (tree, model) = TestCompiler.CompileCS(code);
var root = tree.GetRoot();
var argumentList = root.DescendantNodes().OfType<ArgumentListSyntax>().First();
var method = model.GetDeclaredSymbol(root.DescendantNodes().OfType<MethodDeclarationSyntax>().First());
Expand All @@ -125,7 +125,7 @@ public int M(int arg) =>
M(1);
}
""";
var (tree, model) = TestHelper.CompileCS(code);
var (tree, model) = TestCompiler.CompileCS(code);
var root = tree.GetRoot();
var methodDeclaration = root.DescendantNodes().OfType<MethodDeclarationSyntax>().First();
var method = model.GetDeclaredSymbol(methodDeclaration);
Expand All @@ -144,7 +144,7 @@ public int M(int arg) =>
M(1);
}
""";
var (tree, model) = TestHelper.CompileCS(code);
var (tree, model) = TestCompiler.CompileCS(code);
var root = tree.GetRoot();
var method = model.GetDeclaredSymbol(root.DescendantNodes().OfType<MethodDeclarationSyntax>().First());
var actual = sut.MethodParameterLookup(null, method);
Expand All @@ -162,7 +162,7 @@ public int M(int arg) =>
M(1);
}
""";
var (_, model) = TestHelper.CompileCS(code);
var (_, model) = TestCompiler.CompileCS(code);
var actual = sut.MethodParameterLookup(null, model);
actual.Should().BeNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ private static SyntaxNode NodeBetweenMarkers(string code, string language)
var lastPosition = code.LastIndexOf("$$");
var length = lastPosition == position ? 0 : lastPosition - position - "$$".Length;
code = code.Replace("$$", string.Empty);
return TestHelper.CompileCS(code).Tree.GetRoot().FindNode(new TextSpan(position, length));
return TestCompiler.CompileCS(code).Tree.GetRoot().FindNode(new TextSpan(position, length));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SonarCompilationReportingContextTest
public void Properties_ArePropagated()
{
var cancel = new CancellationToken(true);
var compilation = TestHelper.CompileCS("// Nothing to see here").Model.Compilation;
var compilation = TestCompiler.CompileCS("// Nothing to see here").Model.Compilation;
var options = AnalysisScaffolding.CreateOptions();
var context = new CompilationAnalysisContext(compilation, options, _ => { }, _ => true, cancel);
var sut = new SonarCompilationReportingContext(AnalysisScaffolding.CreateSonarAnalysisContext(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SonarCompilationStartAnalysisContextTest
public void Properties_ArePropagated()
{
var cancel = new CancellationToken(true);
var compilation = TestHelper.CompileCS("// Nothing to see here").Model.Compilation;
var compilation = TestCompiler.CompileCS("// Nothing to see here").Model.Compilation;
var options = AnalysisScaffolding.CreateOptions();
var context = Substitute.For<CompilationStartAnalysisContext>(compilation, options, cancel);
var sut = new SonarCompilationStartAnalysisContext(AnalysisScaffolding.CreateSonarAnalysisContext(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SonarSemanticModelReportingContextTest
public void Properties_ArePropagated()
{
var cancel = new CancellationToken(true);
var (tree, model) = TestHelper.CompileCS("// Nothing to see here");
var (tree, model) = TestCompiler.CompileCS("// Nothing to see here");
var options = AnalysisScaffolding.CreateOptions();
var context = new SemanticModelAnalysisContext(model, options, _ => { }, _ => true, cancel);
var sut = new SonarSemanticModelReportingContext(AnalysisScaffolding.CreateSonarAnalysisContext(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SonarSymbolReportingContextTest
public void Properties_ArePropagated()
{
var cancel = new CancellationToken(true);
var (tree, model) = TestHelper.CompileCS("public class Sample { }");
var (tree, model) = TestCompiler.CompileCS("public class Sample { }");
var options = AnalysisScaffolding.CreateOptions();
var symbol = model.GetDeclaredSymbol(tree.Single<ClassDeclarationSyntax>());
var context = new SymbolAnalysisContext(symbol, model.Compilation, options, _ => { }, _ => true, cancel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SonarSyntaxNodeReportingContextTest
public void Properties_ArePropagated()
{
var cancel = new CancellationToken(true);
var (tree, model) = TestHelper.CompileCS("// Nothing to see here");
var (tree, model) = TestCompiler.CompileCS("// Nothing to see here");
var node = tree.GetRoot();
var options = AnalysisScaffolding.CreateOptions();
var containingSymbol = Substitute.For<ISymbol>();
Expand All @@ -51,9 +51,9 @@ public void Properties_ArePropagated()
public void ReportIssue_TreeNotInCompilation_DoNotReport(bool reportOnCorrectTree)
{
var analysisContext = AnalysisScaffolding.CreateSonarAnalysisContext();
var (tree, model) = TestHelper.CompileCS("// Nothing to see here");
var (tree, model) = TestCompiler.CompileCS("// Nothing to see here");
var nodeFromCorrectCompilation = tree.GetRoot();
var nodeFromAnotherCompilation = TestHelper.CompileCS("// This is another Compilation with another Tree").Tree.GetRoot();
var nodeFromAnotherCompilation = TestCompiler.CompileCS("// This is another Compilation with another Tree").Tree.GetRoot();
var rule = AnalysisScaffolding.CreateDescriptorMain();
var node = tree.GetRoot();
var wasReported = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SonarSyntaxTreeReportingContextTest
public void Properties_ArePropagated()
{
var cancel = new CancellationToken(true);
var (tree, model) = TestHelper.CompileCS("// Nothing to see here");
var (tree, model) = TestCompiler.CompileCS("// Nothing to see here");
var options = AnalysisScaffolding.CreateOptions();
var context = new SyntaxTreeAnalysisContext(tree, options, _ => { }, _ => true, cancel);
var sut = new SonarSyntaxTreeReportingContext(AnalysisScaffolding.CreateSonarAnalysisContext(), context, model.Compilation);
Expand All @@ -40,8 +40,8 @@ public void Properties_ArePropagated()
public void ReportIssue_IgnoreSecondaryLocationOutsideCompilation()
{
Diagnostic lastDiagnostic = null;
var (tree, model) = TestHelper.CompileCS("using System;");
var secondaryTree = TestHelper.CompileCS("namespace Nothing;").Tree; // This tree is not in the analyzed compilation
var (tree, model) = TestCompiler.CompileCS("using System;");
var secondaryTree = TestCompiler.CompileCS("namespace Nothing;").Tree; // This tree is not in the analyzed compilation
var context = new SyntaxTreeAnalysisContext(tree, AnalysisScaffolding.CreateOptions(), x => lastDiagnostic = x, _ => true, default);
var sut = new SonarSyntaxTreeReportingContext(AnalysisScaffolding.CreateSonarAnalysisContext(), context, model.Compilation);
var rule = AnalysisScaffolding.CreateDescriptor("Sxxxx", DiagnosticDescriptorFactory.MainSourceScopeTag);
Expand All @@ -60,7 +60,7 @@ public void ReportIssue_IgnoreSecondaryLocationOutsideCompilation()
[TestMethod]
public void ReportIssue_NullArguments_Throws()
{
var compilation = TestHelper.CompileCS("// Nothing to see here").Model.Compilation;
var compilation = TestCompiler.CompileCS("// Nothing to see here").Model.Compilation;
var context = new SyntaxTreeAnalysisContext(compilation.SyntaxTrees.First(), new AnalyzerOptions([]), _ => { }, _ => true, CancellationToken.None);
var sut = new SonarSyntaxTreeReportingContext(AnalysisScaffolding.CreateSonarAnalysisContext(), context, compilation);
var rule = AnalysisScaffolding.CreateDescriptor("Sxxxx", DiagnosticDescriptorFactory.MainSourceScopeTag);
Expand All @@ -74,7 +74,7 @@ public void ReportIssue_NullArguments_Throws()
public void ReportIssue_PropertiesAndSecondaryLocations_Combine()
{
Diagnostic lastDiagnostic = null;
var (tree, model) = TestHelper.CompileCS("using System;");
var (tree, model) = TestCompiler.CompileCS("using System;");
var context = new SyntaxTreeAnalysisContext(tree, AnalysisScaffolding.CreateOptions(), x => lastDiagnostic = x, _ => true, default);
var sut = new SonarSyntaxTreeReportingContext(AnalysisScaffolding.CreateSonarAnalysisContext(), context, model.Compilation);
var rule = AnalysisScaffolding.CreateDescriptor("Sxxxx", DiagnosticDescriptorFactory.MainSourceScopeTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AnalyzerAdditionalFileTest
[TestMethod]
public void AnalyzerAdditionalFile_GetText()
{
var path = TestHelper.WriteFile(TestContext, "AdditionalFile.txt", "some sample content");
var path = TestFiles.WriteFile(TestContext, "AdditionalFile.txt", "some sample content");
var additionalFile = new AnalyzerAdditionalFile(path);
var content = additionalFile.GetText();
content.ToString().Should().Be("some sample content");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Method()
var t = true || true;
}
}";
var cfg = TestHelper.CompileCfgCS(code);
var cfg = TestCompiler.CompileCfgCS(code);
var localLifetimeRegion = cfg.Root.NestedRegions.Single();
var block = cfg.Blocks[localLifetimeRegion.FirstBlockOrdinal];

Expand All @@ -60,7 +60,7 @@ public void Method()
public void DoSomething() { }
}";
var cfg = TestHelper.CompileCfgCS(code);
var cfg = TestCompiler.CompileCfgCS(code);
var block = cfg.Blocks[2];

block.EnclosingRegion.Kind.Should().Be(ControlFlowRegionKind.LocalLifetime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ void MethodWithParameters(int arg1, string arg2) { }
[DataRow("Sample", "MethodWithParameters", true)]
public void IsMemberAvailable_WithoutTypeCheck(string typeName, string memberName, bool expectedResult)
{
var (_, semanticModel) = TestHelper.Compile(Snippet, false, AnalyzerLanguage.CSharp);
var (_, semanticModel) = TestCompiler.Compile(Snippet, false, AnalyzerLanguage.CSharp);
semanticModel.Compilation.IsMemberAvailable<ISymbol>(new(typeName), memberName)
.Should().Be(expectedResult);
}

[TestMethod]
public void IsMemberAvailable_WithPredicate()
{
var (_, semanticModel) = TestHelper.Compile(Snippet, false, AnalyzerLanguage.CSharp);
var (_, semanticModel) = TestCompiler.Compile(Snippet, false, AnalyzerLanguage.CSharp);
semanticModel.Compilation.IsMemberAvailable<IFieldSymbol>(new("Sample"), "_field", x => KnownType.System_Int32.Matches(x.Type))
.Should().BeTrue();
semanticModel.Compilation.IsMemberAvailable<IPropertySymbol>(new("Sample"), "Property", x => x is { IsReadOnly: true })
Expand Down Expand Up @@ -80,7 +80,7 @@ static void Check(IEnumerable<MetadataReference> compilationReferences, params K
[TestMethod]
public void ReferencesAny_ShouldThrow()
{
var (_, model) = TestHelper.Compile(string.Empty, false, AnalyzerLanguage.CSharp);
var (_, model) = TestCompiler.Compile(string.Empty, false, AnalyzerLanguage.CSharp);

((Func<bool>)(() => model.Compilation.ReferencesAny()))
.Should()
Expand All @@ -90,7 +90,7 @@ public void ReferencesAny_ShouldThrow()

private static void ReferencesAny_ShouldBe(bool expected, IEnumerable<MetadataReference> compilationReferences, params KnownAssembly[] checkedAssemblies)
{
var (_, model) = TestHelper.Compile(string.Empty, false, AnalyzerLanguage.CSharp, compilationReferences.ToArray());
var (_, model) = TestCompiler.Compile(string.Empty, false, AnalyzerLanguage.CSharp, compilationReferences.ToArray());
model.Compilation.ReferencesAny(checkedAssemblies).Should().Be(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Sample
{
public void Method() { }
}";
var (tree, semanticModel) = TestHelper.CompileCS(code);
var (tree, semanticModel) = TestCompiler.CompileCS(code);
var method = tree.Single<MethodDeclarationSyntax>();
var symbol = semanticModel.GetDeclaredSymbol(method) as IMethodSymbol;
var cfg = ControlFlowGraph.Create(method, semanticModel, default);
Expand All @@ -48,7 +48,7 @@ public class Sample
{
public void Method() { }
}";
var cfg = TestHelper.CompileCfgCS(code);
var cfg = TestCompiler.CompileCfgCS(code);
Action a = () => cfg.FindLocalFunctionCfgInScope(null, default);
a.Should().Throw<ArgumentOutOfRangeException>().WithMessage("Specified argument was out of the range of valid values.*Parameter*localFunction*");
}
Expand Down
Loading

0 comments on commit 831d94f

Please sign in to comment.