Skip to content

Commit

Permalink
UTs: Cleanup ResourceTest folder (#6891)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristian-ambrosini-sonarsource authored and CristianAmbrosini committed Mar 14, 2023
1 parent c2afae8 commit 5280b6f
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 1,875 deletions.
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.

0 comments on commit 5280b6f

Please sign in to comment.