private void CheckMergedRulesetFile(GetAnalyzerSettings executedTask, string originalRulesetFullPath)
        {
            var expectedMergedRulesetFilePath = RuleSetAssertions.CheckMergedRulesetFile(executedTask.ProjectSpecificConfigDirectory, originalRulesetFullPath);

            TestContext.AddResultFile(expectedMergedRulesetFilePath);
            executedTask.RuleSetFilePath.Should().Be(expectedMergedRulesetFilePath);
        }
Exemplo n.º 2
0
        private static TestLogger CheckShouldMerge(string serverVersion, string language, string ignoreExternalIssues, bool expected)
        {
            // Should default to true i.e. don't override, merge
            var logger = new TestLogger();
            var config = new AnalysisConfig
            {
                SonarQubeHostUrl = "http://sonarqube.com",
                SonarQubeVersion = serverVersion
            };

            if (ignoreExternalIssues != null)
            {
                config.ServerSettings = new AnalysisProperties
                {
                    new Property {
                        Id = $"sonar.{language}.roslyn.ignoreIssues", Value = ignoreExternalIssues
                    }
                };
            }

            var result = GetAnalyzerSettings.ShouldMergeAnalysisSettings(language, config, logger);

            result.Should().Be(expected);
            return(logger);
        }
        public void GetAnalyzerSettings_ConfigExists_DataReturned()
        {
            // Arrange
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();

            string[] expectedAnalyzers = new string[] { "c:\\analyzer1.DLL", "c:\\analyzer2.dll" };
            string[] expectedAdditionalFiles = new string[] { "c:\\add1.txt", "d:\\add2.txt" };

            // SONARMSBRU-216: non-assembly files should be filtered out
            List<string> filesInConfig = new List<string>(expectedAnalyzers);
            filesInConfig.Add("c:\\not_an_assembly.exe");
            filesInConfig.Add("c:\\not_an_assembly.zip");
            filesInConfig.Add("c:\\not_an_assembly.txt");
            filesInConfig.Add("c:\\not_an_assembly.dll.foo");
            filesInConfig.Add("c:\\not_an_assembly.winmd");

            AnalysisConfig config = new AnalysisConfig();
            config.AnalyzerSettings = new AnalyzerSettings();
            config.AnalyzerSettings.RuleSetFilePath = "f:\\yyy.ruleset";
            config.AnalyzerSettings.AnalyzerAssemblyPaths = filesInConfig;
            config.AnalyzerSettings.AdditionalFilePaths = expectedAdditionalFiles.ToList();
            string fullPath = Path.Combine(testDir, FileConstants.ConfigFileName);
            config.Save(fullPath);

            testSubject.AnalysisConfigDir = testDir;

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            Assert.AreEqual("f:\\yyy.ruleset", testSubject.RuleSetFilePath);
            CollectionAssert.AreEquivalent(expectedAnalyzers, testSubject.AnalyzerFilePaths);
            CollectionAssert.AreEquivalent(expectedAdditionalFiles, testSubject.AdditionalFiles);
        }
        public void GetAnalyzerSettings_ConfigExists_DataReturned()
        {
            // Arrange
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();

            string[] expectedAnalyzers = new string[] { "c:\\analyzer1.dll", "c:\\analyzer2.dll" };
            string[] expectedAdditionalFiles = new string[] { "c:\\add1.txt", "d:\\add2.txt" };

            AnalysisConfig config = new AnalysisConfig();
            config.AnalyzerSettings = new AnalyzerSettings();
            config.AnalyzerSettings.RuleSetFilePath = "f:\\yyy.ruleset";
            config.AnalyzerSettings.AnalyzerAssemblyPaths = expectedAnalyzers.ToList();
            config.AnalyzerSettings.AdditionalFilePaths = expectedAdditionalFiles.ToList();
            string fullPath = Path.Combine(testDir, FileConstants.ConfigFileName);
            config.Save(fullPath);

            testSubject.AnalysisConfigDir = testDir;

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            Assert.AreEqual("f:\\yyy.ruleset", testSubject.RuleSetFilePath);
            CollectionAssert.AreEquivalent(expectedAnalyzers, testSubject.AnalyzerFilePaths);
            CollectionAssert.AreEquivalent(expectedAdditionalFiles, testSubject.AdditionalFiles);
        }
        public void GetAnalyzerSettings_ConfigExists_DataReturned()
        {
            // Arrange
            var testDir     = TestUtils.CreateTestSpecificFolder(TestContext);
            var testSubject = new GetAnalyzerSettings();

            var expectedAnalyzers       = new string[] { "c:\\analyzer1.DLL", "c:\\analyzer2.dll" };
            var expectedAdditionalFiles = new string[] { "c:\\add1.txt", "d:\\add2.txt" };

            // SONARMSBRU-216: non-assembly files should be filtered out
            var filesInConfig = new List <string>(expectedAnalyzers)
            {
                "c:\\not_an_assembly.exe",
                "c:\\not_an_assembly.zip",
                "c:\\not_an_assembly.txt",
                "c:\\not_an_assembly.dll.foo",
                "c:\\not_an_assembly.winmd"
            };

            var config = new AnalysisConfig
            {
                AnalyzersSettings = new List <AnalyzerSettings>()
            };

            var settings = new AnalyzerSettings
            {
                Language              = "my lang",
                RuleSetFilePath       = "f:\\yyy.ruleset",
                AnalyzerAssemblyPaths = filesInConfig,
                AdditionalFilePaths   = expectedAdditionalFiles.ToList()
            };

            config.AnalyzersSettings.Add(settings);

            var anotherSettings = new AnalyzerSettings
            {
                Language              = "cobol",
                RuleSetFilePath       = "f:\\xxx.ruleset",
                AnalyzerAssemblyPaths = filesInConfig,
                AdditionalFilePaths   = expectedAdditionalFiles.ToList()
            };

            config.AnalyzersSettings.Add(anotherSettings);

            var fullPath = Path.Combine(testDir, FileConstants.ConfigFileName);

            config.Save(fullPath);

            testSubject.AnalysisConfigDir = testDir;
            testSubject.Language          = "my lang";

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            Assert.AreEqual("f:\\yyy.ruleset", testSubject.RuleSetFilePath);
            CollectionAssert.AreEquivalent(expectedAnalyzers, testSubject.AnalyzerFilePaths);
            CollectionAssert.AreEquivalent(expectedAdditionalFiles, testSubject.AdditionalFiles);
        }
        public void GetAnalyzerSettings_MissingConfigDir_NoError()
        {
            // Arrange
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();
            testSubject.AnalysisConfigDir = "c:\\missing";

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            CheckNoAnalyzerSettings(testSubject);
        }
        public void GetAnalyzerSettings_MissingConfigFile_NoError()
        {
            // Arrange
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();
            testSubject.AnalysisConfigDir = this.TestContext.DeploymentDirectory;

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            CheckNoAnalyzerSettings(testSubject);
        }
        public void GetAnalyzerSettings_MissingConfigDir_NoError()
        {
            // Arrange
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();

            testSubject.AnalysisConfigDir = "c:\\missing";

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            CheckNoAnalyzerSettings(testSubject);
        }
        public void GetAnalyzerSettings_MissingConfigFile_NoError()
        {
            // Arrange
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();

            testSubject.AnalysisConfigDir = this.TestContext.DeploymentDirectory;

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            CheckNoAnalyzerSettings(testSubject);
        }
