Esempio n. 1
0
        private bool FilesAreEquivalent(AnalyzerLanguage language, out List <string> problematicRules)
        {
            problematicRules = new List <string>();

            var expectedFiles = ExpectedDirectory
                                .GetDirectories(language.GetDirectoryName()).First()
                                .GetFiles("S*.json");
            var actualFiles = AnalysisOutputDirectory
                              .GetDirectories(language.GetDirectoryName()).First()
                              .GetFiles("S*.json");

            var problematicFileNames =
                expectedFiles.Select(file => file.Name)
                .ToImmutableHashSet()
                .SymmetricExcept(actualFiles.Select(file => file.Name));

            if (problematicFileNames.Any())
            {
                problematicRules.AddRange(problematicFileNames);
                return(false);
            }

            foreach (var expectedFile in expectedFiles)
            {
                var bytesExpected = File.ReadAllBytes(expectedFile.FullName);
                var bytesActual   = File.ReadAllBytes(actualFiles.Single(file => file.Name == expectedFile.Name).FullName);

                if (!StructuralComparisons.StructuralEqualityComparer.Equals(bytesExpected, bytesActual))
                {
                    problematicRules.Add(Path.GetFileNameWithoutExtension(expectedFile.Name));
                }
            }

            return(!problematicRules.Any());
        }
Esempio n. 2
0
 private void CreateMissingActualDirectory(AnalyzerLanguage language)
 {
     if (!AnalysisOutputDirectory.GetDirectories(language.GetDirectoryName()).Any())
     {
         Directory.CreateDirectory(Path.Combine(
                                       AnalysisOutputDirectory.FullName,
                                       language.GetDirectoryName()));
     }
 }
Esempio n. 3
0
 private void CreateMissingExpectedDirectory(AnalyzerLanguage language)
 {
     if (!ExpectedDirectory.GetDirectories(language.GetDirectoryName()).Any())
     {
         Directory.CreateDirectory(Path.Combine(
                                       ExpectedDirectory.FullName,
                                       language.GetDirectoryName()));
     }
 }
Esempio n. 4
0
        private void CheckIntegrationTestCount(AnalyzerLanguage language)
        {
            ValidateLanguageInput(language);
            CreateMissingExpectedDirectory(language);

            Assert.AreEqual(
                RuleFinder.GetAnalyzerTypes(language).Count(),
                ExpectedDirectory
                .GetDirectories(language.GetDirectoryName()).First()
                .GetFiles("S*.json").Count());
        }
Esempio n. 5
0
        private void RunItSourcesTest(AnalyzerLanguage language)
        {
            ValidateLanguageInput(language);
            CreateMissingExpectedDirectory(language);
            CreateMissingActualDirectory(language);

            var tempInputFilePath = Path.GetTempFileName();

            try
            {
                File.AppendAllText(tempInputFilePath, GenerateAnalysisInputFile(language));
                var outputPath = Path.Combine(AnalysisOutputDirectory.FullName, language.GetDirectoryName(), "all.xml");

                CallMainAndCheckResult(tempInputFilePath, outputPath, language);
            }
            finally
            {
                File.Delete(tempInputFilePath);
            }
        }
Esempio n. 6
0
        private void SplitAndStoreOmstarByIssueType(AnalysisOutput omstar, AnalyzerLanguage language)
        {
            foreach (var issueGroup in omstar.Issues.GroupBy(issue => issue.RuleId))
            {
                var omstarForRule = new AnalysisOutput
                {
                    ToolInfo = omstar.ToolInfo,
                    Version  = omstar.Version,
                    Issues   = issueGroup
                               .OrderBy(issue =>
                    {
                        var location = issue.Locations.FirstOrDefault();
                        return(location == null ? string.Empty : location.AnalysisTarget.Uri);
                    }, new InvariantCultureStringSortComparer())
                               .ThenBy(issue =>
                    {
                        var location = issue.Locations.FirstOrDefault();
                        return(location == null ? 0 : location.AnalysisTarget.Region.StartLine);
                    })
                               .ThenBy(issue =>
                    {
                        var location = issue.Locations.FirstOrDefault();
                        return(location == null ? 0 : location.AnalysisTarget.Region.EndLine);
                    })
                               .ThenBy(issue => issue.FullMessage, new InvariantCultureStringSortComparer())
                               .ToList()
                };

                var content = JsonConvert.SerializeObject(omstarForRule,
                                                          new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Formatting        = Formatting.Indented
                });

                File.WriteAllText(Path.Combine(
                                      AnalysisOutputDirectory.FullName,
                                      language.GetDirectoryName(),
                                      $"{issueGroup.Key}.json"), content);
            }
        }