Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTs: Cleanup ResourceTest folder #6891

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
618f9bb
SonarLint.xml file read base logic and tests
CristianAmbrosini Mar 1, 2023
84f9749
Removing relativeRootFromSonarLintXml and deprecated 'Files' element
CristianAmbrosini Mar 1, 2023
9ccaccf
Replaced Lazy initialization with null-coalescing assignment operator
CristianAmbrosini Mar 1, 2023
eb39dd8
Removed empty list initializers
CristianAmbrosini Mar 2, 2023
c2465fd
Addressed PR review comments
CristianAmbrosini Mar 2, 2023
7ff26e1
Add SonarLintXml unit tests
CristianAmbrosini Mar 3, 2023
69d65bc
Replaced tabs with spaces
CristianAmbrosini Mar 3, 2023
0b7c818
Add test cases
CristianAmbrosini Mar 3, 2023
07e7627
Bump temporarily UTs ToStringCallCount
CristianAmbrosini Mar 6, 2023
e2cb421
Small merge fix
CristianAmbrosini Mar 6, 2023
d2bb4ca
Fix rebase issues 2
CristianAmbrosini Mar 6, 2023
92cbf8a
Fix UTs
CristianAmbrosini Mar 6, 2023
1ab49e5
IgnoreAttribute for parametrized test.
CristianAmbrosini Mar 6, 2023
d13ad03
Addressed PR comments
CristianAmbrosini Mar 7, 2023
5ba46e6
Second round of comments
CristianAmbrosini Mar 8, 2023
9dde001
Migrated ShouldAnalyzeFile test case to ShouldAnalyzeTree
CristianAmbrosini Mar 8, 2023
dd2a57d
Fix rebase
CristianAmbrosini Mar 9, 2023
70b1ac7
Add test cases
CristianAmbrosini Mar 3, 2023
8659eec
Addressed PR comments
CristianAmbrosini Mar 7, 2023
9e01a32
Second round of comments
CristianAmbrosini Mar 8, 2023
042e33e
Migrated ShouldAnalyzeFile test case to ShouldAnalyzeTree
CristianAmbrosini Mar 8, 2023
f4b6239
Cleanup resource test and migrated references on UTs
CristianAmbrosini Mar 9, 2023
902989a
Reduced the size of the ResourceTest\SonarLint.xml files
CristianAmbrosini Mar 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -37,7 +37,7 @@ public class ParameterLoaderTest
public void SetParameterValues_WhenNoSonarLintIsGiven_DoesNotPopulateParameters(string filePath)
{
// Arrange
var compilation = CreateCompilationWithOption(filePath, SourceText.From(File.ReadAllText("ResourceTests\\SonarLint.xml")));
var compilation = CreateCompilationWithOption(filePath, SourceText.From(File.ReadAllText("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml")));
var analyzer = new ExpressionComplexity(); // Cannot use mock because we use reflection to find properties.

// Act
Expand All @@ -53,7 +53,7 @@ public void SetParameterValues_WhenNoSonarLintIsGiven_DoesNotPopulateParameters(
public void SetParameterValues_WhenGivenValidSonarLintFilePath_PopulatesProperties(string filePath)
{
// Arrange
var compilation = CreateCompilationWithOption(filePath, SourceText.From(File.ReadAllText("ResourceTests\\SonarLint.xml")));
var compilation = CreateCompilationWithOption(filePath, SourceText.From(File.ReadAllText("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml")));
var analyzer = new ExpressionComplexity(); // Cannot use mock because we use reflection to find properties.

// Act
Expand All @@ -67,7 +67,7 @@ public void SetParameterValues_WhenGivenValidSonarLintFilePath_PopulatesProperti
public void SetParameterValues_WhenGivenSonarLintFileHasIntParameterType_PopulatesProperties()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLint.xml");
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml");
var analyzer = new ExpressionComplexity(); // Cannot use mock because we use reflection to find properties.

// Act
Expand All @@ -81,7 +81,7 @@ public void SetParameterValues_WhenGivenSonarLintFileHasIntParameterType_Populat
public void SetParameterValues_WhenGivenSonarLintFileHasStringParameterType_OnlyOneParameter_PopulatesProperty()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\RuleWithStringParameter\\SonarLint.xml");
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\RuleWithStringParameter\\SonarLint.xml");
var analyzer = new EnumNameShouldFollowRegex(); // Cannot use mock because we use reflection to find properties.

// Act
Expand All @@ -95,7 +95,7 @@ public void SetParameterValues_WhenGivenSonarLintFileHasStringParameterType_Only
public void SetParameterValues_WhenGivenSonarLintFileHasBooleanParameterType_OnlyOneParameter_PopulatesProperty()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\RuleWithBooleanParameter\\SonarLint.xml");
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\RuleWithBooleanParameter\\SonarLint.xml");
var analyzer = new CheckFileLicense(); // Cannot use mock because we use reflection to find properties.

// Act
Expand All @@ -109,7 +109,7 @@ public void SetParameterValues_WhenGivenSonarLintFileHasBooleanParameterType_Onl
public void SetParameterValues_WhenGivenValidSonarLintFileAndDoesNotContainAnalyzerParameters_DoesNotPopulateProperties()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLint.xml");
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml");
var analyzer = new LineLength(); // Cannot use mock because we use reflection to find properties.

// Act
Expand Down Expand Up @@ -180,7 +180,7 @@ public void SetParameterValues_WithMalformedXml_DoesNotPopulateProperties(string
public void SetParameterValues_WithWrongPropertyType_StringInsteadOfInt_DoesNotPopulateProperties()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\StringInsteadOfInt\\SonarLint.xml");
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\StringInsteadOfInt\\SonarLint.xml");
var analyzer = new ExpressionComplexity(); // Cannot use mock because we use reflection to find properties.

// Act
Expand All @@ -194,7 +194,7 @@ public void SetParameterValues_WithWrongPropertyType_StringInsteadOfInt_DoesNotP
public void SetParameterValues_WithWrongPropertyType_StringInsteadOfBoolean_DoesNotPopulateProperties()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\StringInsteadOfBoolean\\SonarLint.xml");
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\StringInsteadOfBoolean\\SonarLint.xml");
var analyzer = new CheckFileLicense(); // Cannot use mock because we use reflection to find properties.

// Act
Expand Down
Expand Up @@ -41,7 +41,7 @@ public void SonarLintXmlReader_WhenAllValuesAreSet_ExpectedValues(string languag
AssertArrayContent(sut.TestInclusions, nameof(sut.TestInclusions));
AssertArrayContent(sut.GlobalTestExclusions, nameof(sut.GlobalTestExclusions));

sut.ParametrizedRules.Should().HaveCount(8);
sut.ParametrizedRules.Should().HaveCount(2);
var rule = sut.ParametrizedRules.First(x => x.Key.Equals("S2342"));
rule.Parameters[0].Key.Should().Be("format");
rule.Parameters[0].Value.Should().Be("^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$");
Expand Down
24 changes: 12 additions & 12 deletions analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlTest.cs
Expand Up @@ -30,7 +30,7 @@ public class SonarLintXmlTest
public void SonarLintXml_DeserializeFile_ExpectedValues()
{
var deserializer = new XmlSerializer(typeof(SonarLintXml));
using TextReader textReader = new StreamReader("ResourceTests\\SonarLintXml\\All_properties_small_template\\SonarLint.xml");
using TextReader textReader = new StreamReader("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml");
var sonarLintXml = (SonarLintXml)deserializer.Deserialize(textReader);

AssertSettings(sonarLintXml.Settings);
Expand Down Expand Up @@ -58,20 +58,20 @@ private static void AssertRules(List<SonarLintXmlRule> rules)
rules.Should().HaveCount(4);
rules.Where(x => x.Parameters.Any()).Should().HaveCount(2);

rules[0].Key.Should().BeEquivalentTo("S0001");
rules[0].Key.Should().BeEquivalentTo("S2225");
rules[0].Parameters.Should().BeEmpty();
rules[1].Key.Should().BeEquivalentTo("S0002");
rules[1].Parameters.Should().BeEmpty();

rules[2].Key.Should().BeEquivalentTo("S0003");
rules[2].Parameters.Should().HaveCount(2);
AssertKeyValuePair(rules[2].Parameters[0], "format", "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$");
AssertKeyValuePair(rules[2].Parameters[1], "flagsAttributeFormat", "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$");
rules[1].Key.Should().BeEquivalentTo("S2342");
rules[1].Parameters.Should().HaveCount(2);
AssertKeyValuePair(rules[1].Parameters[0], "format", "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$");
AssertKeyValuePair(rules[1].Parameters[1], "flagsAttributeFormat", "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$");

rules[3].Key.Should().BeEquivalentTo("S0004");
rules[3].Parameters.Should().HaveCount(2);
AssertKeyValuePair(rules[3].Parameters[0], "threshold", "15");
AssertKeyValuePair(rules[3].Parameters[1], "propertyThreshold", "3");
rules[2].Key.Should().BeEquivalentTo("S2346");
rules[2].Parameters.Should().BeEmpty();

rules[3].Key.Should().BeEquivalentTo("S1067");
rules[3].Parameters.Should().HaveCount(1);
AssertKeyValuePair(rules[3].Parameters[0], "max", "1");
}

private static void AssertKeyValuePair(SonarLintXmlKeyValuePair pair, string expectedKey, string expectedValue)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLint.xml

This file was deleted.