Exemplo n.º 10
0
        public void GetAnalyzerSettings_MissingConfigFile_NoError()
        {
            // Arrange
            var testSubject = new GetAnalyzerSettings
            {
                AnalysisConfigDir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext)
            };

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            CheckNoAnalyzerSettings(testSubject);
        }
        private static GetAnalyzerSettings CreateConfiguredTestSubject(AnalysisConfig config, string language, TestContext testContext)
        {
            var testDir     = TestUtils.EnsureTestSpecificFolder(testContext);
            var testSubject = new GetAnalyzerSettings();

            testSubject.Language = language;

            var fullPath = Path.Combine(testDir, FileConstants.ConfigFileName);

            config.Save(fullPath);

            testSubject.AnalysisConfigDir = testDir;
            return(testSubject);
        }
        public void GetAnalyzerSettings_ConfigExistsButNoAnalyzerSettings_NoError()
        {
            // Arrange
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();

            AnalysisConfig config = new AnalysisConfig();
            string fullPath = Path.Combine(testDir, FileConstants.ConfigFileName);
            config.Save(fullPath);

            testSubject.AnalysisConfigDir = testDir;

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            CheckNoAnalyzerSettings(testSubject);
        }
        public void GetAnalyzerSettings_ConfigExistsButNoAnalyzerSettings_NoError()
        {
            // Arrange
            var testDir     = TestUtils.CreateTestSpecificFolder(TestContext);
            var testSubject = new GetAnalyzerSettings();

            var config   = new AnalysisConfig();
            var fullPath = Path.Combine(testDir, FileConstants.ConfigFileName);

            config.Save(fullPath);

            testSubject.AnalysisConfigDir = testDir;

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            CheckNoAnalyzerSettings(testSubject);
        }
