Skip to content

Commit

Permalink
Simplify TestUtilityAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Mar 14, 2023
1 parent 7582915 commit 9cd9199
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void ReadConfig_OutPath(string language, string additionalPath, string ex
// We do not test what is read from the SonarLint file, but we need it
var utilityAnalyzer = new TestUtilityAnalyzer(language, @"ResourceTests\SonarLint.xml", additionalPath);

utilityAnalyzer.TestOutPath.Should().Be(expectedOutPath);
utilityAnalyzer.TestIsAnalyzerEnabled.Should().BeTrue();
utilityAnalyzer.Parameters.OutPath.Should().Be(expectedOutPath);
utilityAnalyzer.Parameters.IsAnalyzerEnabled.Should().BeTrue();
}

[DataTestMethod]
Expand All @@ -57,8 +57,8 @@ public void ReadConfig_OutPath_FromSonarProjectConfig_HasPriority(string firstFi
// We do not test what is read from the SonarLint file, but we need it
var utilityAnalyzer = new TestUtilityAnalyzer(LanguageNames.CSharp, @"ResourceTests\SonarLint.xml", firstFile, secondFile);

utilityAnalyzer.TestOutPath.Should().Be(@"C:\foo\bar\.sonarqube\out\0\output-cs");
utilityAnalyzer.TestIsAnalyzerEnabled.Should().BeTrue();
utilityAnalyzer.Parameters.OutPath.Should().Be(@"C:\foo\bar\.sonarqube\out\0\output-cs");
utilityAnalyzer.Parameters.IsAnalyzerEnabled.Should().BeTrue();
}

[DataTestMethod]
Expand All @@ -70,8 +70,8 @@ public void ReadsSettings_AnalyzeGenerated(string language, string sonarLintXmlP
{
var utilityAnalyzer = new TestUtilityAnalyzer(language, sonarLintXmlPath, DefaultSonarProjectConfig);

utilityAnalyzer.TestAnalyzeGeneratedCode.Should().Be(expectedAnalyzeGeneratedCodeValue);
utilityAnalyzer.TestIsAnalyzerEnabled.Should().BeTrue();
utilityAnalyzer.Parameters.AnalyzeGeneratedCode.Should().Be(expectedAnalyzeGeneratedCodeValue);
utilityAnalyzer.Parameters.IsAnalyzerEnabled.Should().BeTrue();
}

[DataTestMethod]
Expand All @@ -83,20 +83,20 @@ public void ReadsSettings_IgnoreHeaderComments(string language, string sonarLint
{
var utilityAnalyzer = new TestUtilityAnalyzer(language, sonarLintXmlPath, DefaultSonarProjectConfig);

utilityAnalyzer.TestIgnoreHeaderComments.Should().Be(expectedIgnoreHeaderComments);
utilityAnalyzer.TestIsAnalyzerEnabled.Should().BeTrue();
utilityAnalyzer.Parameters.IgnoreHeaderComments.Should().Be(expectedIgnoreHeaderComments);
utilityAnalyzer.Parameters.IsAnalyzerEnabled.Should().BeTrue();
}

[TestMethod]
public void NoSonarLintXml_AnalyzerNotEnabled()
{
new TestUtilityAnalyzer(LanguageNames.CSharp, DefaultProjectOutFolderPath).TestIsAnalyzerEnabled.Should().BeFalse();
new TestUtilityAnalyzer(LanguageNames.CSharp, DefaultSonarProjectConfig).TestIsAnalyzerEnabled.Should().BeFalse();
new TestUtilityAnalyzer(LanguageNames.CSharp, DefaultProjectOutFolderPath).Parameters.IsAnalyzerEnabled.Should().BeFalse();
new TestUtilityAnalyzer(LanguageNames.CSharp, DefaultSonarProjectConfig).Parameters.IsAnalyzerEnabled.Should().BeFalse();
}

[TestMethod]
public void NoOutputPath_AnalyzerNotEnabled() =>
new TestUtilityAnalyzer(LanguageNames.CSharp, @"ResourceTests\AnalyzeGeneratedTrue\SonarLint.xml").TestIsAnalyzerEnabled.Should().BeFalse();
new TestUtilityAnalyzer(LanguageNames.CSharp, @"ResourceTests\AnalyzeGeneratedTrue\SonarLint.xml").Parameters.IsAnalyzerEnabled.Should().BeFalse();

[TestMethod]
public void GetTextRange()
Expand All @@ -123,11 +123,6 @@ private class TestUtilityAnalyzer : UtilityAnalyzerBase
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => throw new NotImplementedException();
public UtilityAnalyzerParameter Parameters { get; }
public bool TestIsAnalyzerEnabled => Parameters.IsAnalyzerEnabled;
public bool TestAnalyzeGeneratedCode => Parameters.AnalyzeGeneratedCode;
public bool TestIgnoreHeaderComments => Parameters.IgnoreHeaderComments;
public string TestOutPath => Parameters.OutPath;


public TestUtilityAnalyzer(string language, params string[] additionalPaths) : base("S9999-test", "Title")
{
Expand Down

0 comments on commit 9cd9199

Please sign in to comment.