Exemplo n.º 14
0
        public void GetAnalyzerSettings_ConfigExists_DataReturned()
        {
            // Arrange
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            GetAnalyzerSettings testSubject = new GetAnalyzerSettings();

            string[] expectedAnalyzers       = new string[] { "c:\\analyzer1.DLL", "c:\\analyzer2.dll" };
            string[] expectedAdditionalFiles = new string[] { "c:\\add1.txt", "d:\\add2.txt" };

            // SONARMSBRU-216: non-assembly files should be filtered out
            List <string> filesInConfig = new List <string>(expectedAnalyzers);

            filesInConfig.Add("c:\\not_an_assembly.exe");
            filesInConfig.Add("c:\\not_an_assembly.zip");
            filesInConfig.Add("c:\\not_an_assembly.txt");
            filesInConfig.Add("c:\\not_an_assembly.dll.foo");
            filesInConfig.Add("c:\\not_an_assembly.winmd");

            AnalysisConfig config = new AnalysisConfig();

            config.AnalyzerSettings = new AnalyzerSettings();
            config.AnalyzerSettings.RuleSetFilePath       = "f:\\yyy.ruleset";
            config.AnalyzerSettings.AnalyzerAssemblyPaths = filesInConfig;
            config.AnalyzerSettings.AdditionalFilePaths   = expectedAdditionalFiles.ToList();
            string fullPath = Path.Combine(testDir, FileConstants.ConfigFileName);

            config.Save(fullPath);

            testSubject.AnalysisConfigDir = testDir;

            // Act
            ExecuteAndCheckSuccess(testSubject);

            // Assert
            Assert.AreEqual("f:\\yyy.ruleset", testSubject.RuleSetFilePath);
            CollectionAssert.AreEquivalent(expectedAnalyzers, testSubject.AnalyzerFilePaths);
            CollectionAssert.AreEquivalent(expectedAdditionalFiles, testSubject.AdditionalFiles);
        }
 private static void CheckNoAnalyzerSettings(GetAnalyzerSettings executedTask)
 {
     Assert.IsNull(executedTask.RuleSetFilePath);
     Assert.IsNull(executedTask.AdditionalFiles);
     Assert.IsNull(executedTask.AnalyzerFilePaths);
 }
Exemplo n.º 16
0
 private static void CheckNoAnalyzerSettings(GetAnalyzerSettings executedTask)
 {
     executedTask.RuleSetFilePath.Should().BeNull();
     executedTask.AdditionalFilePaths.Should().BeNull();
     executedTask.AnalyzerFilePaths.Should().BeNull();
 }
 private static void CheckNoAnalyzerSettings(GetAnalyzerSettings executedTask)
 {
     Assert.IsNull(executedTask.RuleSetFilePath);
     Assert.IsNull(executedTask.AdditionalFiles);
     Assert.IsNull(executedTask.AnalyzerFilePaths);
 }